View Source Tamnoon.Compiler (Tamnoon v1.0.0-a.2)

This module provides functions for compiling (/parsing) Tamnoon HEEx components.

Summary

Functions

Compiles the 'root.ex' component into the final file that is sent to the client.

Escapes the content so it is not rendered as HTML. Available as <%= h.(content) %> inside components.

Takes as an argument a string containing compiled heex for a component, and returns the component as plain HTML for it to be rendered on the DOM.

Returns the compiled HTML code of the component. Takes as arguments

Utility function passed to EEx blocks in components. Calls render_component/3 with the elements in the list as the arguments. When passing it only the first argument, it can be passed directly without putting it in a list. See render_component/3 for more info.

Functions

Link to this function

build_from_root(root \\ Tamnoon.Components.Root)

View Source
@spec build_from_root(root :: String.t() | module()) :: :ok | {:error, atom()}

Compiles the 'root.ex' component into the final file that is sent to the client.

@spec escape_html(String.t()) :: String.t()

Escapes the content so it is not rendered as HTML. Available as <%= h.(content) %> inside components.

Link to this function

parse_tmnn_heex(compiled_heex)

View Source
@spec parse_tmnn_heex(String.t()) :: String.t()

Takes as an argument a string containing compiled heex for a component, and returns the component as plain HTML for it to be rendered on the DOM.

Link to this function

render_component(component, assigns \\ %{}, parse_tmnn_heex \\ false)

View Source
@spec render_component(module() | String.t(), map(), boolean()) :: String.t()

Returns the compiled HTML code of the component. Takes as arguments:

  • either a component module or a file name of a heex component file inside lib/components,
  • the assigns for the EEx blocks in the component,
  • and a boolean for whether to parse the Tamnoon heex. When the function is used inside a component that gets built into the root in the build_from_root/2 function, the last argument should be false to avoid invoking parse_tmnn_heex/1 multiple times. Inside EEx blocks in heex components, this function can be invoked as <%= r.([args..]) %>. See render_component_dyn/1.
Link to this function

render_component_dyn(component)

View Source
@spec render_component_dyn(args :: list() | module() | String.t()) :: String.t()

Utility function passed to EEx blocks in components. Calls render_component/3 with the elements in the list as the arguments. When passing it only the first argument, it can be passed directly without putting it in a list. See render_component/3 for more info.