View Source Phoenix.LiveView.TagEngine behaviour (Phoenix LiveView v0.20.0)

An EEx engine that understands tags.

This cannot be directly used by Phoenix applications. Instead, it is the building block by engines such as Phoenix.LiveView.HTMLEngine.

It is typically invoked like this:

EEx.compile_string(source,
  engine: Phoenix.LiveView.TagEngine,
  line: 1,
  file: path,
  caller: __CALLER__,
  source: source,
  tag_handler: FooBarEngine
)

Where :tag_handler implements the behaviour defined by this module.

Summary

Callbacks

Classify the tag type from the given binary.

Returns if the given binary is either void or not.

Functions

Renders a component defined by the given function.

Define a inner block, generally used by slots.

Callbacks

@callback classify_type(name :: binary()) :: {type :: atom(), name :: binary()}

Classify the tag type from the given binary.

This must return a tuple containing the type of the tag and the name of tag. For instance, for LiveView which uses HTML as default tag handler this would return {:tag, 'div'} in case the given binary is identified as HTML tag.

You can also return {:error, "reason"} so that the compiler will display this error.

@callback void?(name :: binary()) :: boolean()

Returns if the given binary is either void or not.

That's mainly useful for HTML tags and used internally by the compiler. You can just implement as def void?(_), do: false if you want to ignore this.

Functions

Link to this function

component(func, assigns, caller)

View Source

Renders a component defined by the given function.

This function is rarely invoked directly by users. Instead, it is used by ~H to render Phoenix.Components. For example, the following:

<MyApp.Weather.city name="Kraków" />

Is the same as:

<%= component(
      &MyApp.Weather.city/1,
      [name: "Kraków"],
      {__ENV__.module, __ENV__.function, __ENV__.file, __ENV__.line}
    ) %>
Link to this macro

inner_block(name, list)

View Source (macro)

Define a inner block, generally used by slots.

This macro is mostly used by HTML engines that provide a slot implementation and rarely called directly. The name must be the assign name the slot/block will be stored under.

If you're using HEEx templates, you should use its higher level <:slot> notation instead. See Phoenix.Component for more information.