A small and fast precompiled template engine for MoonBit.
///|
#tpl.path("templates/profile_card.mtpl")
pub(all) struct ProfileCard {
name : String
bio : @template.SafeHtml
}<article>
<h1><%= name |> trim |> upper %></h1>
<%- bio %>
</article>moonx justjavac/template_codegen --scan main.mbt templates/profile_card.mtpl -o tpl.generated.mbtoptions(
"pre-build": [
{
"input": [
"main.mbt",
"templates/profile_card.mtpl",
"templates/partials/footer.mtpl",
],
"output": "tpl.generated.mbt",
"command": "moonx justjavac/template_codegen@0.1.4 --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) -> StringInstall
Download zipA small and fast precompiled template engine for MoonBit.