Vaux (Vaux v0.4.0)

View Source

Provides functions to render Vaux components to html.

iex> defmodule HelloWorld do
...>   import Vaux.Component
...> 
...>   attr :title, :string
...> 
...>   ~H"<h1>{@title}</h1>"vaux
...> end
iex> Vaux.render(HelloWorld, %{"title" => "Hello World"})
{:ok, "<h1>Hello World</h1>"}

Summary

Functions

Same as render/3, but raises an Vaux.RuntimeError exception when an error is encountered

Types

attributes()

@type attributes() :: %{required(String.t()) => any()}

slot_content()

@type slot_content() ::
  iodata() | keyword(iodata()) | %{required(atom()) => iodata()} | nil

Functions

render(component, attrs \\ %{}, slots \\ nil)

@spec render(component :: module(), attrs :: attributes(), slots :: slot_content()) ::
  {:ok, iodata()} | {:error, Vaux.RuntimeError.t()}

Render a component to html

Accepts a map where keys are strings as attributes and a map where keys are atoms as slots.

Returns {:ok, iodata()} or {:error, Vaux.RuntimeError.t()} when an error is encountered during rendering.

By default a string is returned, but when

config :vaux, render_to_binary: false 

is set, an iolist is returned. Depending on the template complexity, this can give a small performance boost. Note that this config setting is evaluated at compile time.

render!(component, attrs \\ %{}, slots \\ nil)

@spec render!(component :: module(), attrs :: attributes(), slots :: slot_content()) ::
  iodata()

Same as render/3, but raises an Vaux.RuntimeError exception when an error is encountered