CommBus.Template (CommBus v0.1.0)

Copy Markdown View Source

Template rendering facade.

Summary

Functions

Renders a Mustache template string with the given variable bindings using the configured template engine.

Renders a Mustache template and returns only the content string, discarding render metadata. A convenience wrapper around render/3.

Renders a prompt struct's body template with the given variables, automatically incorporating the prompt's declared variable types and name.

Functions

render(template, values, opts \\ [])

@spec render(String.t(), map(), keyword()) ::
  {:ok, CommBus.Template.RenderResult.t()}
  | {:error, CommBus.Template.RenderError.t()}

Renders a Mustache template string with the given variable bindings using the configured template engine.

Parameters

  • template — A Mustache template string.
  • values — A map of variable names to values.
  • opts — Keyword options:
    • :engine — Template engine module (default from app config).
    • :strict_mode — Whether to raise on missing variables (default: engine-specific).
    • :types — Variable type declarations for coercion.
    • :partials — Map of partial name to template body.
    • :partials_func — Function that resolves partial names to bodies.

Returns

{:ok, %RenderResult{}} on success or {:error, %RenderError{}} on failure.

render_content(template, values, opts \\ [])

@spec render_content(String.t(), map(), keyword()) ::
  {:ok, String.t()} | {:error, CommBus.Template.RenderError.t()}

Renders a Mustache template and returns only the content string, discarding render metadata. A convenience wrapper around render/3.

Parameters

  • template — A Mustache template string.
  • values — A map of variable bindings.
  • opts — Keyword options forwarded to render/3.

Returns

{:ok, content_string} on success or {:error, %RenderError{}} on failure.

render_prompt(prompt, variables, opts \\ [])

Renders a prompt struct's body template with the given variables, automatically incorporating the prompt's declared variable types and name.

Parameters

  • prompt — A %CommBus.Template.Prompt{} struct with a :body template.
  • variables — A map of variable bindings.
  • opts — Keyword options forwarded to render/3.

Returns

{:ok, %RenderResult{}} on success or {:error, %RenderError{}} on failure.