#html-template #html #template

rspack_dojang

Dojang, a EJS like Html Template Engine

5 releases

0.1.11 Feb 11, 2025
0.1.10 Jan 13, 2025
0.1.9 Aug 28, 2024
0.1.8 Aug 23, 2024
0.1.7 Aug 22, 2024

#52 in Template engine

Download history 202/week @ 2024-11-21 254/week @ 2024-11-28 275/week @ 2024-12-05 351/week @ 2024-12-12 434/week @ 2024-12-19 237/week @ 2024-12-26 319/week @ 2025-01-02 443/week @ 2025-01-09 466/week @ 2025-01-16 208/week @ 2025-01-23 68/week @ 2025-01-30 544/week @ 2025-02-06 421/week @ 2025-02-13 293/week @ 2025-02-20 331/week @ 2025-02-27 167/week @ 2025-03-06

1,308 downloads per month
Used in 3 crates (via rspack_plugin_html)

MIT license

165KB
4.5K SLoC

rspack_dojang

[!NOTE]
This is a fork of dojang, and will be used in Rspack to fix bugs and add some Rspack customized features.

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 rspack_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