{% Incrust %}
Incrust is a template engine inspired by Jinja2 and written in Rust.
NOTA BENE
This is a work in progress and (as may be assumed reasonably enough) may be highly unstable just yet.
Unstable
The implementation is at a very early stage and the API is a subject of changes.
Since Incrust developed with unstable features it depends on nightly Rust. Release version will be refactored to build on stable channel.
Installation
Incrust is available on crates.io and can be included in your Cargo enabled project like this:
[dependencies]
incrust = "0.0"
Then include it in your code like this:
extern crate incrust;
Examples
All examples assume a prepared instance of Incrust. For ease of use hashmaps, we use the macro maplit
extern crate maplit;
extern crate incrust;
use ;
Variables
let result = incrust.render_text
Filters
let args: Args = hashmap!;
let result = incrust.render_text.unwrap;
assert_eq!;
Literals
assert_eq!;
assert_eq!;
Expressions
let args = hashmap!;
assert_eq!;
let args = hashmap!;
assert_eq!;
Lazy boolean evaluation
let tpl = r#"Amount: {{ amount and ("" + amount + " pcs") or "-" }}"#;
assert_eq!;
assert_eq!;
Conditional statements
assert_eq!;
assert_eq!;
For-Loop statements
let args = hashmap!;
let tpl = r#"<ul>{% for fruit in fruits %}<li>{{ index }}. {{ fruit | e }}</li>{% endfor %}</ul>"#;
let expected = r#"<ul><li>1. Orange</li><li>2. Apple</li><li>3. Banana</li></ul>"#;
assert_eq!;
Comments
let tpl = incrust.parse.unwrap;
let result = incrust.render_parsed.unwrap;
assert_eq!;
Escaping
let tpl = "Example: {% raw %}{{ mustaches }}{% endraw %}";
let result = incrust.render_text.unwrap;
assert_eq!;
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.