Hyperex v0.1.0 Hyperex View Source

A pure-Elixir HTML renderer.

Link to this section Summary

Functions

A helper that returns an HTML5 doctype

Transforms Hyperex DSL code to renderable elements

Creates HTML iodata from elements

Link to this section Types

Link to this type regular_element() View Source
regular_element() ::
  {tag(),
   %{optional(:children) => :void | renderable(), optional(any()) => any()}}
Link to this type renderable() View Source
renderable() :: [element()] | element() | binary() | number() | nil
Link to this type unescaped_element() View Source
unescaped_element() ::
  {:dangerously_unescaped, binary(), renderable(), binary()}

Link to this section Functions

A helper that returns an HTML5 doctype.

Example

iex> import Hyperex
iex> require Hyperex
iex> to_string render hyperex(
...>   -html5_doctype do
...>     html do
...>       body do
...>         "hello"
...>       end
...>     end
...>   end
...> )
"<!DOCTYPE html><html ><body >hello</body></html>"

Transforms Hyperex DSL code to renderable elements.

Use render/1 to convert the returned renderable elements into iodata or strings.

Example

iex> import Hyperex
iex> require Hyperex
iex> hyperex(html do h1 do "Hello" end end)
{:html, %{children: {:h1, %{children: "Hello"}}}}
Link to this function render(renderable) View Source
render(renderable()) :: iodata()

Creates HTML iodata from elements.

Example

iex> import Hyperex
iex> require Hyperex
iex> renderable = hyperex(html do h1 do "Hello" end end)
{:html, %{children: {:h1, %{children: "Hello"}}}}
iex> render(renderable)
[
  60,
  "html",
  32,
  [],
  62,
  [60, "h1", 32, [], 62, "Hello", "</", "h1", 62],
  "</",
  "html",
  62
]
iex> to_string(render(renderable))
"<html ><h1 >Hello</h1></html>"