hummingbird-project / swift-mustache

Mustache templating engine
Apache License 2.0
21 stars 2 forks source link

Add support for proper lambdas #48

Closed adam-fowler closed 4 weeks ago

adam-fowler commented 1 month ago

Variable lambda

let a = (
    this: "This",
    that: "That",
    random: MustacheLambda { Bool.random() ? "{{this}}" : "{{that}}" }
)
let template = try MustacheTemplate(string: "{{random}}")
let output = template.render(a)
print(output)

Results in either

This

or

That

Section lambda

let a = [
     "bold": MustachLambda { text in "<b>\(text)</b>" }
]
let template = try MustacheTemplate(string: "{{#bold}}text to render{{/bold}}")
let output = template.render(a)
print(output)

Results in

<b>text to render</b>
adam-fowler commented 1 month ago

@MahdiBM would be interested in your thoughts