Skip to content

Commit dcf1d05

Browse files
author
Wolfram Nikolas Müller
committed
add tests for slim syntax
1 parent 0129f90 commit dcf1d05

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

test/fixtures/placeholders.html.slim

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
input.placeholder-transparent.focus-within:outline-black

test/fixtures/show.html.slim

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
.py-12.bg-white.translate-x-1/2 class="my-1.5 sm:py-0.5"
2+
.max-w-7xl.mx-auto.px-4.sm:px-6.lg:px-8
3+
.lg:text-center
4+
h2.text-base.text-indigo-600.font-semibold.tracking-wide.uppercase
5+
| Transactions
6+
p.mt-2.text-3xl.leading-8.font-extrabold.tracking-tight.text-gray-900.sm:text-4xl
7+
| A better way to send money
8+
p.mt-4.max-w-2xl.text-xl.text-gray-500.lg:mx-auto
9+
| Lorem ipsum dolor sit amet consect adipisicing elit. Possimus magnam voluptatum cupiditate veritatis in accusamus quisquam.
10+
.mt-10
11+
dl.space-y-10.md:space-y-0.md:grid.md:grid-cols-2.md:gap-x-8.md:gap-y-10
12+
13+
.flex
14+
.flex-shrink-0
15+
.flex.items-center.justify-center.h-12.w-12.rounded-md.bg-blue-500.text-white
16+
svg.h-6.w-6[xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 24 24" stroke="currentColor" aria-hidden="true"]
17+
path[stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"]
18+
.ml-4
19+
dt.text-lg.leading-6.font-medium.text-gray-900
20+
| Competitive exchange rates
21+
dd.mt-2.text-base.text-gray-500
22+
| Lorem ipsum, dolor sit amet consectetur adipisicing elit. Maiores impedit perferendis suscipit eaque, iste dolor cupiditate blanditiis ratione.
23+
.flex
24+
.flex-shrink-0
25+
.flex.items-center.justify-center.h-12.w-12.rounded-md.bg-indigo-500.text-white
26+
svg.h-6.w-6[xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 24 24" stroke="currentColor" aria-hidden="true"]
27+
path[stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 6l3 1m0 0l-3 9a5.002 5.002 0 006.001 0M6 7l3 9M6 7l6-2m6 2l3-1m-3 1l-3 9a5.002 5.002 0 006.001 0M18 7l3 9m-3-9l-6-2m0-2v2m0 16V5m0 16H9m3 0h3"]
28+
.ml-4
29+
dt.text-lg.leading-6.font-medium.text-gray-900
30+
| No hidden fees
31+
dd.mt-2.text-base.text-gray-500
32+
| Lorem ipsum, dolor sit amet consectetur adipisicing elit. Maiores impedit perferendis suscipit eaque, iste dolor cupiditate blanditiis ratione.
33+
.flex
34+
.flex-shrink-0
35+
.flex.items-center.justify-center.h-12.w-12.rounded-md.bg-indigo-500.text-white
36+
svg.h-6.w-6[xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 24 24" stroke="currentColor" aria-hidden="true"]
37+
path[stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"]
38+
.ml-4
39+
dt.text-lg.leading-6.font-medium.text-gray-900
40+
| Transfers are instant
41+
dd.mt-2.text-base.text-gray-500
42+
| Lorem ipsum, dolor sit amet consectetur adipisicing elit. Maiores impedit perferendis suscipit eaque, iste dolor cupiditate blanditiis ratione.
43+
.flex
44+
.flex-shrink-0
45+
.flex.items-center.justify-center.h-12.w-12.rounded-md.bg-indigo-500.text-white
46+
svg.h-6.w-6[xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 24 24" stroke="currentColor" aria-hidden="true"]
47+
path[stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"]
48+
.ml-4
49+
dt.text-lg.leading-6.font-medium.text-gray-900
50+
| Mobile notifications
51+
dd.mt-2.text-base.text-gray-500
52+
| Lorem ipsum, dolor sit amet consectetur adipisicing elit. Maiores impedit perferendis suscipit eaque, iste dolor cupiditate blanditiis ratione.
53+
.relative.bg-white.overflow-hidden
54+
.max-w-7xl.mx-auto
55+
.relative.z-10.pb-8.bg-white.sm:pb-16.md:pb-20.lg:max-w-2xl.lg:w-full.lg:pb-28.xl:pb-32
56+
svg.hidden.lg:block.absolute.right-0.inset-y-0.h-full.w-48.text-white.transform.translate-x-1/2[fill="currentColor" viewbox="0 0 100 100" preserveaspectratio="none" aria-hidden="true"]
57+
polygon[points="50,0 100,0 50,100 0,100"]
58+
.relative.pt-6.px-4.sm:px-6.lg:px-8
59+
nav.relative.flex.items-center.justify-between.sm:h-10.lg:justify-start[aria-label="Global"]
60+
.flex.items-center.flex-grow.flex-shrink-0.lg:flex-grow-0
61+
.flex.items-center.justify-between.w-full.md:w-auto
62+
a[href="#"]
63+
span.sr-only
64+
| Workflow
65+
img.h-8.w-auto.sm:h-10[src="https://tailwindui.com/img/logos/workflow-mark-indigo-600.svg"]
66+
.-mr-2.flex.items-center.md:hidden
67+
button#main-menu.bg-white.rounded-md.p-2.inline-flex.items-center.justify-center.text-gray-400.hover:text-gray-500.hover:bg-gray-100.focus:outline-none.focus:ring-2.focus:ring-inset.focus:ring-indigo-500[type="button" aria-haspopup="true"]
68+
span.sr-only
69+
| Open main menu
70+
svg.h-6.w-6[xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 24 24" stroke="currentColor" aria-hidden="true"]
71+
path[stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"]
72+
.hidden.md:block.md:ml-10.md:pr-4.md:space-x-8
73+
a.font-medium.text-gray-500.hover:text-gray-900[href="#"]
74+
| Product
75+
a.font-medium.text-gray-500.hover:text-gray-900[href="#"]
76+
| Features
77+
a.font-medium.text-gray-500.hover:text-gray-900[href="#"]
78+
| Marketplace
79+
a.font-medium.text-gray-500.hover:text-gray-900[href="#"]
80+
| Company
81+
a.font-medium.text-indigo-600.hover:text-indigo-500[href="#"]
82+
| Log in
83+
.absolute.top-0.inset-x-0.p-2.transition.transform.origin-top-right.md:hidden
84+
.rounded-lg.shadow-md.bg-white.ring-1.ring-black.ring-opacity-5.overflow-hidden
85+
.px-5.pt-4.flex.items-center.justify-between
86+
div
87+
img.h-8.w-auto[src="https://tailwindui.com/img/logos/workflow-mark-indigo-600.svg" alt=""]
88+
.-mr-2
89+
button.bg-white.rounded-md.p-2.inline-flex.items-center.justify-center.text-gray-400.hover:text-gray-500.hover:bg-gray-100.focus:outline-none.focus:ring-2.focus:ring-inset.focus:ring-indigo-500[type="button"]
90+
span.sr-only
91+
| Close main menu
92+
svg.h-6.w-6[xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 24 24" stroke="currentColor" aria-hidden="true"]
93+
path[stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"]
94+
div[role="menu" aria-orientation="vertical" aria-labelledby="main-menu"]
95+
.px-2.pt-2.pb-3.space-y-1[role="none"]
96+
a.block.px-3.py-2.rounded-md.text-base.font-medium.text-gray-700.hover:text-gray-900.hover:bg-gray-50[href="#" role="menuitem"]
97+
| Product
98+
a.block.px-3.py-2.rounded-md.text-base.font-medium.text-gray-700.hover:text-gray-900.hover:bg-gray-50[href="#" role="menuitem"]
99+
| Features
100+
a.block.px-3.py-2.rounded-md.text-base.font-medium.text-gray-700.hover:text-gray-900.hover:bg-gray-50[href="#" role="menuitem"]
101+
| Marketplace
102+
a.block.px-3.py-2.rounded-md.text-base.font-medium.text-gray-700.hover:text-gray-900.hover:bg-gray-50[href="#" role="menuitem"]
103+
| Company
104+
div[role="none"]
105+
a.block.w-full.px-5.py-3.text-center.font-medium.text-indigo-600.bg-gray-50.hover:bg-gray-100[href="#" role="menuitem"]
106+
| Log in
107+
main.mt-10.mx-auto.max-w-7xl.px-4.sm:mt-12.sm:px-6.md:mt-16.lg:mt-20.lg:px-8.xl:mt-28
108+
.sm:text-center.lg:text-left
109+
h1.text-4xl.tracking-tight.font-extrabold.text-gray-900.sm:text-5xl.md:text-6xl
110+
span.block.xl:inline
111+
| Data to enrich your
112+
span.block.text-indigo-600.xl:inline
113+
| online business
114+
p.mt-3.text-base.text-gray-500.sm:mt-5.sm:text-lg.sm:max-w-xl.sm:mx-auto.md:mt-5.md:text-xl.lg:mx-0
115+
| Anim aute id magna aliqua ad ad non deserunt sunt. Qui irure qui lorem cupidatat commodo. Elit sunt amet fugiat veniam occaecat fugiat aliqua.
116+
.mt-5.sm:mt-8.sm:flex.sm:justify-center.lg:justify-start
117+
.rounded-md.shadow
118+
a.w-full.flex.items-center.justify-center.px-8.py-3.border.border-transparent.text-base.font-medium.rounded-md.text-white.bg-indigo-600.hover:bg-indigo-700.md:py-4.md:text-lg.md:px-10[href="#"]
119+
| Get started
120+
.mt-3.sm:mt-0.sm:ml-3
121+
a.w-full.flex.items-center.justify-center.px-8.py-3.border.border-transparent.text-base.font-medium.rounded-md.text-indigo-700.bg-indigo-100.hover:bg-indigo-200.md:py-4.md:text-lg.md:px-10[href="#"]
122+
| Live demo
123+
.lg:absolute.lg:inset-y-0.lg:right-0.lg:w-1/2
124+
img.h-56.w-full.object-cover.sm:h-72.md:h-96.lg:w-full.lg:h-full[src="https://images.unsplash.com/photo-1551434678-e076c223a692?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2850&q=80" alt=""]

test/fixtures/simple.html.slim

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.max-w-7xl.mx-auto.px-4.sm:px-6.lg:px-8.translate-x-1/2 class="my-1.5 sm:py-0.5"

test/purger_test.rb

+27
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ class Tailwindcss::PurgerTest < ActiveSupport::TestCase
2121
Tailwindcss::Purger.extract_class_names_from(Pathname.new(__dir__).join("fixtures/simple.html.haml"))
2222
end
2323

24+
test "extract class names from slim string" do
25+
assert_equal %w[ class max-w-7xl mx-auto my-1.5 px-4 sm:px-6 lg:px-8 sm:py-0.5 translate-x-1/2 ].sort,
26+
Tailwindcss::Purger.extract_class_names(%(.max-w-7xl.mx-auto.px-4.sm:px-6.lg:px-8.translate-x-1/2 class="my-1.5 sm:py-0.5"))
27+
end
28+
29+
test "extract class names from slim file" do
30+
assert_equal %w[ class max-w-7xl mx-auto my-1.5 px-4 sm:px-6 lg:px-8 sm:py-0.5 translate-x-1/2 ].sort,
31+
Tailwindcss::Purger.extract_class_names_from(Pathname.new(__dir__).join("fixtures/simple.html.slim"))
32+
end
33+
2434
test "basic purge" do
2535
purged = purged_tailwind_from_erb_fixtures
2636

@@ -47,6 +57,19 @@ class Tailwindcss::PurgerTest < ActiveSupport::TestCase
4757
assert purged =~ /.sm\\:py-0\\.5 \{/
4858
end
4959

60+
test "basic slim purge" do
61+
purged = purged_tailwind_from_slim_fixtures
62+
63+
assert purged !~ /.mt-6 \{/
64+
65+
assert purged =~ /.mt-5 \{/
66+
assert purged =~ /.sm\\:px-6 \{/
67+
assert purged =~ /.translate-x-1\\\/2 \{/
68+
assert purged =~ /.mt-10 \{/
69+
assert purged =~ /.my-1\\.5 \{/
70+
assert purged =~ /.sm\\:py-0\\.5 \{/
71+
end
72+
5073
test "purge handles class names that begin with a number" do
5174
purged = purged_tailwind(keep_these_class_names: %w[32xl:container])
5275

@@ -173,6 +196,10 @@ def purged_tailwind_from_haml_fixtures
173196
$purged_tailwind_from_haml_fixtures ||= purged_tailwind_from Pathname(__dir__).glob("fixtures/*.html.haml")
174197
end
175198

199+
def purged_tailwind_from_slim_fixtures
200+
$purged_tailwind_from_haml_fixtures ||= purged_tailwind_from Pathname(__dir__).glob("fixtures/*.html.slim")
201+
end
202+
176203
def purged_tailwind_from files
177204
Tailwindcss::Purger.purge tailwind, keeping_class_names_from_files: files
178205
end

0 commit comments

Comments
 (0)