diff --git a/Makefile b/Makefile index b663fa5..2ab1aee 100644 --- a/Makefile +++ b/Makefile @@ -5,3 +5,6 @@ build: lint: npx prettier ./generator --write + +setup: + npx playwright install \ No newline at end of file diff --git a/generator.js b/generator.js index 47ca1d4..d1e97e3 100644 --- a/generator.js +++ b/generator.js @@ -70,17 +70,10 @@ const fs = require("fs"); import Nitroux.Utils ${extractedElements .map((e) => { - if (voidElements.includes(e)) { return ` @spec ${e}(String.t() | Nitroux.Types.GlobalAttributes.t) :: binary - def ${e}(attrs), do: "${e}" |> tag(attrs, false) - `; - } else { - return ` - @spec ${e}(String.t() | Nitroux.Types.GlobalAttributes.t) :: binary - def ${e}(attrs), do: "${e}" |> tag(attrs) - `; - } + def ${e}(attrs), do: "${e}" |> tag(attrs ${voidElements.includes(e) ? ", false" : ""}) + ` }) .join("\n")} end diff --git a/generator/global-attributes.js b/generator/global-attributes.js index 3b8976e..49b0527 100644 --- a/generator/global-attributes.js +++ b/generator/global-attributes.js @@ -34,23 +34,25 @@ fs.readFile(filePath, "utf8", (err, data) => { # AUTO GENERATED DO NOT EDIT @type t :: [${attributeList - .map((e) => { - return ` + .map((e) => { + return ` ${e.name}: ${e.name}, `; - }) - .join("")}] + }) + .join("")}] ${attributeList - .map((e) => { + .map((e) => { return ` @typedoc """ ${e.description} """ - @type ${e.name} :: ${e.ty == "String" ? "String.t()" : "bool"} + @type ${e.name} :: ${ + e.ty == "String" ? "String.t()" : "bool" + } `; - }) - .join("\n")} + }) + .join("\n")} end `; fs.writeFileSync(outputFilePath, wrappedElement); diff --git a/lib/nitroux/utils.ex b/lib/nitroux/utils.ex index 9ffcca8..fcaad2c 100644 --- a/lib/nitroux/utils.ex +++ b/lib/nitroux/utils.ex @@ -1,6 +1,6 @@ defmodule Nitroux.Utils do @type tag :: String.t() - @spec tag(any, Nitroux.Types.GlobalAttributes.t() | [tag] | tag, any) :: <<_::24, _::_*8>> + @spec tag(any, Nitroux.Types.GlobalAttributes.t() | [tag] | tag, any) :: tag() @doc """ Generates dynamic open and closing tags around content iex> Nitroux.Utils.tag("div", ["hello", " ", "world"]) @@ -18,6 +18,7 @@ defmodule Nitroux.Utils do def tag(name, attrs, container \\ true) def tag(name, attrs, false), do: "<#{name}#{add_attributes(attrs)}/>" def tag(name, [], _container), do: name |> tag("", true) + def tag(name, [{_, _} | _t] = keywordlist, _container), do: "<#{name}#{add_attributes(keywordlist)}>#{Keyword.get(keywordlist, :html, "")}"