liquid-rust
Liquid templating for Rust
Usage
To include liquid in your project add the following to your Cargo.toml:
[]
= "0.9"
Now you can use the crate in your code
extern crate liquid;
Example:
use ;
let template = parse.unwrap;
let mut context = new;
context.set_val;
let output = template.render;
assert_eq!;
You can find a reference on Liquid syntax here.
Plugins
Cache block ( File and Redis ) : https://github.com/FerarDuanSednan/liquid-rust-cache
Extending Liquid
Create your own filters
Creating your own filters is very easy. Filters are simply functions or
closures that take an input Value
and a Vec<Value>
of optional arguments
and return a Value
to be rendered or consumed by chained filters.
use ;
let template = parse.unwrap;
let mut context = new;
// create our custom shout filter
context.add_filter;
let output = template.render;
assert_eq!;
Create your own tags
Tags are made up of two parts, the initialization and the rendering.
Initialization happens when the parser hits a Liquid tag that has your
designated name. You will have to specify a function or closure that will
then return a Renderable
object to do the rendering.
use ;
// our renderable object
let mut options : LiquidOptions = Default default;
// initialize the tag and pass a closure that will return a new Shout renderable
options.register_tag;
// use our new tag
let template = parse.unwrap;
let mut context = new;
let output = template.render;
assert_eq!;
Create your own tag blocks
Blocks work very similar to Tags. The only difference is that blocks contain other
markup, which is why block initialization functions take another argument, a list
of Element
s that are inside the specified block.
For an implementation of a Shout
block, see this example.