expug v0.7.3 Expug.Builder

Builds lines from an AST.

iex> source = "div\n  | Hello"
iex> with tokens <- Expug.Tokenizer.tokenize(source),
...>      ast <- Expug.Compiler.compile(tokens),
...>      lines <- Expug.Builder.build(ast),
...>   do: lines
%{
  :lines => 2,
  1 => ["<div>"],
  2 => ["Hello", "</div>"]
}

This gives you a map of lines that the Stringifier will work on.

Also see

Summary

Functions

Stringifies an attributes map

Builds a list of nodes

Builds an element opening tag

Builds text

Adds a line based on a token’s location

Puts a collapser on the lane after the given token. Used for if…end statements

Adds a line to the end of a document. Used for closing tags

Adds a line to the end of a document, but without a newline before it. Used for closing <% end %>

Updates the :lines count if the latest line is beyond the current max

Functions

add_closing(doc, node, suffix \\ "")
attributes(doc, attributes)

Stringifies an attributes map.

iex> doc = %{options: %{}}
iex> Expug.Builder.attributes(doc, %{ "src" => [{:text, "image.jpg"}] })
" src=\"image.jpg\""

#iex> doc = %{options: %{}}
#iex> Expug.Builder.attributes(doc, %{ "class" => [{:text, "a"}, {:text, "b"}] })
#" class=\"a b\""

iex> doc = %{options: %{attr_helper: "attr", raw_helper: "raw"}}
iex> Expug.Builder.attributes(doc, %{ "src" => [{:eval, "@image"}] })
"<%= raw(attr(\"src\", @image)) %>"

iex> doc = %{options: %{attr_helper: "attr", raw_helper: "raw"}}
iex> Expug.Builder.attributes(doc, %{ "class" => [{:eval, "@a"}, {:eval, "@b"}] })
"<%= raw(attr(\"class\", Enum.join([@a, @b], \" \"))) %>"
build(ast, opts \\ [])
children(doc, list)

Builds a list of nodes.

element(doc, node)

Builds an element opening tag.

make(doc, node)

Builds text.

put(doc, map, str)

Adds a line based on a token’s location.

put_collapse(doc, map)

Puts a collapser on the lane after the given token. Used for if…end statements.

put_last(doc, str)

Adds a line to the end of a document. Used for closing tags.

put_last_no_space(doc, str)

Adds a line to the end of a document, but without a newline before it. Used for closing <% end %>.

self_closable?(node)
self_closing_element(doc, node)
str_join(left, str, sep \\ " ")
update_line_count(doc, line, max)

Updates the :lines count if the latest line is beyond the current max.

valueify(doc, key, values)