View Source EEx.Engine behaviour (EEx v1.18.0-dev)
Basic EEx engine that ships with Elixir.
An engine needs to implement all callbacks below.
This module also ships with a default engine implementation
you can delegate to. See EEx.SmartEngine
as an example.
Summary
Callbacks
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.
Functions
Handles assigns in quoted expressions.
Default implementation for handle_begin/1
.
Default implementation for handle_body/1
.
Default implementation for handle_end/1
.
Default implementation for handle_expr/3
.
Default implementation for handle_text/3
.
Default implementation for init/1
.
Types
@type state() :: term()
Callbacks
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.
Called at the end of every template.
It must return Elixir's quoted expressions for the template.
Invokes at the end of a nesting.
It must return Elixir's quoted expressions for the nesting.
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 handle_text( state(), [line: pos_integer(), column: pos_integer()], text :: String.t() ) :: state()
Called for the text/static parts of a template.
It must return the updated state.
Called at the beginning of every template.
It must return the initial state.
Functions
Handles assigns in quoted expressions.
A warning will be printed on missing assigns. Future versions will raise.
This can be added to any custom engine by invoking
handle_assign/1
with Macro.prewalk/2
:
def handle_expr(state, token, expr) do
expr = Macro.prewalk(expr, &EEx.Engine.handle_assign/1)
super(state, token, expr)
end
Default implementation for handle_begin/1
.
Default implementation for handle_body/1
.
Default implementation for handle_end/1
.
Default implementation for handle_expr/3
.
Default implementation for handle_text/3
.
Default implementation for init/1
.