Expand description
ยงMinilate
A templating engine prioritising minimal binary size and speed at the cost of feature set.
ยง๐ Quick Start
use minilate::{MinilateEngine, Context, VariableTy, MinilateInterface};
// Create engine and add template
let mut engine = MinilateEngine::new();
engine.add_template("hello", "Hello, {{ name }}!").unwrap();
// Create context
let mut context = Context::new();
context.insert("name", VariableTy::String.with_data("World".to_string()));
// Render
let result = engine.render("hello", Some(&context)).unwrap();
assert_eq!(result, "Hello, World!");ยงโก Performance
Minilate is designed for only a core feature set, but maximised performance and minimised binary size.
| Engine | Binary Size | Rel. Size | Time/Template | Rel. Perf. |
|---|---|---|---|---|
| Minilate | 1.56 MB | 1.00x | 205.08 ยตs | 1.00x |
| Handlebars | 1.75 MB | 1.12x | 776.79 ยตs | 3.79x |
| MiniJinja | 2.00 MB | 1.28x | 438.03 ยตs | 2.154 |
๐ Minilate achieves 12-28% smaller binaries while being ~2-4x faster than alternatives.
Benchmarks: 100 complex templates ร 50 iterations each. Template includes conditionals, loops, and nested data. See Benchmarking for details.
ยง๐ Features
- Simple replacements using
{{ variable }} - Conditional blocks with boolean logic using
{{% if <condition> %}},{{% else if %}}, and{{% else %}}- NOT:
! - AND:
&& - OR:
||
- NOT:
- For loops with
{{% for var in iterable %}} - Nested template injection using
{{<< <template_file_name>.tmpl }} - Escaping with
\{{or\{{%
ยง๐ ๏ธ Installation
Add this to your Cargo.toml:
[dependencies]
minilate = "0.1"ยง๐ Examples
ยงBasic Variable Substitution
Welcome to {{ site_name }}!
Your username is {{ user.name }}.ยงConditional Logic
{{% if user && is_active %}}
Hello, {{ user }}! You have {{ message_count }} new messages.
{{% elif !is_active %}}
Your account is inactive. Please contact support.
{{% else %}}
Hello, Guest! Please log in to continue.
{{% endif %}}ยงLoops and Nested Data
# Shopping Cart
{{% if items %}}
Total items: {{ item_count }}
{{% for item in items %}}
- {{ item.name }} ({{ item.quantity }}x) - ${{ item.price }}
{{% if item.special %}}**ON SALE!**{{% endif %}}
{{% endfor %}}
Total: ${{ total_price }}
{{% else %}}
Your cart is empty.
{{% endif %}}ยงTemplate Inclusion
{{<< header.tmpl }}
# Main Content
{{ content }}
{{<< footer.tmpl }}ยงComplex Example
# User Profile: {{ user.name }}
{{% if user.active %}}
**Status:** Active User (Age: {{ user.age }})
{{% if show_details && has_access %}}
## Recent Activity
{{% for activity in recent_activities %}}
- {{ activity.date }}: {{ activity.description }}
{{% if activity.important %}}โ ๏ธ **Important**{{% endif %}}
{{% endfor %}}
{{% elif !has_access %}}
*You don't have permission to view activity details*
{{% endif %}}
{{% else %}}
**Status:** Inactive User
{{% endif %}}ยง๐ Benchmarking
To run benchmarks locally:
./scripts/benchmark.shThis script:
- Builds all benchmark binaries
- Runs performance tests against Minilate, Handlebars, and MiniJinja
- Analyzes binary sizes
- Compares results with previous runs
- Saves results for historical tracking
The benchmark tests template rendering with:
- 100 different contexts
- 50 iterations per engine
- Complex templates with conditionals, loops, and nested data
ยง๐ License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
ยง๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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.
Structsยง
- Context
- Holds the data (variables) available during template rendering.
- Minilate
Engine MinilateEngineis the primary implementation of theMinilateInterfacetrait, providing a complete templating engine for the Minilate system- Template
- A Template represents a parsed template that can be rendered with a context.
- Variable
Enumsยง
- Minilate
Error - Represents errors that can occur during the operation of the Minilate template engine.
- Variable
Ty - Specifies the type of a variable within a
Context.
Traitsยง
- Minilate
Interface MinilateEngineis a trait for the Minilate templating engine, an opinionated and minamalistic templating engine designed for use in offline, static, single-threaded environments.