lightspeed/component/template_ergonomics
Template ergonomics helpers and migration-hint diagnostics for M39.
Types
Attribute alias with migration guidance.
pub type AttrAlias {
AttrAlias(
alias: String,
canonical: String,
migration_hint: String,
)
}
Constructors
-
AttrAlias( alias: String, canonical: String, migration_hint: String, )
Ergonomic compile artifact with metadata.
pub type Compiled(assigns, slots) {
Compiled(
compiled: template_compiler.CompiledTemplate(assigns, slots),
applied_aliases: List(#(String, String)),
applied_slot_defaults: List(String),
signature: String,
)
}
Constructors
-
Compiled( compiled: template_compiler.CompiledTemplate(assigns, slots), applied_aliases: List(#(String, String)), applied_slot_defaults: List(String), signature: String, )
One deterministic compile diagnostic with actionable migration hint.
pub type Diagnostic {
Diagnostic(code: String, label: String, hint: String)
}
Constructors
-
Diagnostic(code: String, label: String, hint: String)
Ergonomic schema wrapper around the template compiler schema.
pub type ErgonomicSchema(assigns, slots) {
ErgonomicSchema(
schema: template_compiler.Schema(assigns, slots),
attr_aliases: List(AttrAlias),
slot_defaults: List(SlotDefault),
)
}
Constructors
-
ErgonomicSchema( schema: template_compiler.Schema(assigns, slots), attr_aliases: List(AttrAlias), slot_defaults: List(SlotDefault), )
Slot default used to reduce repetitive template composition boilerplate.
pub type SlotDefault {
SlotDefault(name: String, rendered: component.Rendered)
}
Constructors
-
SlotDefault(name: String, rendered: component.Rendered)
Values
pub fn applied_aliases(
compiled: Compiled(assigns, slots),
) -> List(#(String, String))
Applied alias migrations.
pub fn applied_slot_defaults(
compiled: Compiled(assigns, slots),
) -> List(String)
Applied slot defaults.
pub fn attr_alias(
alias: String,
canonical: String,
migration_hint: String,
) -> AttrAlias
Build one attr alias.
pub fn bool_attr(
name: String,
value: Bool,
) -> #(String, template_compiler.AttrValue)
Convenience constructor for bool attr input.
pub fn compile(
schema: ErgonomicSchema(assigns, slots),
attrs: List(#(String, template_compiler.AttrValue)),
slots: List(#(String, component.Rendered)),
) -> Result(Compiled(assigns, slots), List(Diagnostic))
Compile one ergonomic template invocation.
pub fn compiled_template(
compiled: Compiled(assigns, slots),
) -> template_compiler.CompiledTemplate(assigns, slots)
Underlying compiled template accessor.
pub fn diagnostics_signature(
diagnostics: List(Diagnostic),
) -> String
Stable diagnostics signature.
pub fn ergonomic_schema(
schema: template_compiler.Schema(assigns, slots),
attr_aliases: List(AttrAlias),
slot_defaults: List(SlotDefault),
) -> ErgonomicSchema(assigns, slots)
Build ergonomic schema wrapper.
pub fn int_attr(
name: String,
value: Int,
) -> #(String, template_compiler.AttrValue)
Convenience constructor for int attr input.
pub fn optional_bool(
attrs: List(#(String, template_compiler.AttrValue)),
name: String,
default: Bool,
) -> Result(Bool, String)
Optional bool accessor with fallback default.
pub fn optional_int(
attrs: List(#(String, template_compiler.AttrValue)),
name: String,
default: Int,
) -> Result(Int, String)
Optional int accessor with fallback default.
pub fn optional_string(
attrs: List(#(String, template_compiler.AttrValue)),
name: String,
default: String,
) -> Result(String, String)
Optional string accessor with fallback default.
pub fn required_slot_html(
slots: List(#(String, component.Rendered)),
name: String,
) -> Result(String, String)
Return one required slot HTML as string.
pub fn routine_schema(
name: String,
attrs: List(template_compiler.AttrSchema),
slots: List(template_compiler.SlotSchema),
build_assigns: fn(List(#(String, template_compiler.AttrValue))) -> Result(
assigns,
String,
),
render: fn(assigns, List(#(String, component.Rendered))) -> component.Rendered,
) -> template_compiler.Schema(
assigns,
List(#(String, component.Rendered)),
)
Build one routine schema that uses automatic slot passthrough.
pub fn signature(compiled: Compiled(assigns, slots)) -> String
Compiled artifact signature.
pub fn slot(
name: String,
rendered: component.Rendered,
) -> #(String, component.Rendered)
Convenience constructor for slot input.
pub fn slot_default(
name: String,
rendered: component.Rendered,
) -> SlotDefault
Build one slot default from rendered content.
pub fn slot_default_html(
name: String,
html: String,
) -> SlotDefault
Build one slot default from raw HTML.
pub fn slot_html(
name: String,
html: String,
) -> #(String, component.Rendered)
Convenience constructor for slot input from raw HTML.
pub fn slot_html_or_empty(
slots: List(#(String, component.Rendered)),
name: String,
) -> String
Return one optional slot HTML as string, defaulting to empty.
pub fn string_attr(
name: String,
value: String,
) -> #(String, template_compiler.AttrValue)
Convenience constructor for string attr input.