Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
tolyo committed Nov 22, 2023
1 parent 5242e9c commit 7f63b8b
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/nitroux/utils.ex
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
defmodule Nitroux.Utils do
@type tag :: String.t()
@spec tag(any, Nitroux.Types.GlobalAttributes.t() | [tag] | tag, any) :: tag()
@spec tag(any, Nitroux.Types.GlobalAttributes.t() | [tag] | tag, boolean()) :: tag()
@doc """
Generates dynamic open and closing tags around content
iex> Nitroux.Utils.tag("div", ["hello", " ", "world"])
"<div>hello world</div>"
Generates dynamic open and closing tags around content
iex> Nitroux.Utils.tag("div", [])
"<div></div>"
Nitroux.Utils.tag("div", [])
"<div></div>"
iex> Nitroux.Utils.tag("div", ["hello world"])
"<div>hello world</div>"
Nitroux.Utils.tag("div", [html: "hello world"])
"<div>hello world</div>"
iex> Nitroux.Utils.tag("div", ["hello", " ", "world"])
"<div>hello world</div>"
Nitroux.Utils.tag("div", [class: "test", html: "hello world"])
"<div class=\"test\">hello world</div>"
"""
def tag(name, attrs, container \\ true)
def tag(name, attrs, false), do: "<#{name}#{add_attributes(attrs)}/>"
Expand All @@ -23,7 +21,6 @@ defmodule Nitroux.Utils do
do: "<#{name}#{add_attributes(keywordlist)}>#{Keyword.get(keywordlist, :html, "")}</#{name}>"

def tag(name, [_h | _t] = list, _container), do: name |> tag(html: Enum.join(list))

def tag(name, text, _) when is_binary(text), do: "<#{name}>#{text}</#{name}>"

defp add_attributes(attrs) do
Expand Down

0 comments on commit 7f63b8b

Please sign in to comment.