expug v0.9.2 Expug.Builder View Source

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

Link to this section 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

Link to this section Functions

Link to this function add_closing(doc, node, suffix \\ "") View Source
Link to this function attributes(doc, attributes) View Source

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], \" \"))) %>"

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.

Link to this function put_last_no_space(doc, str) View Source

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

Link to this function self_closing_element(doc, node) View Source
Link to this function str_join(left, str, sep \\ " ") View Source
Link to this function update_line_count(doc, line, max) View Source

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

Link to this function valueify(doc, key, values) View Source