Mustachio templates, the language of Postmark's templates, rendered as Mustachio renders them.
iex> Braces.Mustachio.render_to_string("Hi {{ name }}! {{#company}}{{ name }}{{^company}}No company{{/company}}", %{"name" => "Ada", "company" => %{"name" => "Acme"}})
{:ok, "Hi Ada! Acme"}Rendering
render/3 renders a template with its data. compile/2 compiles one to render many times,
and the ~MUSTACHIO sigil compiles it with your code, so a template that can't be rendered is a
CompileError at its line:
import Braces.Mustachio, only: :sigils
Braces.render(~MUSTACHIO"Hi {{ name }}", data)Braces.Mustachio.Phoenix.Engine renders .mustachio files in Phoenix. Braces.convert/2 converts Mustachio
to the other languages.
What renders
{{ name }},{{{ name }}}, and paths,{{ company.name }}.{{#company}}…{{/company}}renders its block once, withcompanyas the context, when it's there, even for a list;{{^company}}in the block is its else.{{#each list}}repeats its block for each item.../goes up one segment of the path: in{{#each company.employees}},{{../../name}}is the company'sname.- A block tag alone on its line keeps the line.
{{{ @content }}}, in a layout, is the template's HTML: render the layout withdata: %{"content" => Braces.Handlebars.safe(html)}.{{{ pm:unsubscribe }}}is the valuepm:unsubscribe, so give it in the data.
Braces differs from Mustachio in three ways: it writes false as false where Mustachio
writes False, it escapes ` and =, and an empty map is true.
A template Mustachio would reject, with an invalid path, or a block that isn't closed, is a
Braces.ConversionError.
Summary
Rendering
Compiles Mustachio into a Braces.Template for render/3, or gives the error that
convert/2 gives.
Like compile/2, raising the error.
Renders Mustachio, or a Braces.Template of it, with data, to iodata.
Like render/3, giving a string.
The ~MUSTACHIO sigil: Mustachio compiled with your code into a Braces.Template, so a
template that doesn't convert is a CompileError at its line. Import it with
import Braces.Mustachio, only: :sigils.
Functions
Converts a Mustachio template to Handlebars source, or gives a Braces.ConversionError
with the tag's line and column.
Like convert/2, raising Braces.ConversionError when the template can't be converted.
Reads a Mustachio template into a Braces.IR, for Braces.convert/2.
Rendering
@spec compile(String.t(), keyword()) :: {:ok, Braces.Template.t()} | {:error, Exception.t()}
Compiles Mustachio into a Braces.Template for render/3, or gives the error that
convert/2 gives.
escape: falsewrites values without HTML escaping.templates:the templates it extends or includes, by name: a map of names to Mustachio source orBraces.Templates, or a function of a name giving{:ok, template}or:error. They're compiled into it.
@spec compile!(String.t(), keyword()) :: Braces.Template.t()
Like compile/2, raising the error.
@spec render(String.t() | Braces.Template.t(), term(), keyword()) :: {:ok, iodata()} | {:error, Exception.t()}
Renders Mustachio, or a Braces.Template of it, with data, to iodata.
Takes helpers:, functions for filters Braces doesn't have, as modules that use
Braces.Handlebars.Helpers, and, with source, escape: and templates:, as
compile/2 does.
@spec render_to_string(String.t() | Braces.Template.t(), term(), keyword()) :: {:ok, String.t()} | {:error, Exception.t()}
Like render/3, giving a string.
The ~MUSTACHIO sigil: Mustachio compiled with your code into a Braces.Template, so a
template that doesn't convert is a CompileError at its line. Import it with
import Braces.Mustachio, only: :sigils.
Functions
Converts a Mustachio template to Handlebars source, or gives a Braces.ConversionError
with the tag's line and column.
Like convert/2, raising Braces.ConversionError when the template can't be converted.
Reads a Mustachio template into a Braces.IR, for Braces.convert/2.