Sign in

    moonbitstack/moonctl/template does not have a README file

    FuncFn

    type FuncFn = (Array[Value]) -> Value raise TemplateError

    A pipeline function: it receives the already-evaluated argument list (with the piped-in value, if any, appended last, mirroring Go) and returns a Value.

    TemplateError

    pub suberror TemplateError {
    ParseError(String)
    ExecError(String)
    }

    A template parse or execution failure, carrying a human-readable message.

    Template

    pub struct Template {
    renderer : (Value) -> String raise TemplateError
    funcs : Map[String, (Array[Value]) -> Value raise TemplateError]
    }

    A parsed, reusable template — moonctl's text/template equivalent. Build it with Template::new, register extra functions with func, parse a source with parse, then render it against a Value any number of times. The parsed node tree stays private, captured inside renderer.

    Template::func

    fn Template::func(self : Template, name : String, f : (Array[Value]) -> Value raise TemplateError) -> Template

    Register (or override) a pipeline function, returning self for chaining — the analogue of Go's Template.Funcs. Register before parse.

    Template::new

    fn Template::new() -> Template

    A fresh template preloaded with the default function library. Rendering before parse yields the empty string.

    Template::parse

    fn Template::parse(self : Template, source : String) -> Template raise TemplateError

    Parse source into this template's node tree, returning self for chaining. Raises ParseError on a syntax error (unclosed action, dangling {{end}}, …).

    Template::render

    fn Template::render(self : Template, data : Value) -> String raise TemplateError

    Render the template against data, producing the output string. Raises ExecError on an execution fault (undefined variable/function, bad range target, …).

    Value

    pub(all) enum Value {
    Null
    Bool(Bool)
    Int(Int64)
    Float(Double)
    Str(String)
    List(Array[Value])
    Dict(Map[String, Value])
    }

    Dynamic template data. .Field lookups resolve against Dict; range iterates List (index/element) or Dict (sorted key/value). This is the explicit stand-in for the arbitrary Go values goctl reflects over.

    render

    fn render(source : String, data : Value) -> String raise TemplateError

    Parse and render source against data in one call, with the default function library.

    Source Files