A small and fast precompiled template engine for MoonBit.
///|
#tplpath("templates/profile_card.mtpl")
pub(all) struct ProfileCard {
name : String
bio : @template.SafeHtml
}<article>
<h1><%= name |> trim |> upper %></h1>
<%- bio %>
</article>moon install justjavac/template_codegenoptions(
"pre-build": [
{
"input": [
"main.mbt",
"templates/profile_card.mtpl",
"templates/partials/footer.mtpl",
],
"output": "tpl.generated.mbt",
"command": "template_codegen --scan $input -o $output",
},
],
)///|
let page = ProfileCard::{
name: " justjavac ",
bio: @template.safe_html("<p>Trusted HTML</p>"),
}
///|
let html = try! page.render()pub(open) trait Render {
fn render(Self) -> String raise
}pub struct SafeHtml {
value : String
}fn default(value : String, fallback~ : String) -> Stringfn escape_html(value : String) -> Stringfn lower(value : String) -> Stringfn replace(value : String, old~ : String, new~ : String) -> Stringfn trim(value : String) -> Stringfn trim_end(value : String) -> Stringfn trim_start(value : String) -> Stringfn upper(value : String) -> StringA small and fast precompiled template engine for MoonBit.