c965048f40
* Fine tune whitespace The EEx outut now emits more human-readable and predictable formatting. This includes proper indenting, at least for each "root" template. * Internal whitespace control You can now use a bang version of any nonvoid tag to emit the markup witout the internal whitespace. This means that there will not be a newline emitted after the opening tag and before the closing tag.
43 lines
888 B
Elixir
43 lines
888 B
Elixir
defmodule Temple.Parser.VoidElementsAliases do
|
|
@moduledoc false
|
|
@behaviour Temple.Parser
|
|
|
|
alias Temple.Parser.Utils
|
|
|
|
defstruct name: nil, attrs: []
|
|
|
|
@impl Temple.Parser
|
|
def applicable?({name, _, _}) do
|
|
name in Temple.Parser.void_elements_aliases()
|
|
end
|
|
|
|
def applicable?(_), do: false
|
|
|
|
@impl Temple.Parser
|
|
def run({name, _, args}) do
|
|
args =
|
|
case Temple.Parser.Utils.split_args(args) do
|
|
{_, [args]} when is_list(args) ->
|
|
args
|
|
|
|
{_, args} ->
|
|
args
|
|
end
|
|
|
|
name = Temple.Parser.void_elements_lookup()[name]
|
|
|
|
Temple.Ast.new(__MODULE__, name: name, attrs: args)
|
|
end
|
|
|
|
defimpl Temple.Generator do
|
|
def to_eex(%{name: name, attrs: attrs}, indent \\ 0) do
|
|
[
|
|
"#{Utils.indent(indent)}<",
|
|
to_string(name),
|
|
Temple.Parser.Utils.compile_attrs(attrs),
|
|
">"
|
|
]
|
|
end
|
|
end
|
|
end
|