#templating #string #cli

bin+lib nanotemplate

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

4 releases (2 breaking)

0.3.0 Sep 22, 2022
0.2.1 Jun 23, 2021
0.2.0 May 5, 2021
0.1.0 May 4, 2021

#157 in Template engine

Download history 944/week @ 2024-03-14 345/week @ 2024-03-21 1311/week @ 2024-03-28 435/week @ 2024-04-04 383/week @ 2024-04-11 357/week @ 2024-04-18 452/week @ 2024-04-25 261/week @ 2024-05-02 360/week @ 2024-05-09 319/week @ 2024-05-16 284/week @ 2024-05-23 420/week @ 2024-05-30 480/week @ 2024-06-06 518/week @ 2024-06-13 561/week @ 2024-06-20 479/week @ 2024-06-27

2,108 downloads per month
Used in 2 crates

MIT license

17KB
298 lines

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

No runtime deps