nanotemplate

Crates.ionanotemplate
lib.rsnanotemplate
version0.3.0
sourcesrc
created_at2021-05-04 11:58:09.8951
updated_at2022-09-22 12:55:17.542095
descriptionA minimal templating engine that renders a string from the template, replacing all instances of {placeholder} with given values
homepagehttps://sr.ht/~jpastuszek/nanotemplate/
repositoryhttps://git.sr.ht/~jpastuszek/nanotemplate
max_upload_size
id392969
size17,940
Jakub Pastuszek (jpastuszek)

documentation

https://docs.rs/nanotemplate

README

Latest Version Documentation License

A minimal templating engine that renders a string from the template, replacing all instances of {placeholder} with given values.

The engine is strict:

  • all placeholders must have values provided (use template_default to use default value for placeholders),
  • all provided values must have matching placeholder (when using template_strict),
  • a single placeholder can be used multiple times and will be expanded in all places.

Values are provided as an iterable object that provides placeholder name and value pairs.

use nanotemplate::template;

assert_eq!(
	template("Hello, my name is {name}!", &[("name", "nanotemplate")]).unwrap(),
	"Hello, my name is nanotemplate!".to_owned());

Also comes with simple CLI utility:

echo "Hello my name is {name}" | nanotemplate name=nanotemplate
Commit count: 0

cargo fmt