glemplate/renderer
The renderer is given the template AST and some assigns, which it will render into a string output.
Types
Function to encode potentially dangerous contents into the template in a safe way. E.g. encode text with HTML entities in an HTML template.
pub type EncoderFn =
fn(String) -> string_tree.StringTree
pub type RenderError {
AssignNotFound(
assign: ast.Var,
assigns: dict.Dict(String, assigns.AssignData),
)
AssignNotIterable(
assign: ast.Var,
assigns: dict.Dict(String, assigns.AssignData),
)
AssignNotStringifiable(
assign: ast.Var,
assigns: dict.Dict(String, assigns.AssignData),
)
AssignFieldNotFound(
assign: ast.Var,
field: String,
assigns: dict.Dict(String, assigns.AssignData),
)
AssignNotFieldAccessible(
assign: ast.Var,
assigns: dict.Dict(String, assigns.AssignData),
)
ChildTemplateNotFound(tpl_name: String)
}
Constructors
-
AssignNotFound( assign: ast.Var, assigns: dict.Dict(String, assigns.AssignData), )A referenced assign was not found.
-
AssignNotIterable( assign: ast.Var, assigns: dict.Dict(String, assigns.AssignData), )A referenced assign was not iterable.
-
AssignNotStringifiable( assign: ast.Var, assigns: dict.Dict(String, assigns.AssignData), )A referenced assign could not be stringified.
-
AssignFieldNotFound( assign: ast.Var, field: String, assigns: dict.Dict(String, assigns.AssignData), )A referenced assign didn’t have the requested field.
-
AssignNotFieldAccessible( assign: ast.Var, assigns: dict.Dict(String, assigns.AssignData), )A referenced assign couldn’t be accessed with field access.
-
ChildTemplateNotFound(tpl_name: String)A referenced child template was not found in the template cache.
Rendering options:
encoder: Encoder function to use, it should encode dynamic content in a safe way for this template type.template_cache: A cache of templates that child templates are looked up from, when using Render nodes.
pub type RenderOptions {
RenderOptions(
encoder: fn(String) -> string_tree.StringTree,
template_cache: dict.Dict(String, ast.Template),
)
}
Constructors
-
RenderOptions( encoder: fn(String) -> string_tree.StringTree, template_cache: dict.Dict(String, ast.Template), )
pub type RenderResult =
Result(string_tree.StringTree, RenderError)
pub type StringifyError {
StringifyError
}
Constructors
-
StringifyError
A cache of templates to use for rendering child templates.
pub type TemplateCache =
dict.Dict(String, ast.Template)
Values
pub fn render(
template: ast.Template,
assigns: dict.Dict(String, assigns.AssignData),
opts: RenderOptions,
) -> Result(string_tree.StringTree, RenderError)
Render given template with the assigns and options.