expug v0.1.1 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, arg2)
attributes(attributes)

Stringifies an attributes map.

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

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

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

iex> Expug.Builder.attributes(%{ "class" => [{:eval, "@a"}, {:eval, "@b"}] })
"<%= raw(Expug.Runtime.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(key, values)