#liquid #template #templating #language #html

bin liquid

The liquid templating language for Rust

35 releases (15 breaking)

0.15.0 Jul 30, 2018
0.14.2 Mar 16, 2018
0.13.6 Dec 29, 2017
0.12.0 Nov 29, 2017
0.0.1 Feb 15, 2015

#4 in Template engine

Download history 156/week @ 2018-05-10 58/week @ 2018-05-17 198/week @ 2018-05-24 316/week @ 2018-05-31 105/week @ 2018-06-07 293/week @ 2018-06-14 161/week @ 2018-06-21 525/week @ 2018-06-28 641/week @ 2018-07-05 118/week @ 2018-07-12 337/week @ 2018-07-19 247/week @ 2018-07-26 595/week @ 2018-08-02

1,250 downloads per month

liquid-rust Travis Status Appveyor Status Crates Status Coverage Status Dependency Status

Liquid templating for Rust

Usage

To include liquid in your project add the following to your Cargo.toml:

[dependencies]
liquid = "0.15"

Now you can use the crate in your code:

extern crate liquid;

Example:

extern crate liquid;

let template = liquid::ParserBuilder::with_liquid()
    .build()
    .parse("Liquid! {{num | minus: 2}}").unwrap();

let mut globals = liquid::Object::new();
globals.insert("num".to_owned(), liquid::Value::scalar(4f64));

let output = template.render(&globals).unwrap();
assert_eq!(output, "Liquid! 2".to_string());

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.

See filters.rs for what a filter implementation looks like. You can then register it by calling liquid::ParserBuilder::filter.

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.

See include_tag.rs for what a tag implementation looks like. You can then register it by calling liquid::ParserBuilder::tag.

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 Elements that are inside the specified block.

See comment_block.rs for what a block implementation looks like. You can then register it by calling liquid::ParserBuilder::block.

MIT license

Dependencies

Reverse deps