defmodule HyperEx do
@moduledoc """
The root HyperEx module contains all publically exposed functions of this
package.
"""
alias HyperEx.Abbreviation
alias HyperEx.Renderer
alias HyperEx.Util
@doc """
Render an abbreviation.
## Examples
iex> HyperEx.h("div")
~s{
}
iex> HyperEx.open("div#foo")
~s{
}
"""
def open(abbreviation) do
{tag, abbreviation_attrs} = Abbreviation.expand(abbreviation)
Renderer.open(tag, abbreviation_attrs)
end
@doc """
Render an opening tag from an abbreviation with attributes.
## Examples
iex> HyperEx.open("div#foo", [class: "bar"])
~s{
}
"""
def open(abbreviation, attrs) do
{tag, abbreviation_attrs} = Abbreviation.expand(abbreviation)
Renderer.open(tag, Util.merge_attrs(abbreviation_attrs, attrs))
end
@doc """
Render an closing tag from an abbreviation.
## Examples
iex> HyperEx.close("div")
~s{
}
iex> HyperEx.close("div#foo")
~s{
}
"""
def close(abbreviation) do
{tag, _abbreviation_attrs} = Abbreviation.expand(abbreviation)
Renderer.close(tag)
end
@doc """
Wrap children (a binary or list) in an abbreviation. Behaves like `h/2` but
expects children to be the first argument. Useful for piping.
## Examples
iex> HyperEx.h("div#foo") |> HyperEx.wrap("div#bar")
~s{
}
"""
def wrap(contents, abbreviation), do: h(abbreviation, contents)
@doc """
Wrap children (a binary or list) in an abbreviation with attributes. Behaves
like `h/3` but expects children to be the first argument. Useful for piping.
## Examples
iex> HyperEx.h("div#foo") |> HyperEx.wrap("div#bar", [class: "baz"])
~s{
}
"""
def wrap(contents, abbreviation, attrs), do: h(abbreviation, attrs, contents)
end