Taggart v0.1.1 Taggart View Source

Generates tags upon use.

The use macro automatically handles any ambiguities between html elements and the funcions from Kernel. Kernel.div/2 for example is unimported to allow the use of the div element. If you still need to use Kernel.div/2, just call it as Kernel.div(20, 2)

Importing

Generates all known HTML tags as macros upon import:

use Taggart

div do
  span("some content")
end

Generates just the given tags:

use Taggart, tags: [:foo, :bar]

foo do
  bar("some content")
end

If you would like to carefully control the imports:

import Kernel, except: [div: 2]
use Taggart, deconflict_imports: false

Link to this section Summary

Functions

Produces an html comment

Produces a doctype tag

Allows grouping tags in a block

Link to this section Functions

Link to this macro html_comment(comment) View Source (macro)

Produces an html comment.

Examples

iex> html_comment("this is a comment") |> Phoenix.HTML.safe_to_string()
"<!-- this is a comment -->"
Link to this macro html_doctype(type \\ :html5) View Source (macro)

Produces a doctype tag.

Defaults to html5. Available doctypes are:

  • :html5
  • :html401_strict
  • :html401_transitional
  • :html401_frameset
  • :xhtml10_strict
  • :xhtml10_transitional
  • :xhtml10_frameset
  • :xhtml11

Examples

iex> html_doctype() |> Phoenix.HTML.safe_to_string()
"<!DOCTYPE html>"

iex> html_doctype(:html5) |> Phoenix.HTML.safe_to_string()
"<!DOCTYPE html>"

iex> html_doctype(:xhtml11) |> Phoenix.HTML.safe_to_string()
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">"

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>"