3个不稳定版本
0.2.1 | 2024年2月23日 |
---|---|
0.2.0 | 2024年2月23日 |
0.1.0 | 2024年2月3日 |
#196 在 模板引擎
每月21次下载
23KB
520 行
Zinal是一个Rust程序的HTML模板渲染库。
示例
use zinal::*;
#[derive(Template)]
#[template(content = "
<div>We greet the following people:</div>
<ul>
<# for name in &self.names #>
<Person name={{name}} />
<#end>
</ul>
")]
struct Greetings {
names: Vec<String>
}
#[derive(Template)]
#[template(content = "<li><p>{{self.name}}</p></li>")]
struct Person<'a> {
name: &'a str,
}
let greetings = Greetings {
names: vec!["Mary".to_owned(), "John".to_owned(), "Kate".to_owned(), "Agnes".to_owned()]
};
println!("{}", greetings.render_to_string().unwrap());
// Prints (possibly with some insignificant whitespace differences):
// <div>We greet the following people:</div>
// <ul>
// <li><p>Mary</p></li>
// <li><p>John</p></li>
// <li><p>Kate</p></li>
// <li><p>Agnes</p></li>
// </ul>
依赖项
~130KB