1 个稳定版本
1.0.0 | 2023年9月18日 |
---|
#275 在 模板引擎 中
6KB
89 行
scuf
从模板生成文本。
用法
scuf
目前仅在UTF-8文件上进行了测试。如果存在冲突的名称,模板文件语法将与其他sh
变量冲突。
以下是一个示例模板文件,让我们称它为 foo.txt
The quick ${color} ${animal0} jumps over the lazy ${animal1}.
color
、animal0
和 animal1
是变量,如果 scuf
接收一个将其中一个名称分配给它们的参数,则将被替换,如下所示
scaf --var color=green
--var animal0=frog
--var animal1=turtle
foo.txt
这将打印到标准输出
The quick green frog jumps over the lazy turtle.
可以安全省略变量,因此模板变量不会被替换。但是,您必须提供至少一个文件,否则 scuf
会提前失败。
话虽如此,可以使用多个文件,首先将它们的内容连接起来,然后根据需要替换
foo.txt
${msg1}
和
bar.txt
${msg2}
使用以下命令调用
scaf --var "msg1=Hello world!"
--var "msg2=Goodbye friends!"
foo.txt bar.txt
结果为
foo.txt
Hello world!
bar.txt
Goodbye friends!