moonbitstack/moonctl/template does not have a README file

    FuncFn

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

    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.

    Refused

    pub(all) suberror Refused {
    ParseError(String)
    ExecError(String)
    }

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

    MissingKey

    pub(all) enum MissingKey {
    Zero
    Literal
    Error
    }

    What a {{.Field}} that names no key does (Go's missingkey option).

    Template

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

    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 Refused) -> 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::options

    fn Template::options(self : Template, opts : TemplateOptions) -> Template

    Set the behaviour switches — a missing key's fate, and how much whitespace an action takes — returning self for chaining. Set them before parse: the trimming happens while the source is being read.

    Template::parse

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

    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 Refused

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

    TemplateOptions

    pub(all) struct TemplateOptions {
    missing_key : MissingKey
    trim : Trim
    }

    The engine's behaviour switches: what a missing key does, and how much whitespace an action takes with it.

    Trim

    pub(all) enum Trim {
    Markers
    Actions
    BlankLines
    }

    Whether whitespace around an action is trimmed, beyond the {{- and -}} markers the template writes.

    Value

    pub(all) enum Value {
    Null
    Missing
    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.

    default_options

    let default_options : TemplateOptions

    The options a template is built with when none are asked for: a missing key is nothing, and only the markers trim — what this engine has always done, and what a template ported from Go expects.

    parse_option

    fn parse_option(text : String) -> TemplateOptions raise Refused

    The options Go's text/template spells as strings, read the same way: missingkey=zero, missingkey=default (or invalid), missingkey=error, and trim=markers, trim=actions, trim=blanklines. An unknown name is refused rather than silently taken for the default.

    render

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

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

    Source Files