# EEx v1.10.3 EEx.Engine behaviour View Source

Basic EEx engine that ships with Elixir.

An engine needs to implement all callbacks below.

An engine may also `use EEx.Engine` to get the default behaviour but this is not advised. In such cases, if any of the callbacks are overridden, they must call `super()` to delegate to the underlying `EEx.Engine`.

# Link to this section Summary

## Types

state()

## Functions

handle_assign(arg)

Handles assigns in quoted expressions.

## Callbacks

handle_begin(state)

Invoked at the beginning of every nesting.

handle_body(state)

Called at the end of every template.

handle_end(state)

Invokes at the end of a nesting.

handle_expr(state, marker, expr)

Called for the dynamic/code parts of a template.

handle_text(state, text)

Called for the text/static parts of a template.

init(opts)

Called at the beginning of every template.

# Link to this section Types

Link to this type

# state()

View Source

## Specs

    state() :: term()

# Link to this section Functions

Link to this function

# handle_assign(arg)

View Source

## Specs

    handle_assign(Macro.t()) :: Macro.t()

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

# Link to this section Callbacks

Link to this callback

# handle_begin(state)

View Source

## Specs

    handle_begin(state()) :: 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.

Link to this callback

# handle_body(state)

View Source

## Specs

    handle_body(state()) :: Macro.t()

Called at the end of every template.

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

Link to this callback

# handle_end(state)

View Source

## Specs

    handle_end(state()) :: Macro.t()

Invokes at the end of a nesting.

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

Link to this callback

# handle_expr(state, marker, expr)

View Source

## Specs

    handle_expr(state(), marker :: String.t(), expr :: Macro.t()) :: state()

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.

Link to this callback

# handle_text(state, text)

View Source

## Specs

    handle_text(state(), text :: String.t()) :: state()

Called for the text/static parts of a template.

It must return the updated state.

Link to this callback

# init(opts)

View Source

## Specs

    init(opts :: keyword()) :: state()

Called at the beginning of every template.

It must return the initial state.