diff --git a/README.md b/README.md index 9988c69..69631bb 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This library provides [Nitrogen](https://nitrogenproject.com/)-like templating f ### Generate HTML -Each `Nitroux` function represents an HTML tag and generates HTML content. Example: +Each `Nitroux` function represents an HTML tag and generates HTML content: ```elixir iex> Nitroux.hr() @@ -41,6 +41,16 @@ iex> Nitroux.div(html: p("hello world")) "

hello world

" ``` +### Use typed version + +If you want additional type hints and don't mind additional verbosity, use `Nitroux.HtmlTypedTags` module. Instead of `html` key in keyword parameters, content is passed via a second parameter, which can be either a tag or a list of tags. + +```elixir +iex> Nitroux.HtmlTypedTags.div([class: "red"], Nitroux.HtmlTypedTags.p([], "hello world")) +"

hello world

" +``` + + ## Rationale Take this HTML as an example: @@ -53,7 +63,7 @@ Take this HTML as an example: ``` -We usually don't think of HTML as code, but if we were to treat it as such, would have to admit that this example does not adhere to the DRY (Don't Repeat Yourself) principle. Nitroux solves this problem by allowing us to think of HTML as code, while keeping our maintenance burden to the minimum. The above example becomes: +We usually don't think of HTML as code, but if we were to treat it as such, we would have to admit that this example does not adhere to the DRY (Don't Repeat Yourself) principle. Nitroux solves this problem by allowing us to think of HTML as code, while keeping our maintenance burden to the minimum. The above example becomes: ```elixir import Nitroux @@ -88,7 +98,7 @@ by adding `nitroux` to your list of dependencies in `mix.exs`: ```elixir def deps do [ - {:nitroux, "~> 0.3"} + {:nitroux, "~> 0.4"} ] end ``` diff --git a/generator.js b/generator.js index 7be5a4a..814a174 100644 --- a/generator.js +++ b/generator.js @@ -45,8 +45,8 @@ const fs = require("fs"); } else { console.log("No rows found in the table."); } - const outputFilePath = "lib/nitroux/html_tags.ex"; - const wrappedElement = ` + let outputFilePath = "lib/nitroux/html_tags.ex"; + let wrappedElement = ` defmodule Nitroux.HtmlTags do # AUTO GENERATED. DO NOT EDIT @@ -57,7 +57,7 @@ const fs = require("fs"); ${extractedElements .map((e) => { return ` - @spec ${e}(String.t() | Nitroux.Types.GlobalAttributes.t) :: binary + @spec ${e}(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def ${e}(attrs), do: "${e}" |> tag(attrs ${voidElements.includes(e) ? ", false" : ""}) ` }) @@ -67,7 +67,30 @@ const fs = require("fs"); end `; fs.writeFileSync(outputFilePath, wrappedElement); + + outputFilePath = "lib/nitroux/html_typed_tags.ex"; + wrappedElement = ` + defmodule Nitroux.HtmlTypedTags do + + # AUTO GENERATED. DO NOT EDIT + + defmacro __using__(_opts) do + quote do + import Nitroux.Utils + ${extractedElements + .map((e) => { + return ` + @spec ${e}(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def ${e}(attrs, content), do: "${e}" |> tag(attrs, content ${voidElements.includes(e) ? ", false" : ""}) + ` + }) + .join("\n")} + end + end + end + `; + fs.writeFileSync(outputFilePath, wrappedElement); // Close the browser await browser.close(); })(); diff --git a/lib/nitroux/html_tags.ex b/lib/nitroux/html_tags.ex index 50fcde6..bf5c05e 100644 --- a/lib/nitroux/html_tags.ex +++ b/lib/nitroux/html_tags.ex @@ -5,340 +5,340 @@ defmodule Nitroux.HtmlTags do quote do import Nitroux.Utils - @spec a(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec a(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def a(attrs), do: "a" |> tag(attrs) - @spec abbr(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec abbr(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def abbr(attrs), do: "abbr" |> tag(attrs) - @spec address(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec address(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def address(attrs), do: "address" |> tag(attrs) - @spec area(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec area(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def area(attrs), do: "area" |> tag(attrs, false) - @spec article(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec article(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def article(attrs), do: "article" |> tag(attrs) - @spec aside(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec aside(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def aside(attrs), do: "aside" |> tag(attrs) - @spec audio(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec audio(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def audio(attrs), do: "audio" |> tag(attrs) - @spec b(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec b(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def b(attrs), do: "b" |> tag(attrs) - @spec base(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec base(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def base(attrs), do: "base" |> tag(attrs, false) - @spec bdi(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec bdi(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def bdi(attrs), do: "bdi" |> tag(attrs) - @spec bdo(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec bdo(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def bdo(attrs), do: "bdo" |> tag(attrs) - @spec blockquote(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec blockquote(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def blockquote(attrs), do: "blockquote" |> tag(attrs) - @spec body(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec body(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def body(attrs), do: "body" |> tag(attrs) - @spec br(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec br(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def br(attrs), do: "br" |> tag(attrs, false) - @spec button(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec button(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def button(attrs), do: "button" |> tag(attrs) - @spec canvas(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec canvas(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def canvas(attrs), do: "canvas" |> tag(attrs) - @spec caption(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec caption(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def caption(attrs), do: "caption" |> tag(attrs) - @spec cite(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec cite(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def cite(attrs), do: "cite" |> tag(attrs) - @spec code(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec code(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def code(attrs), do: "code" |> tag(attrs) - @spec col(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec col(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def col(attrs), do: "col" |> tag(attrs, false) - @spec colgroup(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec colgroup(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def colgroup(attrs), do: "colgroup" |> tag(attrs) - @spec data(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec data(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def data(attrs), do: "data" |> tag(attrs) - @spec datalist(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec datalist(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def datalist(attrs), do: "datalist" |> tag(attrs) - @spec dd(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec dd(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def dd(attrs), do: "dd" |> tag(attrs) - @spec del(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec del(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def del(attrs), do: "del" |> tag(attrs) - @spec details(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec details(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def details(attrs), do: "details" |> tag(attrs) - @spec dfn(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec dfn(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def dfn(attrs), do: "dfn" |> tag(attrs) - @spec dialog(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec dialog(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def dialog(attrs), do: "dialog" |> tag(attrs) - @spec div(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec div(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def div(attrs), do: "div" |> tag(attrs) - @spec dl(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec dl(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def dl(attrs), do: "dl" |> tag(attrs) - @spec dt(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec dt(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def dt(attrs), do: "dt" |> tag(attrs) - @spec em(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec em(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def em(attrs), do: "em" |> tag(attrs) - @spec embed(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec embed(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def embed(attrs), do: "embed" |> tag(attrs, false) - @spec fieldset(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec fieldset(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def fieldset(attrs), do: "fieldset" |> tag(attrs) - @spec figcaption(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec figcaption(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def figcaption(attrs), do: "figcaption" |> tag(attrs) - @spec figure(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec figure(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def figure(attrs), do: "figure" |> tag(attrs) - @spec footer(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec footer(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def footer(attrs), do: "footer" |> tag(attrs) - @spec form(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec form(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def form(attrs), do: "form" |> tag(attrs) - @spec h1(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec h1(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def h1(attrs), do: "h1" |> tag(attrs) - @spec h2(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec h2(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def h2(attrs), do: "h2" |> tag(attrs) - @spec h3(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec h3(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def h3(attrs), do: "h3" |> tag(attrs) - @spec h4(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec h4(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def h4(attrs), do: "h4" |> tag(attrs) - @spec h5(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec h5(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def h5(attrs), do: "h5" |> tag(attrs) - @spec h6(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec h6(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def h6(attrs), do: "h6" |> tag(attrs) - @spec head(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec head(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def head(attrs), do: "head" |> tag(attrs) - @spec header(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec header(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def header(attrs), do: "header" |> tag(attrs) - @spec hgroup(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec hgroup(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def hgroup(attrs), do: "hgroup" |> tag(attrs) - @spec hr(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec hr(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def hr(attrs), do: "hr" |> tag(attrs, false) - @spec html(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec html(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def html(attrs), do: "html" |> tag(attrs) - @spec i(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec i(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def i(attrs), do: "i" |> tag(attrs) - @spec iframe(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec iframe(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def iframe(attrs), do: "iframe" |> tag(attrs) - @spec img(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec img(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def img(attrs), do: "img" |> tag(attrs, false) - @spec input(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec input(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def input(attrs), do: "input" |> tag(attrs, false) - @spec ins(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec ins(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def ins(attrs), do: "ins" |> tag(attrs) - @spec kbd(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec kbd(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def kbd(attrs), do: "kbd" |> tag(attrs) - @spec label(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec label(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def label(attrs), do: "label" |> tag(attrs) - @spec legend(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec legend(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def legend(attrs), do: "legend" |> tag(attrs) - @spec li(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec li(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def li(attrs), do: "li" |> tag(attrs) - @spec link(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec link(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def link(attrs), do: "link" |> tag(attrs, false) - @spec main(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec main(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def main(attrs), do: "main" |> tag(attrs) - @spec map(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec map(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def map(attrs), do: "map" |> tag(attrs) - @spec mark(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec mark(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def mark(attrs), do: "mark" |> tag(attrs) - @spec menu(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec menu(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def menu(attrs), do: "menu" |> tag(attrs) - @spec meta(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec meta(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def meta(attrs), do: "meta" |> tag(attrs, false) - @spec meter(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec meter(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def meter(attrs), do: "meter" |> tag(attrs) - @spec nav(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec nav(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def nav(attrs), do: "nav" |> tag(attrs) - @spec noscript(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec noscript(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def noscript(attrs), do: "noscript" |> tag(attrs) - @spec object(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec object(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def object(attrs), do: "object" |> tag(attrs) - @spec ol(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec ol(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def ol(attrs), do: "ol" |> tag(attrs) - @spec optgroup(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec optgroup(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def optgroup(attrs), do: "optgroup" |> tag(attrs) - @spec option(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec option(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def option(attrs), do: "option" |> tag(attrs) - @spec output(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec output(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def output(attrs), do: "output" |> tag(attrs) - @spec p(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec p(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def p(attrs), do: "p" |> tag(attrs) - @spec picture(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec picture(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def picture(attrs), do: "picture" |> tag(attrs) - @spec pre(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec pre(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def pre(attrs), do: "pre" |> tag(attrs) - @spec progress(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec progress(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def progress(attrs), do: "progress" |> tag(attrs) - @spec q(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec q(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def q(attrs), do: "q" |> tag(attrs) - @spec rp(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec rp(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def rp(attrs), do: "rp" |> tag(attrs) - @spec rt(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec rt(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def rt(attrs), do: "rt" |> tag(attrs) - @spec ruby(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec ruby(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def ruby(attrs), do: "ruby" |> tag(attrs) - @spec s(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec s(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def s(attrs), do: "s" |> tag(attrs) - @spec samp(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec samp(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def samp(attrs), do: "samp" |> tag(attrs) - @spec script(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec script(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def script(attrs), do: "script" |> tag(attrs) - @spec search(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec search(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def search(attrs), do: "search" |> tag(attrs) - @spec section(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec section(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def section(attrs), do: "section" |> tag(attrs) - @spec select(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec select(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def select(attrs), do: "select" |> tag(attrs) - @spec slot(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec slot(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def slot(attrs), do: "slot" |> tag(attrs) - @spec small(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec small(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def small(attrs), do: "small" |> tag(attrs) - @spec source(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec source(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def source(attrs), do: "source" |> tag(attrs, false) - @spec span(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec span(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def span(attrs), do: "span" |> tag(attrs) - @spec strong(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec strong(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def strong(attrs), do: "strong" |> tag(attrs) - @spec style(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec style(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def style(attrs), do: "style" |> tag(attrs) - @spec sub(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec sub(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def sub(attrs), do: "sub" |> tag(attrs) - @spec summary(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec summary(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def summary(attrs), do: "summary" |> tag(attrs) - @spec sup(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec sup(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def sup(attrs), do: "sup" |> tag(attrs) - @spec table(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec table(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def table(attrs), do: "table" |> tag(attrs) - @spec tbody(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec tbody(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def tbody(attrs), do: "tbody" |> tag(attrs) - @spec td(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec td(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def td(attrs), do: "td" |> tag(attrs) - @spec template(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec template(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def template(attrs), do: "template" |> tag(attrs) - @spec textarea(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec textarea(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def textarea(attrs), do: "textarea" |> tag(attrs) - @spec tfoot(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec tfoot(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def tfoot(attrs), do: "tfoot" |> tag(attrs) - @spec th(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec th(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def th(attrs), do: "th" |> tag(attrs) - @spec thead(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec thead(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def thead(attrs), do: "thead" |> tag(attrs) - @spec time(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec time(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def time(attrs), do: "time" |> tag(attrs) - @spec title(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec title(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def title(attrs), do: "title" |> tag(attrs) - @spec tr(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec tr(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def tr(attrs), do: "tr" |> tag(attrs) - @spec track(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec track(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def track(attrs), do: "track" |> tag(attrs, false) - @spec u(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec u(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def u(attrs), do: "u" |> tag(attrs) - @spec ul(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec ul(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def ul(attrs), do: "ul" |> tag(attrs) - @spec var(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec var(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def var(attrs), do: "var" |> tag(attrs) - @spec video(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec video(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def video(attrs), do: "video" |> tag(attrs) - @spec wbr(String.t() | Nitroux.Types.GlobalAttributes.t()) :: binary + @spec wbr(map() | [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: Nitroux.Utils.tag() def wbr(attrs), do: "wbr" |> tag(attrs, false) end end diff --git a/lib/nitroux/html_typed_tags.ex b/lib/nitroux/html_typed_tags.ex new file mode 100644 index 0000000..31d3883 --- /dev/null +++ b/lib/nitroux/html_typed_tags.ex @@ -0,0 +1,525 @@ +defmodule Nitroux.HtmlTypedTags do + # AUTO GENERATED. DO NOT EDIT + + defmacro __using__(_opts) do + quote do + import Nitroux.Utils + + @spec a(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def a(attrs, content), do: "a" |> tag(attrs, content) + + @spec abbr(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def abbr(attrs, content), do: "abbr" |> tag(attrs, content) + + @spec address( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def address(attrs, content), do: "address" |> tag(attrs, content) + + @spec area(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def area(attrs, content), do: "area" |> tag(attrs, content, false) + + @spec article( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def article(attrs, content), do: "article" |> tag(attrs, content) + + @spec aside(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def aside(attrs, content), do: "aside" |> tag(attrs, content) + + @spec audio(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def audio(attrs, content), do: "audio" |> tag(attrs, content) + + @spec b(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def b(attrs, content), do: "b" |> tag(attrs, content) + + @spec base(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def base(attrs, content), do: "base" |> tag(attrs, content, false) + + @spec bdi(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def bdi(attrs, content), do: "bdi" |> tag(attrs, content) + + @spec bdo(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def bdo(attrs, content), do: "bdo" |> tag(attrs, content) + + @spec blockquote( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def blockquote(attrs, content), do: "blockquote" |> tag(attrs, content) + + @spec body(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def body(attrs, content), do: "body" |> tag(attrs, content) + + @spec br(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def br(attrs, content), do: "br" |> tag(attrs, content, false) + + @spec button( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def button(attrs, content), do: "button" |> tag(attrs, content) + + @spec canvas( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def canvas(attrs, content), do: "canvas" |> tag(attrs, content) + + @spec caption( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def caption(attrs, content), do: "caption" |> tag(attrs, content) + + @spec cite(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def cite(attrs, content), do: "cite" |> tag(attrs, content) + + @spec code(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def code(attrs, content), do: "code" |> tag(attrs, content) + + @spec col(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def col(attrs, content), do: "col" |> tag(attrs, content, false) + + @spec colgroup( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def colgroup(attrs, content), do: "colgroup" |> tag(attrs, content) + + @spec data(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def data(attrs, content), do: "data" |> tag(attrs, content) + + @spec datalist( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def datalist(attrs, content), do: "datalist" |> tag(attrs, content) + + @spec dd(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def dd(attrs, content), do: "dd" |> tag(attrs, content) + + @spec del(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def del(attrs, content), do: "del" |> tag(attrs, content) + + @spec details( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def details(attrs, content), do: "details" |> tag(attrs, content) + + @spec dfn(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def dfn(attrs, content), do: "dfn" |> tag(attrs, content) + + @spec dialog( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def dialog(attrs, content), do: "dialog" |> tag(attrs, content) + + @spec div(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def div(attrs, content), do: "div" |> tag(attrs, content) + + @spec dl(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def dl(attrs, content), do: "dl" |> tag(attrs, content) + + @spec dt(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def dt(attrs, content), do: "dt" |> tag(attrs, content) + + @spec em(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def em(attrs, content), do: "em" |> tag(attrs, content) + + @spec embed(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def embed(attrs, content), do: "embed" |> tag(attrs, content, false) + + @spec fieldset( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def fieldset(attrs, content), do: "fieldset" |> tag(attrs, content) + + @spec figcaption( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def figcaption(attrs, content), do: "figcaption" |> tag(attrs, content) + + @spec figure( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def figure(attrs, content), do: "figure" |> tag(attrs, content) + + @spec footer( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def footer(attrs, content), do: "footer" |> tag(attrs, content) + + @spec form(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def form(attrs, content), do: "form" |> tag(attrs, content) + + @spec h1(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def h1(attrs, content), do: "h1" |> tag(attrs, content) + + @spec h2(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def h2(attrs, content), do: "h2" |> tag(attrs, content) + + @spec h3(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def h3(attrs, content), do: "h3" |> tag(attrs, content) + + @spec h4(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def h4(attrs, content), do: "h4" |> tag(attrs, content) + + @spec h5(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def h5(attrs, content), do: "h5" |> tag(attrs, content) + + @spec h6(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def h6(attrs, content), do: "h6" |> tag(attrs, content) + + @spec head(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def head(attrs, content), do: "head" |> tag(attrs, content) + + @spec header( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def header(attrs, content), do: "header" |> tag(attrs, content) + + @spec hgroup( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def hgroup(attrs, content), do: "hgroup" |> tag(attrs, content) + + @spec hr(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def hr(attrs, content), do: "hr" |> tag(attrs, content, false) + + @spec html(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def html(attrs, content), do: "html" |> tag(attrs, content) + + @spec i(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def i(attrs, content), do: "i" |> tag(attrs, content) + + @spec iframe( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def iframe(attrs, content), do: "iframe" |> tag(attrs, content) + + @spec img(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def img(attrs, content), do: "img" |> tag(attrs, content, false) + + @spec input(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def input(attrs, content), do: "input" |> tag(attrs, content, false) + + @spec ins(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def ins(attrs, content), do: "ins" |> tag(attrs, content) + + @spec kbd(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def kbd(attrs, content), do: "kbd" |> tag(attrs, content) + + @spec label(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def label(attrs, content), do: "label" |> tag(attrs, content) + + @spec legend( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def legend(attrs, content), do: "legend" |> tag(attrs, content) + + @spec li(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def li(attrs, content), do: "li" |> tag(attrs, content) + + @spec link(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def link(attrs, content), do: "link" |> tag(attrs, content, false) + + @spec main(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def main(attrs, content), do: "main" |> tag(attrs, content) + + @spec map(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def map(attrs, content), do: "map" |> tag(attrs, content) + + @spec mark(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def mark(attrs, content), do: "mark" |> tag(attrs, content) + + @spec menu(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def menu(attrs, content), do: "menu" |> tag(attrs, content) + + @spec meta(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def meta(attrs, content), do: "meta" |> tag(attrs, content, false) + + @spec meter(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def meter(attrs, content), do: "meter" |> tag(attrs, content) + + @spec nav(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def nav(attrs, content), do: "nav" |> tag(attrs, content) + + @spec noscript( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def noscript(attrs, content), do: "noscript" |> tag(attrs, content) + + @spec object( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def object(attrs, content), do: "object" |> tag(attrs, content) + + @spec ol(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def ol(attrs, content), do: "ol" |> tag(attrs, content) + + @spec optgroup( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def optgroup(attrs, content), do: "optgroup" |> tag(attrs, content) + + @spec option( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def option(attrs, content), do: "option" |> tag(attrs, content) + + @spec output( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def output(attrs, content), do: "output" |> tag(attrs, content) + + @spec p(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def p(attrs, content), do: "p" |> tag(attrs, content) + + @spec picture( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def picture(attrs, content), do: "picture" |> tag(attrs, content) + + @spec pre(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def pre(attrs, content), do: "pre" |> tag(attrs, content) + + @spec progress( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def progress(attrs, content), do: "progress" |> tag(attrs, content) + + @spec q(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def q(attrs, content), do: "q" |> tag(attrs, content) + + @spec rp(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def rp(attrs, content), do: "rp" |> tag(attrs, content) + + @spec rt(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def rt(attrs, content), do: "rt" |> tag(attrs, content) + + @spec ruby(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def ruby(attrs, content), do: "ruby" |> tag(attrs, content) + + @spec s(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def s(attrs, content), do: "s" |> tag(attrs, content) + + @spec samp(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def samp(attrs, content), do: "samp" |> tag(attrs, content) + + @spec script( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def script(attrs, content), do: "script" |> tag(attrs, content) + + @spec search( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def search(attrs, content), do: "search" |> tag(attrs, content) + + @spec section( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def section(attrs, content), do: "section" |> tag(attrs, content) + + @spec select( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def select(attrs, content), do: "select" |> tag(attrs, content) + + @spec slot(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def slot(attrs, content), do: "slot" |> tag(attrs, content) + + @spec small(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def small(attrs, content), do: "small" |> tag(attrs, content) + + @spec source( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def source(attrs, content), do: "source" |> tag(attrs, content, false) + + @spec span(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def span(attrs, content), do: "span" |> tag(attrs, content) + + @spec strong( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def strong(attrs, content), do: "strong" |> tag(attrs, content) + + @spec style(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def style(attrs, content), do: "style" |> tag(attrs, content) + + @spec sub(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def sub(attrs, content), do: "sub" |> tag(attrs, content) + + @spec summary( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def summary(attrs, content), do: "summary" |> tag(attrs, content) + + @spec sup(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def sup(attrs, content), do: "sup" |> tag(attrs, content) + + @spec table(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def table(attrs, content), do: "table" |> tag(attrs, content) + + @spec tbody(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def tbody(attrs, content), do: "tbody" |> tag(attrs, content) + + @spec td(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def td(attrs, content), do: "td" |> tag(attrs, content) + + @spec template( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def template(attrs, content), do: "template" |> tag(attrs, content) + + @spec textarea( + Nitroux.Types.GlobalAttributes.t(), + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + ) :: [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def textarea(attrs, content), do: "textarea" |> tag(attrs, content) + + @spec tfoot(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def tfoot(attrs, content), do: "tfoot" |> tag(attrs, content) + + @spec th(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def th(attrs, content), do: "th" |> tag(attrs, content) + + @spec thead(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def thead(attrs, content), do: "thead" |> tag(attrs, content) + + @spec time(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def time(attrs, content), do: "time" |> tag(attrs, content) + + @spec title(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def title(attrs, content), do: "title" |> tag(attrs, content) + + @spec tr(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def tr(attrs, content), do: "tr" |> tag(attrs, content) + + @spec track(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def track(attrs, content), do: "track" |> tag(attrs, content, false) + + @spec u(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def u(attrs, content), do: "u" |> tag(attrs, content) + + @spec ul(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def ul(attrs, content), do: "ul" |> tag(attrs, content) + + @spec var(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def var(attrs, content), do: "var" |> tag(attrs, content) + + @spec video(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def video(attrs, content), do: "video" |> tag(attrs, content) + + @spec wbr(Nitroux.Types.GlobalAttributes.t(), [Nitroux.Utils.tag()] | Nitroux.Utils.tag()) :: + [Nitroux.Utils.tag()] | Nitroux.Utils.tag() + def wbr(attrs, content), do: "wbr" |> tag(attrs, content, false) + end + end +end diff --git a/lib/nitroux/utils.ex b/lib/nitroux/utils.ex index 605666b..ab24f97 100644 --- a/lib/nitroux/utils.ex +++ b/lib/nitroux/utils.ex @@ -1,6 +1,7 @@ defmodule Nitroux.Utils do + alias Nitroux.Types.GlobalAttributes @type tag :: String.t() - @spec tag(any, Nitroux.Types.GlobalAttributes.t() | [tag] | tag, boolean()) :: tag() + @spec tag(any, map() | [tag] | tag, boolean()) :: tag() @doc """ Generates dynamic open and closing tags around content iex> Nitroux.Utils.tag("div", []) @@ -23,6 +24,16 @@ defmodule Nitroux.Utils do 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}" + @spec typed_tag(String.t(), GlobalAttributes.t(), [tag()] | tag(), boolean()) :: tag() + def typed_tag(name, attrs, content, container \\ true) + def typed_tag(name, attrs, _, false), do: "<#{name}#{add_attributes(attrs)}/>" + + def typed_tag(name, attrs, [_h | _t] = list, true), + do: "<#{name}#{add_attributes(attrs)}>#{Enum.join(list)}" + + def typed_tag(name, attrs, content, true), + do: "<#{name}#{add_attributes(attrs)}>#{content}" + defp add_attributes(attrs) do attrs |> Keyword.filter(fn {key, _} -> diff --git a/mix.exs b/mix.exs index 6f4f80d..31aea48 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Nitroux.MixProject do def project do [ app: :nitroux, - version: "0.3.3", + version: "0.4.0", elixir: "~> 1.13", name: "nitroux", description: description(), diff --git a/test/nitroux/utils_test.exs b/test/nitroux/utils_test.exs index d42676e..7798d35 100644 --- a/test/nitroux/utils_test.exs +++ b/test/nitroux/utils_test.exs @@ -53,13 +53,68 @@ defmodule Nitroux.UtilsTest do assert tag == "
test
test
" end - test "tag/3 with non-conteiner" do - tag = Nitroux.Utils.tag("input", [], false) + test "typed_tag/3 with non-conteiner" do + tag = Nitroux.Utils.typed_tag("input", [], nil, false) assert tag == "" - tag = Nitroux.Utils.tag("meta", [lang: "en"], false) + tag = Nitroux.Utils.typed_tag("meta", [lang: "en"], nil, false) assert tag == "" end + + test "typed_tag/3 with simple text" do + assert Nitroux.Utils.typed_tag("div", [], "test") == "
test
" + end + + test "typed_tag/3 with attributes and simple text" do + tag = + Nitroux.Utils.typed_tag( + "div", + [ + class: "bg", + id: "app" + ], + "test" + ) + + assert tag =~ "class=\"bg\"" + assert tag =~ "id=\"app\"" + assert tag =~ "test" + end + + test "typed_tag/3 with attributes and another tag" do + tag = + Nitroux.Utils.typed_tag( + "div", + [ + class: "outer", + id: "app" + ], + "test" + ) + + tag = + Nitroux.Utils.typed_tag( + "div", + [ + class: "bg", + id: "app" + ], + tag + ) + + assert tag =~ "class=\"outer\"" + assert tag =~ "class=\"bg\"" + assert tag =~ "id=\"app\"" + assert tag =~ "test" + + tag = + Nitroux.Utils.typed_tag("div", [], "test") + + tag = + Nitroux.Utils.typed_tag("div", [], [tag, tag]) + + assert tag == "
test
test
" + end end