Exampple.Template (exampple v0.10.6)
Templates are XML chunks which could be in use for a Exampple.Client
.
The template is usually a string which could contain special execution
code using an escape sintaxis %{var}
.
The templates are stored in ETS tables for each node. It was not thought for the implementation as a cluster so it will be needed to start it and populate it individually for each node.
Link to this section Summary
Functions
Retrieve all of the templates as a list of tuples `{name(), }
Retrieve a template given the name of the template.
Template requires to be initiated to start working. It's a good idea to start it from an Application process because if the process who spawned dies, the ETS table also dies.
Adds several templates at once.
Adds a template to be in use by the process when we call send_template/2
or send_template/3
. The name
is the name or PID for the process, the
name
is the name we will use storing the template and xml
is the
text or function which will generate the stanza.
Use a template registered. This let us to trigger faster stanzas when we are working from the shell, developing tests or even when we have our code narrowed and focused on the business logic.
See render/1
. It performs the same action but triggering an error
if the template name wasn't found.
Link to this section Types
bindings()
Specs
content()
Specs
key()
Specs
key() :: atom()
name()
Specs
name() :: String.t()
rendered()
Specs
rendered() :: String.t() | Exampple.Xml.Xmlel.t()
Link to this section Functions
all()
Specs
Retrieve all of the templates as a list of tuples `{name(), }
get(name)
Specs
Retrieve a template given the name of the template.
init()
Specs
init() :: :ok
Template requires to be initiated to start working. It's a good idea to start it from an Application process because if the process who spawned dies, the ETS table also dies.
put(contents)
Specs
Adds several templates at once.
put(name, xml)
Specs
Adds a template to be in use by the process when we call send_template/2
or send_template/3
. The name
is the name or PID for the process, the
name
is the name we will use storing the template and xml
is the
text or function which will generate the stanza.
render(name, bindings \\ [])
Specs
Use a template registered. This let us to trigger faster stanzas when we are working from the shell, developing tests or even when we have our code narrowed and focused on the business logic.
The name
parameter is the name to lookup the template.
The args
are the arguments passed to the function template.
Examples:
iex> :ok = Exampple.Template.init()
iex> Exampple.Template.put("gret", "Hello %{name}!")
iex> Exampple.Template.render("gret", name: "World")
{:ok, "Hello World!"}
iex> :ok = Exampple.Template.init()
iex> Exampple.Template.put("gret", &"Hello #{&1[:name]}!")
iex> Exampple.Template.render("gret", name: "World")
{:ok, "Hello World!"}
render!(name, bindings \\ [])
Specs
See render/1
. It performs the same action but triggering an error
if the template name wasn't found.
Examples:
iex> :ok = Exampple.Template.init()
iex> Exampple.Template.put("gret", "Hello %{name}!")
iex> Exampple.Template.render!("gret", name: "World")
"Hello World!"
iex> :ok = Exampple.Template.init()
iex> Exampple.Template.put("gret", &"Hello #{&1[:name]}!")
iex> Exampple.Template.render!("gret", name: "World")
"Hello World!"
iex> :ok = Exampple.Template.init()
iex> Exampple.Template.render!("missing", name: "World")
** (ArgumentError) not_found