3 unstable releases
Uses old Rust 2015
0.2.0 | Feb 13, 2017 |
---|---|
0.1.1 | Nov 22, 2016 |
0.1.0 | Nov 21, 2016 |
#24 in #render-template
Used in ocean
47KB
1K
SLoC
mage
Mage is an intuitive and powerful template engine.
Document
Usage
Add dependency to Cargo.toml
[dependencies]
mage = "^0.2"
In your main.rs
or lib.rs
:
extern crate mage;
Supported keywords: for
if
include
set
Mage support expression evaluate with crate eval
.
Built-in functions and operators documentation: eval
.
License
mage is primarily distributed under the terms of the MIT license. See LICENSE for details.
lib.rs
:
Mage is an intuitive and powerful template engine.
Supported keywords: for
if
include
set
Mage support expression evaluate with crate eval
.
Built-in functions and operators documentation: eval
.
Examples
Render template from string:
use mage::Template;
let source = "{{if true}}Hello world!{{if}}";
let output = Template::new().template(source).render().unwrap();
assert_eq!(output, "Hello world!");
Render template from file:
use mage::Template;
let output = Template::new()
.root("examples")
.extension("html")
.open("main")
.unwrap()
.render()
.unwrap();
Keywords
For
Loop a value.
{{for value in object}}
{{value}}
{{for}}
{{for value, key in object}}
{{key}}
{{value}}
{{for}}
If
Conditionally render a block.
{{if boolean}}
Hello world!
{{elseif boolean}}
Hello world!
{{elseif boolean}}
Hello world!
{{else}}
Hello world!
{{if}}
Include
Include a sub template.
{{include views/header}}
Set
Set a value to current context.
{{set boolean=true}}
{{set number=123}}
{{set string='Hello world!'}}
Dependencies
~2MB
~40K SLoC