Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions lib/sneeze/internals.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
defmodule Sneeze.Internal do
require Sneeze.Macros

Sneeze.Macros.define_tags_to_strings([
:a,
:div,
:span,
:li,
:br,
:p,
:link,
:meta,
:td,
:tr,
:ul,
:h3,
:h2,
:img,
:code,
:svg,
:button
])

def void_tags() do
[
:area,
Expand Down Expand Up @@ -29,25 +51,25 @@ defmodule Sneeze.Internal do
end

def render_opening_tag(tag_name) do
["<", to_string(tag_name), ">"]
["<", tag_to_string(tag_name), ">"]
end

def render_opening_tag(tag_name, attribs) do
attrib_iolist = attributes_to_iolist(attribs)
["<", to_string(tag_name), attrib_iolist, ">"]
["<", tag_to_string(tag_name), attrib_iolist, ">"]
end

def render_closing_tag(tag_name) do
["</", to_string(tag_name), ">"]
["</", tag_to_string(tag_name), ">"]
end

def render_void_tag(tag_name) do
["<", to_string(tag_name), " />"]
["<", tag_to_string(tag_name), " />"]
end

def render_void_tag(tag_name, attribs) do
attrib_iolist = attributes_to_iolist(attribs)
["<", to_string(tag_name), attrib_iolist, " ", "/>"]
["<", tag_to_string(tag_name), attrib_iolist, " ", "/>"]
end

def render_tag(tag) do
Expand Down
17 changes: 17 additions & 0 deletions lib/sneeze/macros.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule Sneeze.Macros do
@moduledoc false

defmacro define_tags_to_strings(tags) do
quote bind_quoted: [tags: tags] do
Enum.each(tags, fn tagname ->
as_str = to_string(tagname)

defp tag_to_string(unquote(tagname)) do
unquote(as_str)
end
end)

defp tag_to_string(unknown_tag), do: to_string(unknown_tag)
end
end
end