Taggart v0.1.5 Taggart.Tags View Source

Define HTML tags.

Contains macros for creating a tag-based DSL.

Link to this section Summary

Link to this section Functions

Link to this function build_attrs(tag, list, acc) View Source
Link to this function content_tag(tag, attrs, content) View Source

Define a new tag.

deftag :span
deftag :div

div do
  span("Foo")
end
Link to this macro deftag(tag, list) View Source (macro)

Define a new void tag.

deftag :hr, void: true
deftag :img, void: true

hr()
img(class: "red")
Link to this function normalized_call(tag, attrs, content) View Source

Allows grouping tags in a block.

Groups tags such that they all become part of the result. Normally, with an Elixir block, only the last expression is part of the value. This is useful, for example, as the do block of Phoenix.HTML.Form.form_for/4.

form_for(conn, "/users", [as: :user], fn f ->
  taggart do
    label do
      "Name:"
      text_input(f, :name)
    end
    label do
      "Age:"
      select(f, :age, 18..100)
    end
  end
end

Examples

iex> taggart() |> Phoenix.HTML.safe_to_string()
""

iex> (taggart do div() ; span() end) |> Phoenix.HTML.safe_to_string()
"<div></div><span></span>"