Convert underscores to dashes in attributes
This commit is contained in:
@ -48,7 +48,15 @@ defmodule Heroicons do
|
|||||||
@doc unquote(doc)
|
@doc unquote(doc)
|
||||||
@spec unquote(name)(keyword(binary)) :: binary
|
@spec unquote(name)(keyword(binary)) :: binary
|
||||||
def unquote(name)(opts \\ []) do
|
def unquote(name)(opts \\ []) do
|
||||||
attrs = for {k, v} <- opts, do: {:safe, [Phoenix.HTML.Safe.to_iodata(k), ?=, ?", Phoenix.HTML.Safe.to_iodata(v), ?"]}
|
attrs =
|
||||||
|
for {k, v} <- opts do
|
||||||
|
safe_k =
|
||||||
|
k |> Atom.to_string() |> String.replace("_", "-") |> Phoenix.HTML.Safe.to_iodata()
|
||||||
|
safe_v = v |> Phoenix.HTML.Safe.to_iodata()
|
||||||
|
|
||||||
|
{:safe, [safe_k, ?=, ?", safe_v, ?"]}
|
||||||
|
end
|
||||||
|
|
||||||
{:safe, [unquote(head), Phoenix.HTML.Safe.to_iodata(attrs), unquote(tail)]}
|
{:safe, [unquote(head), Phoenix.HTML.Safe.to_iodata(attrs), unquote(tail)]}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,15 @@ defmodule HeroiconsTest do
|
|||||||
|
|
||||||
assert Heroicons.Outline.academic_cap(class: "<> \" ")
|
assert Heroicons.Outline.academic_cap(class: "<> \" ")
|
||||||
|> Phoenix.HTML.safe_to_string() =~
|
|> Phoenix.HTML.safe_to_string() =~
|
||||||
~s(class="<> ")
|
~s(class="<> " ")
|
||||||
|
|
||||||
|
assert Heroicons.Outline.academic_cap(foo: "bar")
|
||||||
|
|> Phoenix.HTML.safe_to_string() =~
|
||||||
|
~s(foo="bar")
|
||||||
|
|
||||||
|
assert Heroicons.Outline.academic_cap(multiword_key: "foo")
|
||||||
|
|> Phoenix.HTML.safe_to_string() =~
|
||||||
|
~s(multiword-key="foo")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "generated docs" do
|
test "generated docs" do
|
||||||
|
Reference in New Issue
Block a user