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