diff --git a/README.md b/README.md index 2558b88..0070268 100644 --- a/README.md +++ b/README.md @@ -30,4 +30,14 @@ and style it with some classes <%= Heroicons.Solid.cake(class: "h-6 w-6 text-gray-500") %> ``` +Note these functions return `Phoenix.HTML.Safe` iodata: +```elixir +iex(1)> Heroicons.Solid.academic_cap +{:safe, + [" Heroicons.Solid.academic_cap |> Phoenix.HTML.safe_to_string +"\n ..." +``` + For a full list of icons see [the docs](https://hexdocs.pm/heroicons/api-reference.html) or [heroicons.com](https://heroicons.com/). diff --git a/lib/heroicons.ex b/lib/heroicons.ex index dfc1eb1..a8dfa71 100644 --- a/lib/heroicons.ex +++ b/lib/heroicons.ex @@ -48,11 +48,8 @@ defmodule Heroicons do @doc unquote(doc) @spec unquote(name)(keyword(binary)) :: binary def unquote(name)(opts \\ []) do - attrs = - opts - |> Enum.map_join(fn {k, v} -> ~s( #{k}="#{v}") end) - - unquote(head) <> attrs <> unquote(tail) + attrs = for {k, v} <- opts, do: {:safe, [Phoenix.HTML.Safe.to_iodata(k), ?=, ?", Phoenix.HTML.Safe.to_iodata(v), ?"]} + {:safe, [unquote(head), Phoenix.HTML.Safe.to_iodata(attrs), unquote(tail)]} end end end diff --git a/mix.exs b/mix.exs index ed52c93..3f3d6f5 100644 --- a/mix.exs +++ b/mix.exs @@ -26,8 +26,7 @@ defmodule HeroiconsElixir.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - # {:dep_from_hexpm, "~> 0.3.0"}, - # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} + {:phoenix_html, "~> 2.14"}, {:ex_doc, "~> 0.23", only: :dev, runtime: false} ] end diff --git a/mix.lock b/mix.lock index a770f90..d96712e 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,12 @@ "makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"}, "meeseeks": {:hex, :meeseeks, "0.15.1", "148d5d9ea879cdb415b8bc4162ac5528f9a2fe42fbfe1802c681a2842cb1c0a4", [:mix], [{:meeseeks_html5ever, "~> 0.12.1", [hex: :meeseeks_html5ever, repo: "hexpm", optional: false]}], "hexpm", "5589957b7cca75e6683cecc308253d7854f43b07806939d7031b81ca6e8abd98"}, "meeseeks_html5ever": {:hex, :meeseeks_html5ever, "0.12.1", "718fab10d05b83204524a518b2b88caa37ba6a6e02f82e80d6a7bc47552fb54a", [:mix], [{:rustler, "~> 0.21.0", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm", "11489094637f49a26bad4610a9138352c8d229339d888169cb35b08cdfd8861a"}, + "mime": {:hex, :mime, "1.5.0", "203ef35ef3389aae6d361918bf3f952fa17a09e8e43b5aa592b93eba05d0fb8d", [:mix], [], "hexpm", "55a94c0f552249fc1a3dd9cd2d3ab9de9d3c89b559c2bd01121f824834f24746"}, "nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"}, + "phoenix_html": {:hex, :phoenix_html, "2.14.3", "51f720d0d543e4e157ff06b65de38e13303d5778a7919bcc696599e5934271b8", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "efd697a7fff35a13eeeb6b43db884705cba353a1a41d127d118fda5f90c8e80f"}, + "plug": {:hex, :plug, "1.11.1", "f2992bac66fdae679453c9e86134a4201f6f43a687d8ff1cd1b2862d53c80259", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "23524e4fefbb587c11f0833b3910bfb414bf2e2534d61928e920f54e3a1b881f"}, + "plug_crypto": {:hex, :plug_crypto, "1.2.1", "5c854427528bf61d159855cedddffc0625e2228b5f30eff76d5a4de42d896ef4", [:mix], [], "hexpm", "6961c0e17febd9d0bfa89632d391d2545d2e0eb73768f5f50305a23961d8782c"}, "rustler": {:hex, :rustler, "0.21.1", "5299980be32da997c54382e945bacaa015ed97a60745e1e639beaf6a7b278c65", [:mix], [{:toml, "~> 0.5.2", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "6ee1651e10645b2b2f3bb70502bf180341aa058709177e9bc28c105934094bc6"}, + "telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"}, "toml": {:hex, :toml, "0.5.2", "e471388a8726d1ce51a6b32f864b8228a1eb8edc907a0edf2bb50eab9321b526", [:mix], [], "hexpm", "f1e3dabef71fb510d015fad18c0e05e7c57281001141504c6b69d94e99750a07"}, } diff --git a/test/heroicons_test.exs b/test/heroicons_test.exs index 79fcf6f..f6bbdf5 100644 --- a/test/heroicons_test.exs +++ b/test/heroicons_test.exs @@ -7,25 +7,35 @@ defmodule HeroiconsTest do |> Path.join("outline/academic-cap.svg") |> File.read!() - assert Heroicons.Outline.academic_cap() == academic_cap + assert Heroicons.Outline.academic_cap() + |> Phoenix.HTML.safe_to_string() == + academic_cap - assert TestIcons.academic_cap(class: "h-6 w-6 text-gray-500") =~ + assert Heroicons.Outline.academic_cap(class: "h-6 w-6 text-gray-500") + |> Phoenix.HTML.safe_to_string() =~ ~s(class="h-6 w-6 text-gray-500") + + assert Heroicons.Outline.academic_cap(class: "<> \" ") + |> Phoenix.HTML.safe_to_string() =~ + ~s(class="<> ") end test "generated docs" do - {:docs_v1, _annotation, _beam_language, _format, _module_doc, - _metadata, docs} = Code.fetch_docs(Heroicons.Outline) + {:docs_v1, _annotation, _beam_language, _format, _module_doc, _metadata, docs} = + Code.fetch_docs(Heroicons.Outline) - doc = Enum.find_value(docs, fn {{:function, :academic_cap, 1}, _annotation, _signature, doc, _metadata} -> doc - _ -> nil end) + doc = + Enum.find_value(docs, fn + {{:function, :academic_cap, 1}, _annotation, _signature, doc, _metadata} -> doc + _ -> nil + end) assert doc["en"] == """ - ![](assets/outline/academic-cap.svg) {: width=24px} + ![](assets/outline/academic-cap.svg) {: width=24px} - ## Examples - iex> academic_cap() - iex> academic_cap(class: "h-6 w-6 text-gray-500") - """ + ## Examples + iex> academic_cap() + iex> academic_cap(class: "h-6 w-6 text-gray-500") + """ end end