A simple, powerful template engine.
{{ user.name }}
{% if user.enabled %} ... {% endif %}
{% for user in users %} ... {% endfor %}
{{ user.name | lower }}
<? user.name ?>
, (( if user.enabled ))
serde
serializable values.upon::value!{ name: "John", age: 42 }
serde
" supportYour entry point is the compilation and rendering Engine
, this stores the
delimiter settings and filter functions. Generally, you only need to construct
one engine.
rust
let engine = upon::Engine::new();
Compiling a template returns a reference to it bound to the lifetime of the engine and the template source.
rust
let template = engine.compile("Hello {{ user.name }}!")?;
The template can then be rendered by calling .render()
.
rust
let result = template.render(upon::value!{ user: { name: "John Smith" }})?;
assert_eq!(result, "Hello John Smith!");
You can also use add_template(name, ...)
and get_template(name).render(...)
to store a template by name in the engine.
```rust let mut engine = upon::Engine::new(); engine.add_template("hello", "Hello {{ user.name }}!")?;
// later...
let template = engine.gettemplate("hello").unwrap(); let result = template.render(upon::value!{ user: { name: "John Smith" }})?; asserteq!(result, "Hello John Smith!"); ```
See more in the docs.
The following shows a violin plot of the benchmark results for upon
compared
to the following template rendering engines.
- handlebars
- minijinja
- tera
- tinytemplate
Obviously, each of these engines has a completely different feature set so this
just compares the performance for some of the features that upon
supports.
Host - MacBook Pro (14-inch, 2021) - Chipset: Apple M1 Pro - Memory: 16 GB
Licensed under either of
at your option.