HBMustacheLambda

public struct HBMustacheLambda

Lambda function. Can add this to object being rendered to filter contents of objects.

See http://mustache.github.io/mustache.5.html for more details on mustache lambdas. Lambdas work slightly differently in HummingbirdMustache though as they are passed a template representing the contained text and not the raw text e.g

struct Object {
    let name: String
    let wrapped: HBMustacheLambda
}
let willy = Object(name: "Willy", wrapped: .init({ object, template in
    return "<b>\(template.render(object))</b>"
}))
let mustache = "{{#wrapped}}{{name}} is awesome.{{/wrapped}}"
let template = try HBMustacheTemplate(string: mustache)
let output = template.render(willy)
print(output) // <b>Willy is awesome</b>
  • lambda callback

    Declaration

    Swift

    public typealias Callback = (Any, HBMustacheTemplate) -> String
  • Initialize HBMustacheLambda

    Declaration

    Swift

    public init(_ cb: @escaping Callback)

    Parameters

    cb

    function to be called by lambda