View Source PrEEx.Engine (PrEEx v0.1.0)
A thin wrapper around EEx.SmartEngine
that makes it nicer to write preformatted text templates.
Usage
EEx.eval_string(template, bindings, engine: PrEEx.Engine)
Options
None at the moment.
Newline trimming around blocks
When interpolating block expressions such as if
or for
, newlines are trimmed to avoid undesired whitespace in
the rendered template.
Up to two extraneous newlines are removed: the first immediate \n
within the block, and the \n
immediately following the
block. For example, the template
hello
<%= if condition() do %>
to the
<% end %>
world
will result in
hello
to the
world
when the condition is true, and
hello
world
when the condition is false, effectively making the lines of EEx invisible.
Loops are also more conveinent to write:
How many licks to the center of a Tootsie Pop?
<%= for i <- 1..3 do %>
<%= i %>...
<% end %>
3!
will result in
How many licks to the center of a Tootsie Pop?
1...
2...
3...
3!
No trimming occurs if the block expression is in the middle of a line. For example,
hello <%= if condition() do %>to the <% end %>world
will result in "hello to the world"
or "hello world"
, depending on the condition.