daqing/moon-templ/runtime does not have a README file

    AsURL

    pub(open) trait AsURL {
    fn as_url(Self) -> SafeURL
    }

    What a href={ ... }, action={ ... } or data={ ... } may hold. templ's JoinURLErrs[T ~string] takes any string type and asks at run time whether the value is already a SafeURL; here the value says which it is through this trait, and a template's own type says the same by implementing it.

    The check templ makes at run time is the one that keeps a SafeURL out of the whitelist — templ.SafeURL("javascript:…") is rendered as written — and that is what the two implementations below say: a string is a URL to be sanitized, a SafeURL is one already.
    impl AsURL for String

    Attributer

    pub(open) trait Attributer {
    fn items(Self) -> Array[KV[String, AttributeValue]]
    }

    What { attrs... } can spread. The generated call takes anything that can name its items, which is how a caller with attributes of its own can spread them: Map is the core library's type, so a map is wrapped in Attributes rather than made an Attributer itself.

    Stylable

    pub(open) trait Stylable {
    fn sanitized(Self) -> String
    }

    What a style={ ... } attribute may hold. templ switches on the value's dynamic type; here the value says what it is by which implementation it takes, and a plain String — the common case, and the one templ's own golden opens with — is one of them.

    The value a Stylable renders is the one SanitizeStyleAttributeValues returns: each piece escaped for its place between the quotes. The attribute escapes that whole result again, exactly as templ's generator does, which is why a value holding an & comes out as & here as well.
    impl Stylable for String

    AttributeValue

    pub(all) enum AttributeValue {
    Value(String)
    Flag(Bool)
    Conditional(KV[String, Bool])
    }

    The value of one attribute in a { attrs... } spread.

    templ carries these in a map[string]any and switches on the dynamic type while rendering. MoonBit has no such type, so the cases templ's switch held are the variants here.

    Attributes

    pub(all) struct Attributes {
    // private fields
    }

    A set of spread attributes, which is what { attrs... } hands to render_attributes.

    templ models this as an interface over either a map or a slice. MoonBit does not let a package implement a trait for a type it does not own, and Map belongs to the core library, so those two shapes meet in one struct built by one of two constructors rather than in two implementations of Attributer.

    Attributes::from_map

    fn Attributes::from_map(attributes : Map[String, AttributeValue]) -> Attributes

    The attributes of a map, rendered in name order — templ's templ.Attributes. Which order the map was written in does not reach the output: a map has none of its own, and templ sorts one by key for the same reason.

    templ sorts at render time; here the sort happens once, at construction, because nothing can reach items afterwards.

    Attributes::items

    fn Attributes::items(self : Attributes) -> Array[KV[String, AttributeValue]]

    Attributes::ordered

    fn Attributes::ordered(items : Array[KV[String, AttributeValue]]) -> Attributes

    The attributes in the order they were given — templ's templ.OrderedAttributes.

    CSSClass

    pub(all) enum CSSClass {
    Name(String)
    Toggle(KV[String, Bool])
    }

    One class of a class list: a name that is always there, or a name that is there only while its flag holds.

    templ takes any here and switches on the dynamic type — a plain string, a templ.KV, a map of names to flags. MoonBit has no such type, so the list is written out instead, and the maps templ accepted are read by the caller.

    CSSClasses

    pub(all) struct CSSClasses {
    // private fields
    }

    A list of class names, templ's templ.CSSClasses. class={ ... } renders it into one attribute value.
    impl Show for CSSClasses

    CSSClasses::new

    fn CSSClasses::new(items : Array[CSSClass]) -> CSSClasses

    CSSClasses::output

    fn CSSClasses::output(self : CSSClasses, logger : &Logger) -> Unit

    CSSClasses::to_string

    fn CSSClasses::to_string(self : CSSClasses) -> String

    Component

    pub struct Component {
    // private fields
    }

    impl Show for Component

    Component::nop

    fn Component::nop() -> Component

    Component::output

    fn Component::output(self : Component, logger : &Logger) -> Unit

    Component::render

    fn Component::render(self : Component, ctx : RenderCtx, w : &Logger) -> Unit

    Component::to_string

    fn Component::to_string(self : Component) -> String

    Component::with_children

    fn Component::with_children(self : Component, children : Component) -> Component

    ComponentScript

    pub(all) struct ComponentScript {
    call : String
    }

    A script a template calls from an event attribute: templ's templ.ComponentScript.

    call is the JavaScript that invokes the function — name, parameters and all — and it is written into the attribute as it stands. Nothing escapes it again, because the parameters were escaped when the call was built, which is why the quotes of a string parameter arrive as ".

    templ's Name, Function and CallInline are what a script block needs to be defined and rendered, and RenderScriptItems is how those definitions reach the page. Neither is here yet: this type is what an event attribute's expression is expected to be, and T6.2 is where a script block becomes one.

    ComponentScript::new

    fn ComponentScript::new(call : String) -> ComponentScript

    pub(all) struct KV[K, V] {
    key : K
    value : V
    }

    A name and a value together, templ's templ.KeyValue. A spread attribute and a CSS class both pair a name with a flag that says whether it applies, which is what templ's templ.KV builds.

    RenderCtx

    pub struct RenderCtx {
    children : Component
    nonce : String
    }

    RenderCtx::clear_children

    fn RenderCtx::clear_children(self : RenderCtx) -> RenderCtx

    RenderCtx::new

    fn RenderCtx::new() -> RenderCtx

    RenderCtx::with_children

    fn RenderCtx::with_children(self : RenderCtx, children : Component) -> RenderCtx

    SafeCSS

    pub(all) struct SafeCSS {
    // private fields
    }

    A CSS value the caller vouches for: templ's templ.SafeCSS and templ.SafeCSSProperty. It is escaped for its place in the attribute but never handed to the sanitizer.
    impl Stylable for SafeCSS

    SafeCSS::new

    fn SafeCSS::new(value : String) -> SafeCSS

    SafeCSS::sanitized

    fn SafeCSS::sanitized(self : SafeCSS) -> String

    SafeURL

    pub(all) struct SafeURL {
    // private fields
    }

    A URL the caller vouches for: templ's templ.SafeURL. A value of this type goes into its attribute as it was given — sanitize_url leaves it alone — which is the point of the type: a template that knows where its URL came from says so, and one that does not hands over a string.
    impl AsURL for SafeURL
    impl Show for SafeURL

    SafeURL::as_url

    fn SafeURL::as_url(self : SafeURL) -> SafeURL

    SafeURL::new

    fn SafeURL::new(value : String) -> SafeURL

    SafeURL::output

    fn SafeURL::output(self : SafeURL, logger : &Logger) -> Unit

    SafeURL::to_string

    fn SafeURL::to_string(self : SafeURL) -> String

    Style

    pub(all) struct Style {
    // private fields
    }

    A list of pieces: what style={ ... } renders, and the MoonBit spelling of templ's SanitizeStyleAttributeValues(values ...any).
    impl Stylable for Style

    Style::from_map

    fn Style::from_map(properties : Map[String, String]) -> Style

    The declarations of a map, rendered in property-name order — templ's map[string]string, which it sorts for the same reason, a map having no order of its own.

    Style::from_trusted_map

    fn Style::from_trusted_map(properties : Map[String, SafeCSS]) -> Style

    The declarations of a map whose values the caller vouches for — templ's map[string]templ.SafeCSSProperty.

    Style::new

    fn Style::new(parts : Array[StylePart]) -> Style

    Style::sanitized

    fn Style::sanitized(self : Style) -> String

    StylePart

    pub(all) enum StylePart {
    Text(String)
    Trusted(SafeCSS)
    Property(KV[String, String])
    TrustedProperty(KV[String, SafeCSS])
    Toggle(KV[String, Bool])
    TrustedToggle(KV[SafeCSS, Bool])
    }

    One piece of a style attribute. templ takes ...any and switches on the dynamic type, reflection included; MoonBit has neither any nor reflection, so the shapes that switch handles by name are the variants here, and the shapes it reached by reflection — a function, a slice of anything — are written out by the caller as the variants they hold.

    component

    fn component(render : (RenderCtx, &Logger) -> Unit) -> Component

    escape

    fn escape(s : String) -> String

    failed_sanitization_url

    fn failed_sanitization_url() -> SafeURL

    What a URL that fails the whitelist becomes: templ's FailedSanitizationURL, a URL no browser follows and no template author misses in the output.
    fn[K, V] kv(key : K, value : V) -> KV[K, V]

    raw

    fn raw(s : String) -> Component

    render_attributes

    fn[A : Attributer] render_attributes(w : &Logger, attributes : A) -> Unit

    { attrs... } writes the whole of each attribute, separator included, so the literal run of the start tag breaks around it. Names and values are escaped here, the way templ's RenderAttributes escapes them.

    resolve_attribute_value

    fn[T : Show] resolve_attribute_value(v : T) -> String

    The value of a name={ expr } attribute, escaped for its place inside a double-quoted attribute value. templ's ResolveAttributeValue does the same for every value type that is not a script or a URL, and those two get their own handling later.

    sanitize_style_attribute_value

    fn[A : Stylable] sanitize_style_attribute_value(v : A) -> String

    The value of a style={ ... } attribute, ready to be written between the quotes of the attribute: the sanitized value, escaped once more.

    sanitize_url

    fn[A : AsURL] sanitize_url(v : A) -> String

    The value of a URL attribute, ready to be written between its quotes: the URL the value resolves to, escaped. templ escapes it too — its generator writes EscapeString around the SafeURL it resolved — so the apostrophes of a javascript: that a SafeURL let through come out as '.

    url

    fn url(value : String) -> SafeURL

    templ's URL: a URL naming one of the six schemes it knows is handed back, and one naming any other becomes the failed-sanitization URL — a javascript: is exactly what this is here to stop.

    A scheme is the text before the first :, and only counts as one when no / comes before it: a/b:c is a path with a colon in it, not a scheme named a/b.

    write_any

    fn[T : Show] write_any(w : &Logger, v : T) -> Unit

    write_escaped

    fn write_escaped(w : &Logger, s : String) -> Unit