View Source Hologram.Template.Renderer (hologram v0.2.0)

Summary

Functions

Renders the given DOM.

Renders the given page.

Functions

render_dom(dom, env)

@spec render_dom(Hologram.Template.DOM.t(), Hologram.Template.Renderer.Env.t()) ::
  {String.t(),
   %{
     required(String.t()) => %{module: module(), struct: Hologram.Component.t()}
   }}

Renders the given DOM.

Examples

iex> dom = {:component, MyModule, [{"cid", [text: "my_component"]}], []}
iex> render_dom(dom, %Env{})
{
  "<div>state_a = 1, state_b = 2</div>",
  %{"my_component" => %{module: MyModule, struct: %Component{state: %{a: 1, b: 2}}}}
}

render_page(page_module, params, opts)

@spec render_page(
  module(),
  %{required(atom() | String.t()) => any()},
  Hologram.Commons.Types.opts()
) ::
  {String.t(),
   %{
     required(String.t()) => %{module: module(), struct: Hologram.Component.t()}
   }}

Renders the given page.

Examples

iex> render_page(MyPage, %{param: "value"}, initial_page?: true)
{
  "<div>full page content including layout</div>",
  %{"page" => %{module: MyPage, struct: %Component{state: %{a: 1, b: 2}}}}
}