glemplate/ast
The abstract syntax tree that templates are stored as in memory. This AST can be rendered with the renderer module.
Types
A dynamic node is used for dynamic behaviour in a template.
pub type DynamicNode {
Output(Var)
RawOutput(Var)
If(Var, if_true: NodeList, if_false: NodeList)
Iter(over: Var, binding: VarName, NodeList)
Render(tpl: TemplateName, assigns_map: List(#(Var, VarName)))
}
Constructors
-
Output(Var)
Output the variable, encoded.
-
RawOutput(Var)
Output the variable, without encoding.
-
If(Var, if_true: NodeList, if_false: NodeList)
Render a node list based on if the assign is truthy (non-false).
-
Iter(over: Var, binding: VarName, NodeList)
Iterate over the variable, bind it to a new name, and render the node list for every item.
-
Render(tpl: TemplateName, assigns_map: List(#(Var, VarName)))
Render the given template, using the assigns mapping. The assigns mapping is a list of tuples
(from, to)
, where thefrom
named assigns are available withto
names in the child template.
pub type Node {
Text(String)
Dynamic(DynamicNode)
Nodes(nodes: NodeList)
}
Constructors
-
Text(String)
-
Dynamic(DynamicNode)
-
Nodes(nodes: NodeList)
pub type Template {
Template(name: TemplateName, nodes: NodeList)
}
Constructors
-
Template(name: TemplateName, nodes: NodeList)
A reference to a template with the given name.
pub type TemplateName =
String
A reference to a variable input.
pub type Var {
Assign(name: VarName)
FieldAccess(container: Var, field: String)
IndexAccess(container: Var, index: Int)
}
Constructors
-
Assign(name: VarName)
Reference to an assign with the given name.
-
FieldAccess(container: Var, field: String)
Accessing a field of an associative container.
-
IndexAccess(container: Var, index: Int)
Accessing an item in an indexable container.