Skip to content

Commit b3513d4

Browse files
committed
Added support for TailwindCSS 1.3
Refactored PHP class extractor Classes are now sorted alphabetically
1 parent 30be9e3 commit b3513d4

File tree

4 files changed

+17057
-13152
lines changed

4 files changed

+17057
-13152
lines changed

extractClassNames.php

Lines changed: 66 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,88 @@
11
<?php
22

3-
// Grab contents of css file
4-
// $file = file_get_contents('tailwind.css');
5-
$file = file_get_contents('tailwind-ui.css');
3+
// Get latest versions of these two files from
4+
// https://unpkg.com/tailwindcss@%5E1.0/dist/tailwind.css
5+
// https://cdn.jsdelivr.net/npm/@tailwindcss/ui@latest/dist/tailwind-ui.css
66

7-
// Strip comments
8-
$pattern = '!/\*[^*]*\*+([^/][^*]*\*+)*/!';
9-
$stripped = preg_replace($pattern, '', $file);
7+
$classes['tailwind.css'] = extractClasses(file_get_contents('tailwind.css'));
8+
$classes['tailwind-ui.css'] = extractClasses(file_get_contents('tailwind-ui.css'));
109

11-
// Strip out everything between { and }
12-
$pattern = '/(?<=\{)(.*?)(?=\})/s';
13-
$stripped = preg_replace($pattern, '', $stripped);
10+
function extractClasses($file)
11+
{
12+
// Strip comments
13+
$pattern = '!/\*[^*]*\*+([^/][^*]*\*+)*/!';
14+
$stripped = preg_replace($pattern, '', $file);
1415

15-
// Remove double line breaks
16-
$stripped = str_replace("\n\n", "\n", $stripped);
16+
// Strip out everything between { and }
17+
$pattern = '/(?<=\{)(.*?)(?=\})/s';
18+
$stripped = preg_replace($pattern, '', $stripped);
1719

18-
// Convert every line to array
19-
$classes = explode("\n", $stripped);
20+
// Remove double line breaks
21+
$stripped = str_replace("\n\n", "\n", $stripped);
2022

21-
$keepers = [];
23+
// Convert every line to array
24+
$classes = explode("\n", $stripped);
2225

23-
for ($i = 0; $i < count($classes); $i++) {
24-
$match = trim($classes[$i]);
26+
$keepers = [];
2527

26-
$match = stripslashes($match);
28+
for ($i = 0; $i < count($classes); $i++) {
29+
$match = trim($classes[$i]);
2730

28-
$excludeThesePrefixes = [
29-
'.sm:',
30-
'.md:',
31-
'.lg:',
32-
'.xl:',
31+
$match = stripslashes($match);
3332

34-
'.form',
33+
$excludeThesePrefixes = [
34+
'.sm:',
35+
'.md:',
36+
'.lg:',
37+
'.xl:',
3538

36-
'.group:hover',
37-
'.group:focus',
38-
];
39+
'.form',
3940

40-
if (substr($match, 0, 1) !== '.') {
41-
continue;
42-
}
41+
'.group:hover',
42+
'.group:focus',
43+
];
4344

44-
foreach ($excludeThesePrefixes as $exclude) {
45-
if (strpos($match, $exclude) === 0) {
46-
continue 2;
45+
if (substr($match, 0, 1) !== '.') {
46+
continue;
47+
}
48+
49+
foreach ($excludeThesePrefixes as $exclude) {
50+
if (strpos($match, $exclude) === 0) {
51+
continue 2;
52+
}
4753
}
48-
}
4954

50-
$stripThese = [
51-
'.',
52-
' {}',
53-
':focus:-ms-input-placeholder',
54-
':focus::-ms-input-placeholder',
55-
':focus::placeholder',
56-
'::placeholder',
57-
'::-ms-input-placeholder',
58-
':-ms-input-placeholder',
59-
'::-moz-placeholder',
60-
'::-webkit-input-placeholder',
61-
':focus-within',
62-
':focus',
63-
];
64-
65-
foreach ($stripThese as $strip) {
66-
$match = str_replace($strip, '', $match);
55+
$stripThese = [
56+
'.',
57+
' {}',
58+
':focus:-ms-input-placeholder',
59+
':focus::-ms-input-placeholder',
60+
':focus::placeholder',
61+
'::placeholder',
62+
'::-ms-input-placeholder',
63+
':-ms-input-placeholder',
64+
'::-moz-placeholder',
65+
'::-webkit-input-placeholder',
66+
':focus-within',
67+
':focus',
68+
':hover',
69+
' > :not(template) ~ :not(template)',
70+
];
71+
72+
foreach ($stripThese as $strip) {
73+
$match = str_replace($strip, '', $match);
74+
}
75+
76+
$keepers[] = sprintf(' \'%s\',', $match);
6777
}
6878

69-
$keepers[] = sprintf(' \'%s\',', $match);
79+
return $keepers;
7080
}
7181

82+
$keepers = array_merge($classes['tailwind.css'], $classes['tailwind-ui.css']);
83+
84+
sort($keepers);
85+
7286
$file = '
7387
export default {
7488
data() {
@@ -81,4 +95,4 @@ classes: [
8195
};
8296
';
8397

84-
file_put_contents('tailwind-classes.js', $file);
98+
file_put_contents('src/views/tailwind-classes.js', $file);

0 commit comments

Comments
 (0)