Rust-DTL
Rust-DTL compiles Django Template Language.
This project is inspired by ideas: https://github.com/erlydtl/erlydtl/
Example
An Django template is a text file (e.g.: a HTML or CSS file) containing variables to control the runtime template content, tags to control the runtime template logic and comments, which get filtered out.
views/welcome.html
{% extends "layouts/main.html" %}
{% block title %}Welcome Page{% endblock %}
{% block content %}replacing the base content - variable: {{ test_var }} after variable {% endblock %}
views/layouts/main.html
MySite - {% block title %}{% endblock %}
{# TODO: add more text! #}
{% block head %}Where my head?!{% endblock %}
Hello, {{username}}!
{% block content %}Some text...{% endblock %}
main.rs
extern crate dtl;
use std::path::Path;
use std::error::Error;
use dtl::{Context, Template};
fn main() {
let mut ctx = Context::new();
ctx.set("username", Box::new("Ivan Ivanov".to_string()));
ctx.set("test_var", Box::new("test-barstring".to_string()));
let mut tpl = Template::new(Path::new("welcome.html"), Path::new("examples/views/"));
match tpl.compile() {
Ok(_) => {},
Err(e) => panic!("{}", e),
};
println!("{}", tpl.render(&mut ctx));
}
output
MySite - Welcome Page
Where my head?!
Hello, Ivan Ivanov!
replacing the base content - variable: test-barstring after variable some text
License
Rust-DTL is released under the MIT license.