7 releases

0.1.6 Jul 25, 2021
0.1.5 Jun 18, 2021
0.1.0 May 31, 2021

#221 in Template engine

Download history 254/week @ 2024-07-20 519/week @ 2024-07-27 226/week @ 2024-08-03 297/week @ 2024-08-10 192/week @ 2024-08-17 59/week @ 2024-08-24 62/week @ 2024-08-31 70/week @ 2024-09-07 59/week @ 2024-09-14 76/week @ 2024-09-21 69/week @ 2024-09-28 55/week @ 2024-10-05 59/week @ 2024-10-12 32/week @ 2024-10-19 25/week @ 2024-10-26 34/week @ 2024-11-02

160 downloads per month
Used in 2 crates (via rspack_plugin_html)

MIT license

160KB
4K SLoC

Dojang

Test and Coverage

Dojang is a Html template engine, as a drop in replacement for EJS. Though it does not supports 100% of the javascript syntax, it supports enough to cover the basic usages.

Features

  • Supports basic javascript. (if, for, while, etc.)
  • Supports script and output tags. (<%, <%-, <%=)
  • Supports calling external functions.

How to use?

use dojang::Dojang;
use serde_json::Value;

// Create a template engine Dojang.
let mut dojang = Dojang::new();

// Load template file under '/my/template/files'
assert!(dojang.load("/my/template/files").is_ok());

// Render a template. "some_template" is the one of the template file under /my/template/files. 
// Note that the context should be provided as a serde_json value.
assert_eq!(
    dojang
        .render(
            "some_template",
            serde_json::from_str(r#"{ "a" : 1 }"#).unwrap()
        )
        .unwrap(),
    " Hi "
    );

assert_eq!(
    dojang
        .render(
            "some_template",
            serde_json::from_str(r#"{ "a" : 2 }"#).unwrap()
        )
        .unwrap(),
    "2"
    );

Features coming soon.

  • Support for file includes (<%- .. >)
  • Optimization.

Dependencies

~0.6–1.1MB
~24K SLoC