A lightweight, high-performance Mustache-style template engine in MoonBit.
moon add LL124-Arch/stencilimport {
"LL124-Arch/stencil/src" @stencil,
}fn main {
let template = "Hello {{name}}! Welcome to {{project}}."
let data : Json = {
"name": "Developer",
"project": "Stencil",
}
try {
let result = @stencil.render(template, data)
println(result)
} catch {
@stencil.TemplateError(msg) => println("Template error: \{msg}")
}
}Hello Developer! Welcome to Stencil.let options = @stencil.RenderOptions::default()
.with_max_output_length(1_000_000)
.with_missing_partial(@stencil.MissingPartialPolicy::Error)
let html = @stencil.render_with_options_and_partials(template, data, partials, options)moon run cli -- analyze
moon run cli -- compatibility
moon run cli -- benchmarklet tpl = "<p>{{content}}</p>"
let result = @stencil.render(tpl, { "content": "<script>alert(1)</script>" })
// <p><script>alert(1)</script></p>let tpl = @stencil.compile("User: {{name}}")
println(tpl.render({ "name": "Alice" }))
println(tpl.render({ "name": "Bob" }))let template = "items:\n {{>item}}\ndone"
let partials = {
"item": "- {{name}}\n- ready",
}
let data : Json = { "name": "Stencil" }
let result = @stencil.render_with_partials(template, data, partials)items:
- Stencil
- ready
donelet template =
"Hello {{user.name}},\n" +
"{{#items}}- {{title}}: {{status}}\n{{/items}}" +
"{{^items}}No pending tasks.\n{{/items}}"
let data : Json = {
"user": { "name": "Ops Team" },
"items": [
{ "title": "CI", "status": "green" },
{ "title": "Release", "status": "pending" },
],
}moon run climoon fmt --check
moon check --deny-warn --target all
moon build --target wasm,wasm-gc,js
moon info --target all
git diff --ignore-blank-lines --exit-code
moon test --deny-warn --target wasm,wasm-gc,jsmoon test --deny-warn --target native
moon build --target nativepowershell -ExecutionPolicy Bypass -File scripts\verify_acceptance.ps1powershell -ExecutionPolicy Bypass -File scripts\benchmark.ps1 -Iterations 5A lightweight, high-performance Mustache-style template engine in MoonBit.