This repository has been archived on 2023-08-07. You can view files and clone it, but cannot push or open issues or pull requests.
temple/lib/temple/parser/right_arrow.ex
Mitchell Hanberg c965048f40
Better whitespace handling and control (#145)
* 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.
2021-08-29 17:45:07 -04:00

31 lines
725 B
Elixir

defmodule Temple.Parser.RightArrow do
@moduledoc false
alias Temple.Parser
@behaviour Parser
defstruct elixir_ast: nil, children: []
@impl Parser
def applicable?({:->, _, _}), do: true
def applicable?(_), do: false
@impl Parser
def run({_, _, [[pattern], args]}) do
children = Parser.parse(args)
Temple.Ast.new(__MODULE__, elixir_ast: pattern, children: children)
end
defimpl Temple.Generator do
def to_eex(%{elixir_ast: elixir_ast, children: children}, indent \\ 0) do
[
"#{Parser.Utils.indent(indent)}<% ",
Macro.to_string(elixir_ast),
" -> %>\n",
for(child <- children, do: Temple.Generator.to_eex(child, indent + 1))
]
end
end
end