5个不稳定版本
0.3.1 | 2024年8月16日 |
---|---|
0.3.0 | 2024年6月25日 |
0.2.1 | 2024年6月22日 |
0.2.0 | 2024年6月11日 |
0.1.0 | 2024年5月13日 |
#125 在 模板引擎 中
每月370 次下载
用于 5 个crates(2 个直接使用)
56KB
1K SLoC
Ribboncurls
Ribboncurls 是一个用于渲染 mustache 模板的Rust库。Ribboncurls通过了所有133个mustache v1.4.1规范测试。
注意:Ribboncurls库的公共API可能会更改,因此请谨慎使用。
用法
基本用法
let template = r#"Hello, {{name}}!"#;
let data = r#"{"name": "world"}"#;
let result = ribboncurls::render(template, data, None).unwrap();
assert_eq!(result, "Hello, world!");
使用部分模板
以下是如何使用mustache部分模板
let partials = r#"
header: <header>Some header partial</header>
footer: <footer>Footer partial content goes here</footer>"#;
let template = r#"{{> header}}
Hello, {{name}}!
{{> footer}}"#;
let data = r#"{"name": "world"}"#;
let result = ribboncurls::render(template, data, Some(partials)).unwrap();
assert_eq!(result, r#"<header>Some header partial</header>Hello, world!
<footer>Footer partial content goes here</footer>"#);
Mustache规范测试
我们对Ribboncurls库运行mustache规范测试,并通过了133个测试中的所有测试。
测试
✅ comments::inline✅ comments::standalone
✅ comments::multiline_standalone
✅ comments::variable_name_collision
✅ comments::multiline
✅ comments::indented_inline
✅ comments::indented_standalone
✅ comments::indented_multiline_standalone
✅ comments::surrounding_whitespace
✅ comments::standalone_line_endings
✅ comments::standalone_without_previous_line
✅ comments::standalone_without_newline
✅ delimiters::pair_behavior
✅ delimiters::pair_with_padding
✅ delimiters::indented_standalone_tag
✅ delimiters::outlying_whitespace_inline
✅ delimiters::special_characters
✅ delimiters::standalone_tag
✅ interpolation::ampersand_context_miss_interpolation
✅ delimiters::surrounding_whitespace
✅ delimiters::standalone_without_newline
✅ delimiters::standalone_without_previous_line
✅ interpolation::ampersand
✅ delimiters::inverted_sections
✅ delimiters::standalone_line_endings
✅ delimiters::post_partial_behavior
✅ interpolation::ampersand_integer_interpolation
✅ delimiters::sections
✅ interpolation::ampersand_standalone
✅ interpolation::ampersand_decimal_interpolation
✅ interpolation::ampersand_with_padding
✅ interpolation::ampersand_null_interpolation
✅ interpolation::basic_context_miss_interpolation
✅ interpolation::ampersand_surrounding_whitespace
✅ interpolation::basic_null_interpolation
✅ interpolation::dotted_names_broken_chain_resolution
✅ interpolation::basic_decimal_interpolation
✅ interpolation::basic_integer_interpolation
✅ interpolation::dotted_names_arbitrary_depth
✅ interpolation::dotted_names_broken_chains
✅ interpolation::dotted_names_ampersand_interpolation
✅ interpolation::basic_interpolation
✅ 分隔符:部分继承
✅ 插值:点命名基本插值
✅ 插值:点命名上下文优先级
✅ 插值:隐式迭代器基本整数插值
✅ 插值:HTML 转义
✅ 插值:点命名初始解析
✅ 插值:隐式迭代器三重花括号
✅ 插值:插值周围空白
✅ 插值:隐式迭代器和符号
✅ 插值:点命名三重花括号插值
✅ 插值:独立插值
✅ 插值:隐式迭代器基本插值
✅ 插值:带有填充的插值
✅ 插值:隐式迭代器 HTML 转义
✅ 插值:三重花括号
✅ 插值:无插值
✅ 插值:三重花括号周围空白
✅ 插值:三重花括号上下文缺失插值
✅ 插值:三重花括号独立
✅ 插值:三重花括号整数插值
✅ 插值:三重花括号空插值
✅ 插值:三重花括号带有填充
✅ 插值:三重花括号十进制插值
✅ 反转:上下文缺失
✅ 反转:上下文
✅ 反转:点命名真值
✅ 反转:假值
✅ 反转:点命名断链
✅ 反转:空列表
✅ 反转:点命名假值
✅ 反转:列表
✅ 反转:重复
✅ 反转:缩进内联部分
✅ 反转:内部空白
✅ 反转:嵌套假值
✅ 反转:填充
✅ 反转:null 为假值
✅ 反转:独立行结束符
✅ 反转:独立缩进行
✅ 反转:嵌套真值
✅ 反转:独立行
✅ 反转:真值
✅ 反转:独立无前一行
✅ 部分视图:查找失败
✅ 反转:独立无换行符
✅ 反转:周围空白
✅ 部分视图:独立无前一行
✅ 部分视图:基本行为
✅ 部分视图:上下文
✅ 部分视图:填充空白
✅ 部分视图:内联缩进
✅ 部分:点命名断链
✅ 部分:点命名假值
✅ 部分视图:独立行结束符
✅ 部分视图:独立缩进
✅ 部分视图:嵌套
✅ 部分视图:周围空白
✅ 部分:点命名真值
✅ 部分视图:独立无换行符
✅ 部分视图:递归
✅ 部分:上下文
✅ 部分:空列表
✅ 部分:假值
✅ 部分:上下文缺失
✅ 部分:重复
✅ 部分:隐式迭代器 HTML 转义
✅ 部分:隐式迭代器十进制
✅ 部分:隐式迭代器根级
✅ 部分:隐式迭代器和符号
✅ 部分:隐式迭代器字符串
✅ 部分:隐式迭代器整数
✅ 部分:隐式迭代器数组
✅ 部分:缩进独立行
✅ 部分:隐式迭代器三重花括号
✅ 部分:列表
✅ 部分:缩进内联部分
✅ 部分:内部空白
✅ 部分:填充
✅ 部分:深度嵌套上下文
✅ 部分:独立行
✅ 部分:嵌套假值
✅ 部分:父上下文
✅ 部分:独立行结束符
✅ 部分:null 为假值
✅ 部分:列表上下文
✅ 部分:独立无换行符
✅ 部分:周围空白
✅ 部分:嵌套真值
✅ 部分:变量测试
✅ 部分:真值
✅ 部分:独立无前一行
许可
Ribboncurls 在 MPL-2.0 许可下授权。
第三方许可
本项目包含在 MPL-2.0 许可下授权的第三方代码。有关详细信息,请参阅 THIRD_PARTY_LICENSES 文件。
依赖项
~4–6MB
~114K SLoC