Crates.io | crabtml |
lib.rs | crabtml |
version | 0.1.9 |
source | src |
created_at | 2024-10-08 21:53:10.082595 |
updated_at | 2024-10-09 23:41:25.987426 |
description | A simple and flexible template engine written in Rust. |
homepage | |
repository | https://github.com/trvswgnr/crabtml |
max_upload_size | |
id | 1401726 |
size | 34,918 |
CrabTML is a lightweight and flexible template engine written in Rust. It provides a simple yet powerful way to render dynamic content in your applications.
[!WARNING]
This project is still in early development and is not recommended for production use.
Add this to your Cargo.toml
:
[dependencies]
crabtml = "0.1.0"
Here's a quick example of how to use CrabTML:
use crabtml::{TemplateEngine, Value, Context};
use std::collections::HashMap;
fn main() {
let mut engine = TemplateEngine::new();
// Load a template from a string
engine.add_template_from_string("example", "hello {{ text }}").unwrap();
// Create a context
let mut context = Context::new();
context.set(
"text",
"darkness my old friend",
);
// Render the template
let result = engine.render("example", &mut context).unwrap();
println!("{}", result); // -> hello darkness my old friend
// You can also create a context using the `context!` macro,
// and objects using the `object!` macro
use crabtml::{context, object};
let mut context = context! {
"text" => "darkness my old friend",
"user" => object! {
"name" => "trav",
"age" => 35,
},
};
}
For more detailed examples, check the tests
module in the source code.
CrabTML supports the following syntax:
{{ variable_name }}
{% if condition %} ... {% else %} ... {% endif %}
{% for item in items %} ... {% endfor %}
{{ user.name }}
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.