A spec-compliant Mustache template engine in pure MoonBit.
moon add Lyllyl789/mustacheimport {
"Lyllyl789/mustache/mustache",
}fn main {
let template = "Hello {{name}}! Welcome to {{location}}."
let context : Json = {
"name": "Lu Yilu",
"location": "Beijing, China"
}
try {
let output = @mustache.render_string(template, context)
println(output)
} catch {
ParseError(msg) => println("Parse error: \{msg}")
RenderError(msg) => println("Render error: \{msg}")
}
}moon run examples/simple
moon run examples/partialsmoon check
moon build --target all
moon fmt --check
moon info
moon testlet options = @mustache.RenderOptions::new(
max_partial_depth=32,
missing_partial_is_error=true,
)
let html = @mustache.render_string_with_options(
template,
context,
partials,
options,
)let plan = @mustache.TemplatePlan::compile("Hello {{>card}} {{name}}")
let partials : Map[String, String] = { "card": "<b>{{name}}</b>" }
let options = @mustache.RenderOptions::new(
max_output_chars=100000,
max_nodes=10000,
max_context_depth=32,
missing_partial_is_error=true,
)
let output = plan.render_checked(
{ "name": "MoonBit" },
partials~,
options~,
)| Area | Supported behavior | Boundary covered by tests |
|---|---|---|
| Lookup | names, dotted paths, . iterator | missing keys, nested objects, arrays |
| Sections | truthy values, arrays, objects, inverted sections | empty arrays, false, null, nested contexts |
| Escaping | HTML escaping and triple/ampersand raw output | &, <, >, quotes, apostrophes, non-BMP Unicode |
| Layout | comments, standalone lines, CRLF, indented partials | inline vs standalone tags |
| Syntax | delimiter changes and nested sections | mismatched/unclosed tags |
| Partials | nesting, recursion, inherited context | missing partials and depth limits |
| Safety limits | output, AST nodes, context frames | deterministic limit errors |
| Tooling | metrics, validation, cache, batch, bundle, catalog | dependency graph checks |
| Diagnostics | source normalization and locations | BOM, CRLF/CR, clamped offsets |
moon version --all
moon update
moon check --target all --deny-warn
moon build --target all
moon fmt --check
moon info
moon test --target all
moon run examples/simple
moon run examples/partials
moon run examples/complex_htmlA spec-compliant Mustache template engine in pure MoonBit.