Crates.io | rspack_dojang |
lib.rs | rspack_dojang |
version | 0.1.9 |
source | src |
created_at | 2024-08-22 08:10:28.391367 |
updated_at | 2024-08-28 03:56:17.14184 |
description | Dojang, a EJS like Html Template Engine. |
homepage | |
repository | |
max_upload_size | |
id | 1347416 |
size | 165,300 |
[!NOTE]
This is a fork of dojang, and will be used in Rspack to fix bugs and add some Rspack customized features.
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.
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"
);