Fab.Template (fab v1.2.2)

Dynamically generate formatted text using EEx templates.

Fab.Template defines EEx templates with bindings resolved at runtime via {module, function, args} tuples or static string values. Useful when fake data must match a specific format, such as localized output in locale modules.

Summary

Functions

Renders the template by evaluating its bindings and applying them to the EEx source.

Types

binding_t()

@type binding_t() :: {atom(), {module(), atom(), list()} | String.t()}

t()

@type t() :: %Fab.Template{bindings: [binding_t()], source: String.t()}

Functions

render(template)

(since 1.2.0)
@spec render(t()) :: String.t()

Renders the template by evaluating its bindings and applying them to the EEx source.

Each binding must be a {module, function, args} tuple or a static string. If the binding is an MFA it will be invoked at render time. If the binding is a string it will be used as-is. The results are passed as the template context.

Returns the rendered string.