Skip to content

Commit

Permalink
handle local and remote components (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
goodtouch authored Mar 4, 2024
1 parent 9d45814 commit 3896f73
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/tailwind_formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ defmodule TailwindFormatter do
contents
|> HEExTokenizer.tokenize()
|> Enum.reduce([contents], fn
{:tag, _name, attrs, _meta}, contents ->
{elt, _name, attrs, _meta}, contents
when elt in [:tag, :local_component, :remote_component] ->
Enum.reduce(attrs, contents, fn
{"class", class_attr, _meta}, [remainder | acc] ->
[attr, remainder] = String.split(remainder, old_classes(class_attr), parts: 2)
Expand Down
24 changes: 24 additions & 0 deletions test/tailwind_formatter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,28 @@ defmodule TailwindFormatterTest do

assert_formatter_output(input, expected)
end

test "handles local components" do
input = """
<.img class="text-sm potato sm:lowercase uppercase" />
"""

expected = """
<.img class="potato text-sm uppercase sm:lowercase" />
"""

assert_formatter_output(input, expected)
end

test "handles remote components" do
input = """
<CP.img class="text-sm potato sm:lowercase uppercase" />
"""

expected = """
<CP.img class="potato text-sm uppercase sm:lowercase" />
"""

assert_formatter_output(input, expected)
end
end

0 comments on commit 3896f73

Please sign in to comment.