Packages
raxx
0.15.9
1.1.0
1.0.1
1.0.0
1.0.0-rc.3
1.0.0-rc.2
retired
1.0.0-rc.1
retired
1.0.0-rc.0
retired
0.18.1
0.18.0
0.17.6
0.17.5
0.17.4
0.17.3
0.17.2
0.17.1
0.17.0
0.16.1
0.16.0
retired
0.15.11
0.15.10
0.15.9
0.15.8
0.15.7
0.15.6
0.15.5
0.15.4
0.15.3
0.15.2
0.15.1
0.15.0
0.14.14
0.14.13
0.14.12
0.14.11
0.14.10
0.14.9
0.14.8
0.14.7
0.14.6
0.14.5
0.14.4
0.14.3
0.14.2
0.14.1
0.14.0
0.13.0
0.12.3
0.12.2
0.12.1
0.12.0
0.11.1
0.11.0
0.10.5
0.10.4
0.10.3
0.10.2
0.10.1
0.10.0
0.9.0
0.8.2
0.8.1
0.8.0
0.7.1
0.7.0
0.6.0
0.5.2
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.0
0.2.0
0.1.0
0.0.1
Interface for HTTP webservers, frameworks and clients.
Current section
Files
Jump to
Current section
Files
lib/eex/html_engine.ex
defmodule EEx.HTMLEngine do
@moduledoc """
An engine for templating HTML content.
Interpolated values are HTML escaped,
unless the term implements the `EEx.HTML.Safe` protocol.
Values returned are `io_lists` for performance reasons.
## Examples
iex> EEx.eval_string("foo <%= bar %>", [bar: "baz"], engine: EEx.HTMLEngine)
...> |> IO.iodata_to_binary()
"foo baz"
iex> EEx.eval_string("foo <%= bar %>", [bar: "<script>"], engine: EEx.HTMLEngine)
...> |> IO.iodata_to_binary()
"foo <script>"
iex> EEx.eval_string("foo <%= bar %>", [bar: EEx.HTML.raw("<script>")], engine: EEx.HTMLEngine)
...> |> IO.iodata_to_binary()
"foo <script>"
iex> EEx.eval_string("foo <%= @bar %>", [assigns: %{bar: "<script>"}], engine: EEx.HTMLEngine)
...> |> IO.iodata_to_binary()
"foo <script>"
"""
use EEx.Engine
def init(_options) do
quote do: []
end
def handle_begin(_previous) do
quote do: []
end
def handle_end(quoted) do
quoted
end
def handle_text(buffer, text) do
quote do
[unquote(buffer) | unquote(text)]
end
end
def handle_body(quoted) do
quoted
end
def handle_expr(buffer, "=", expr) do
expr = Macro.prewalk(expr, &EEx.Engine.handle_assign/1)
quote do
[unquote(buffer), EEx.HTML.escape(unquote(expr)).data]
end
end
def handle_expr(buffer, "", expr) do
expr = Macro.prewalk(expr, &EEx.Engine.handle_assign/1)
quote do
tmp2 = unquote(buffer)
unquote(expr)
tmp2
end
end
def handle_expr(buffer, type, expr) do
super(buffer, type, expr)
end
end