eex_html v1.0.0 EExHTML.Engine

An engine for templating HTML content.

Interpolated values are HTML escaped, unless the term implements the EExHTML.Safe protocol.

Values returned are io_lists for performance reasons.

Examples

iex> EEx.eval_string("foo <%= bar %>", [bar: "baz"], engine: EExHTML.Engine)
...> |> String.Chars.to_string
"foo baz"

iex> EEx.eval_string("foo <%= bar %>", [bar: "<script>"], engine: EExHTML.Engine)
...> |> String.Chars.to_string
"foo &lt;script&gt;"

iex> EEx.eval_string("foo <%= bar %>", [bar: EExHTML.raw("<script>")], engine: EExHTML.Engine)
...> |> String.Chars.to_string
"foo <script>"

iex> EEx.eval_string("foo <%= @bar %>", [assigns: %{bar: "<script>"}], engine: EExHTML.Engine)
...> |> String.Chars.to_string
"foo &lt;script&gt;"

iex> EEx.eval_string("<%= for _ <- 1..1 do %><p><%= bar %></p><% end %>", [bar: "<script>"], engine: EExHTML.Engine)
...> |> String.Chars.to_string
"<p>&lt;script&gt;</p>"

Link to this section Summary

Functions

Invoked at the beginning of every nesting

Called at the end of every template

Invokes at the end of a nesting

Called for the dynamic/code parts of a template

Called for the text/static parts of a template

Called at the beginning of every template

Link to this section Functions

Link to this function handle_begin(state)

Invoked at the beginning of every nesting.

It must return a new state that is used only inside the nesting. Once the nesting terminates, the current state is resumed.

Callback implementation for EEx.Engine.handle_begin/1.

Link to this function handle_body(state)

Called at the end of every template.

It must return Elixir’s quoted expressions for the template.

Callback implementation for EEx.Engine.handle_body/1.

Link to this function handle_end(state)

Invokes at the end of a nesting.

It must return Elixir’s quoted expressions for the nesting.

Callback implementation for EEx.Engine.handle_end/1.

Link to this function handle_expr(state, marker, expr)

Called for the dynamic/code parts of a template.

The marker is what follows exactly after <%. For example, <% foo %> has an empty marker, but <%= foo %> has "=" as marker. The allowed markers so far are:

  • ""
  • "="
  • "/"
  • "|"

Markers "/" and "|" are only for use in custom EEx engines and are not implemented by default. Using them without an appropriate implementation raises EEx.SyntaxError.

It must return the updated state.

Callback implementation for EEx.Engine.handle_expr/3.

Link to this function handle_text(state, text)

Called for the text/static parts of a template.

It must return the updated state.

Callback implementation for EEx.Engine.handle_text/2.

Called at the beginning of every template.

It must return the initial state.

Callback implementation for EEx.Engine.init/1.