MCPcopy Index your code
hub / github.com/cobalt-org/liquid-rust

github.com/cobalt-org/liquid-rust @liquid-core-v0.26.11

Chat with this repo
repository ↗ · DeepWiki ↗ · release liquid-core-v0.26.11 ↗ · + Follow
2,223 symbols 5,310 edges 162 files 317 documented · 14%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

liquid-rust

Liquid templating for Rust

Crates Status

Goals: 1. Conformant. Incompatibilities with strict shopify/liquid are bugs to be fixed. 2. Flexible. Liquid embraces variants for different domains and we want to follow in that spirit. 3. Performant. Do the best we can within what is conformant.

Example applications using liquid-rust: - cobalt: static site generator. - cargo-tarball: crate bin packaging tool. - cargo-generate: crate generator from templates. - Mandy: A hypersonic, easy-to-use, performant static-site generator.

Usage

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

$ cargo add liquid

Example:

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

let globals = liquid::object!({
    "num": 4f64
});

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

You can find a reference on Liquid syntax here.

Customizing Liquid

Language Variants

By default, liquid-rust has no filters, tags, or blocks. You can enable the default set or pick and choose which to add to suite your application.

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/ 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.

License

Licensed under either of

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.

Extension points exported contracts — how you extend this code

Filter (Interface)
A trait that holds a filter, ready to evaluate. # Deriving You cannot derive `Filter`, as it would go against the very [75 …
crates/core/src/parser/filter.rs
Renderable (Interface)
(no doc) [20 implementers]
crates/help-md/src/lib.rs
ParserReflection (Interface)
(no doc) [2 implementers]
src/reflection.rs
ParseTag (Interface)
A trait for creating custom tags. This is a simple type alias for a function. This function will be called whenever the [9 …
crates/core/src/parser/tag.rs
ParseBlock (Interface)
A trait for creating custom custom block-size tags (`{% if something %}{% endif %}`). This is a simple type alias for a [9 …
crates/core/src/parser/block.rs
ValueView (Interface)
Accessor for Values. [21 implementers]
crates/core/src/model/value/view.rs
PartialSource (Interface)
Partial-template source repository. [8 implementers]
crates/core/src/partials/mod.rs

Core symbols most depended-on inside this repo

into
called by 341
crates/core/src/model/ser.rs
parse
called by 118
crates/core/src/parser/parser.rs
build
called by 102
crates/core/src/runtime/runtime.rs
as_str
called by 99
crates/core/src/parser/parser.rs
render
called by 97
src/template.rs
render
called by 93
crates/help-md/src/lib.rs
filter
called by 85
src/parser.rs
build
called by 76
src/parser.rs

Shape

Function 1,037
Method 791
Class 340
Enum 28
Interface 27

Languages

Rust100%

Modules by API surface

crates/core/src/model/value/ser.rs84 symbols
tests/conformance_ruby/standard_filter_test.rs78 symbols
crates/lib/src/stdlib/filters/array.rs57 symbols
crates/core/src/parser/parser.rs57 symbols
crates/core/src/model/scalar/mod.rs55 symbols
crates/lib/src/stdlib/blocks/for_block.rs54 symbols
crates/lib/src/stdlib/filters/math.rs47 symbols
crates/lib/src/stdlib/blocks/if_block.rs46 symbols
crates/core/src/model/ser.rs46 symbols
crates/core/src/runtime/runtime.rs44 symbols
crates/core/src/model/object/map.rs41 symbols
crates/core/src/model/value/values.rs39 symbols

For agents

$ claude mcp add liquid-rust \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page