4 个版本 (2 个重大更新)
0.3.0 | 2022年9月22日 |
---|---|
0.2.1 | 2021年6月23日 |
0.2.0 | 2021年5月5日 |
0.1.0 | 2021年5月4日 |
在 模板引擎 中排名 #157
每月下载量 2,108
在 2 crates 中使用
17KB
298 行
一个最小化的模板引擎,从模板渲染字符串,将所有 {placeholder}
实例替换为给定的值。
引擎是严格的
- 所有占位符都必须提供值(使用
template_default
为占位符使用默认值), - 提供的所有值都必须与占位符匹配(使用
template_strict
), - 单个占位符可以使用多次,并将被扩展到所有位置。
值由一个提供占位符名称和值对的迭代对象提供。
use nanotemplate::template;
assert_eq!(
template("Hello, my name is {name}!", &[("name", "nanotemplate")]).unwrap(),
"Hello, my name is nanotemplate!".to_owned());
还附带简单的 CLI 工具
echo "Hello my name is {name}" | nanotemplate name=nanotemplate