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
Expug.Compiler
builds the AST used by this builder.Expug.Stringifier
takes this builder’s output.
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
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], \" \"))) %>"
Puts a collapser on the lane after the given token. Used for if…end statements.
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.