View Source PrEEx.Engine (PrEEx v0.1.1)

A thin wrapper around EEx.SmartEngine that makes it nicer to write preformatted text templates.

Usage

EEx.eval_string(template, bindings, engine: PrEEx.Engine)

Features

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

is transformed internally to standard EEx

hello
<%= if condition() do %>to the
<% end %>world

which results 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!

results 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

results in "hello to the world" or "hello world", depending on the condition.

The special forms case, cond, and with are also trimmed.

Options

None at the moment.