#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

#270 in Template engine

Download history 328/week @ 2024-11-16 473/week @ 2024-11-23 536/week @ 2024-11-30 880/week @ 2024-12-07 561/week @ 2024-12-14 581/week @ 2024-12-21 442/week @ 2024-12-28 1758/week @ 2025-01-04 459/week @ 2025-01-11 313/week @ 2025-01-18 334/week @ 2025-01-25 123/week @ 2025-02-01 110/week @ 2025-02-08 115/week @ 2025-02-15 99/week @ 2025-02-22 69/week @ 2025-03-01

408 downloads per month

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