Eml.Template

Templates in Eml are simple structures that contain rendererd chunks of eml, optionally interleaved with parameters.

A template is created when you compile some block of eml. Templates can also be precompiled at compile time by using the Eml.precompile/2 macro.

Example:

iex> use Eml.Language.HTML
iex> t = div class: "photo" do
...>   div do
...>     img [src: :url, alt: :title]
...>     p :title
...>   end
...> end |> Eml.compile
#Template<[:title, :url]>
iex> t = Template.bind(t, url: "http://i.imgur.com/4xPWp.jpg")
#Template<[:title]>
iex> Eml.render(t, title: "Little duck")
"<div class='photo'><div><img alt='Little duck' src='http://i.imgur.com/4xPWp.jpg'/><p>Little duck</p></div></div>"
Source

Summary

bind(t, new)

Binds values to parameters by providing a Keyword list where the Keyword keys are parameter ids

bind(t, param_id, data)

Binds a value to parameters by providing a parameter ids and value

bound?(t)

Checks if all parameters in the template are bound

unbind(t, param_id)

Unbinds previously binded values by providing a list of parameter ids

unbound(template)

Lists all parameter ids that are not yet bound to a value

Types

chunks :: [binary | Eml.Parameter.t]

t :: %Eml.Template{chunks: chunks, bindings: bindings}

Functions

bind(t, new)

Specs:

Binds values to parameters by providing a Keyword list where the Keyword keys are parameter ids.

Source
bind(t, param_id, data)

Specs:

Binds a value to parameters by providing a parameter ids and value.

Source
bound?(t)

Specs:

  • bound?(t) :: boolean

Checks if all parameters in the template are bound.

Example

iex> use Eml.Language.HTML
iex> t = Eml.compile(div [id: :id], :content)
#Template<[:id, :content]>
iex> Template.bound?(t)
false
iex> t = Template.bind(t, id: "some_id", content: "some content")
iex> Template.bound?(t)
true
Source
unbind(t, param_id)

Specs:

Unbinds previously binded values by providing a list of parameter ids.

Note that it’s not possible to unbind values after a template is compiled.

Source
unbound(template)

Specs:

Lists all parameter ids that are not yet bound to a value.

Example

iex> use Eml
iex> t = Eml.compile(div [id: :id], :content)
#Template<[:id, :content]>
iex> Template.unbound(t)
[:id, :content]
iex> t = Template.bind(t, :id, "some_id")
#Template<[:content]>
iex> Template.unbound(t)
[:content]
Source