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

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

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.

Search Document