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/slot.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

43 lines
864 B
Elixir

defmodule Temple.Parser.Slot do
@moduledoc false
@behaviour Temple.Parser
alias Temple.Parser.Utils
defstruct name: nil, args: []
@impl true
def applicable?({:slot, _, _}) do
true
end
def applicable?(_), do: false
@impl true
def run({:slot, _, [slot_name | rest]}) do
args =
case rest do
[args] ->
args
_ ->
[]
end
Temple.Ast.new(__MODULE__, name: slot_name, args: args)
end
defimpl Temple.Generator do
def to_eex(%{name: name, args: args}, indent \\ 0) do
render_block_function = Temple.Config.mode().render_block_function
[
"#{Utils.indent(indent)}<%= #{render_block_function}(@inner_block, {:",
to_string(name),
", ",
Macro.to_string(quote(do: Enum.into(unquote(args), %{}))),
"}) %>\n"
]
end
end
end