Skip to content

Commit

Permalink
Don't depend on Phoenix.HTML.Tag.content_tag in Showcase
Browse files Browse the repository at this point in the history
  • Loading branch information
angelikatyborska committed Jul 16, 2024
1 parent e9d7e9b commit f78b906
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/bitstyles_phoenix/showcase.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
defmodule BitstylesPhoenix.Showcase do
@moduledoc false

import Phoenix.HTML, only: [safe_to_string: 1]
import Phoenix.HTML.Tag, only: [content_tag: 3]
import Phoenix.HTML, only: [safe_to_string: 1, attributes_escape: 1, html_escape: 1]

defmacro story(name, doctest_iex_code, doctest_expected_results, opts \\ []) do
default_version = BitstylesPhoenix.Bitstyles.default_version() |> String.to_atom()
Expand Down Expand Up @@ -154,4 +153,13 @@ defmodule BitstylesPhoenix.Showcase do
"""
end
end

# copy-paste from phoenix_html_helpers because `content_tag` was removed in phoenix_html v4
# and we don't want to depend on phoenix_html_helpers
defp content_tag(name, content, attrs) when is_list(attrs) do
name = to_string(name)
{:safe, escaped} = html_escape(content)
sorted_attrs = attrs |> Enum.sort() |> attributes_escape() |> elem(1)
{:safe, [?<, name, sorted_attrs, ?>, escaped, ?<, ?/, name, ?>]}
end
end

0 comments on commit f78b906

Please sign in to comment.