Sablon.Content behaviour (sablon v0.4.4)

Copy Markdown View Source

The values that can be inserted into a template.

Every content type knows how to render itself into the document at the position of a merge field. Types are registered in Sablon.Registry and can be extended by implementing this behaviour.

Summary

Callbacks

Renders the content into paragraph, replacing display_node (the w:t element of the merge field).

Builds the content struct from the user supplied arguments.

The identifier used by Sablon.content/2, e.g. :word_ml.

Whether this type should be used to wrap a bare, unwrapped value.

Functions

Renders content at the position of display_node.

Builds a content value of the given type.

Registers a content type module.

Removes a content type, by id or by module.

Wraps a plain value in the content type that claims it.

Callbacks

append_to(struct, t, t, t)

@callback append_to(
  struct(),
  Sablon.XML.Node.t(),
  Sablon.XML.Node.t(),
  Sablon.Environment.t()
) :: any()

Renders the content into paragraph, replacing display_node (the w:t element of the merge field).

build(list)

@callback build(list()) :: struct()

Builds the content struct from the user supplied arguments.

id()

@callback id() :: atom()

The identifier used by Sablon.content/2, e.g. :word_ml.

wraps?(term)

@callback wraps?(term()) :: boolean()

Whether this type should be used to wrap a bare, unwrapped value.

Functions

append_to(content, paragraph, display_node, env)

Renders content at the position of display_node.

make(type_id, args \\ [])

@spec make(atom(), list()) :: struct()

Builds a content value of the given type.

register(module)

@spec register(module()) :: :ok

Registers a content type module.

remove(id_or_module)

@spec remove(atom() | module()) :: :ok

Removes a content type, by id or by module.

wrap(value)

@spec wrap(term()) :: struct()

Wraps a plain value in the content type that claims it.

Content structs are returned unchanged.