Sablon.Template (sablon v0.4.4)

Copy Markdown View Source

A Word document used as a template.

Rendering reads the whole package into a Sablon.DOM.Model, runs every registered processor over the parts it applies to, and writes the result back out as a new .docx. The template itself is never modified.

Summary

Functions

Points at a template on disk.

The processors registered for a part.

Registers a processor for the parts whose name matches pattern.

Renders the template, returning both the .docx binary and the document model it was produced from. The model is useful for inspecting what a render did without unzipping the result again.

Renders the template and writes the result to output_path.

Renders the template and returns the resulting .docx as a binary.

Types

t()

@type t() :: %Sablon.Template{path: Path.t()}

Functions

new(path)

@spec new(Path.t()) :: t()

Points at a template on disk.

processors_for(entry_name)

@spec processors_for(binary()) :: [module()]

The processors registered for a part.

register_processor(pattern, module, opts \\ [])

@spec register_processor(Regex.t(), module(), keyword()) :: :ok

Registers a processor for the parts whose name matches pattern.

render(template, context, properties \\ %{})

@spec render(t(), map() | keyword(), map() | keyword()) ::
  {binary(), Sablon.DOM.Model.t()}

Renders the template, returning both the .docx binary and the document model it was produced from. The model is useful for inspecting what a render did without unzipping the result again.

The model holds the parsed document in the calling process; call Sablon.DOM.Model.drop/1 when done with it, or use render_to_string/3, which cleans up on its own.

render_to_file(template, output_path, context, properties \\ %{})

@spec render_to_file(t(), Path.t(), map() | keyword(), map() | keyword()) :: :ok

Renders the template and writes the result to output_path.

render_to_string(template, context, properties \\ %{})

@spec render_to_string(t(), map() | keyword(), map() | keyword()) :: binary()

Renders the template and returns the resulting .docx as a binary.