-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.mbt
More file actions
29 lines (29 loc) · 846 Bytes
/
Copy pathmain.mbt
File metadata and controls
29 lines (29 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
///|
fn main {
let engine = @mold.Engine::new().with_loader(fn(name) {
match name {
"header" => Some("Report: {{ title }}\n")
"item" => Some("- {{ item.name }} x {{ item.count }}\n")
"footer" => Some("Owner: {{ owner }}")
_ => None
}
})
let template_source =
#|{% include "header" %}
#|{% for item in items %}{% include "item" %}{% endfor %}
#|{% include "footer" %}
let output = engine.render(
template_source,
@mold.object({
"title": @mold.string("Weekly Stock"),
"owner": @mold.string("Moon Market"),
"items": @mold.array([
@mold.object({ "name": @mold.string("apple"), "count": @mold.int(12) }),
@mold.object({ "name": @mold.string("banana"), "count": @mold.int(8) }),
]),
}),
) catch {
_ => "render failed"
}
println(output)
}