tailwindcss-formatter 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6c8cd02e4f4b52fd2a85a19148d5b28c2e8055b3c851d0547025886baf5dbe7
|
4
|
+
data.tar.gz: 672f2cc8364a601d5841acf22bd756a6ad5d668f1b132ab80679eb09a72e443a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c56a232c431873d2453d2c96ed109208487b9df0936062d8463512ba735f079fc9dec77fb2b6bd22bba42568d2d569390906ca9b36aff43f5c502dcb77d76e36
|
7
|
+
data.tar.gz: fa64b62e76a020cf5b13ce6ebf24808e7a7606dfa0275f559b73561d73b53f88bd9cddcd24dc7a630e484831865c7a6b07e1bd6705fdea8cdd4ee878df41e72b
|
@@ -32,32 +32,61 @@ module Tailwindcss
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
def sorted_class_string(str)
|
36
|
+
class_string = str.dup
|
37
|
+
class_list = []
|
38
|
+
template_tags = extract_template_tags(class_string)
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
"#{_regex[:prefix]}\"#{sorted_class_string(Regexp.last_match(1))}\""
|
41
|
-
end
|
40
|
+
# Remove the found template tags from the class_string
|
41
|
+
template_tags.each do |tag|
|
42
|
+
class_string.gsub!(tag, "")
|
42
43
|
end
|
43
44
|
|
44
|
-
|
45
|
-
|
45
|
+
# Split the remaing class_string by whitespace
|
46
|
+
class_list += class_string.split(/\s+/)
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
48
|
+
# Sort the class_list
|
49
|
+
sorted_class_list = sort_class_list(class_list)
|
50
|
+
|
51
|
+
# Add the filtered template tags back to the sorted class list
|
52
|
+
sorted_class_list += template_tags
|
53
53
|
|
54
|
-
|
54
|
+
# Join and return the sorted class list as a formatted class_string
|
55
|
+
sorted_class_list.join(" ")
|
55
56
|
end
|
56
57
|
|
57
58
|
def fail_format_check
|
58
59
|
puts "Check format failure - exited with error code 1"
|
59
60
|
exit(1)
|
60
61
|
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def extract_template_tags(class_string)
|
66
|
+
template_tags = []
|
67
|
+
|
68
|
+
# Check for ERB template tags
|
69
|
+
template_tags += class_string.scan(/<%.*?%>/)
|
70
|
+
|
71
|
+
template_tags
|
72
|
+
end
|
73
|
+
|
74
|
+
def sort_class_list(class_list)
|
75
|
+
class_list.sort_by do |class_name|
|
76
|
+
order_index = CLASS_ORDER.index(class_name)
|
77
|
+
order_index.nil? ? [1, class_name] : [0, order_index]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def format_content(content)
|
82
|
+
CLASS_REGEX_PATTERNS.each do |regex|
|
83
|
+
content = content.gsub(regex[:pattern]) do |_match|
|
84
|
+
"#{regex[:prefix]}\"#{sorted_class_string(Regexp.last_match(1))}\""
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
content
|
89
|
+
end
|
61
90
|
end
|
62
91
|
end
|
63
92
|
end
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
# Regex patterns to get the class strings for formatting
|
4
4
|
CLASS_REGEX_PATTERNS = [
|
5
|
-
{ pattern: /class:\s*"([^"]*)"/, prefix: "class: " },
|
6
|
-
{ pattern: /class
|
7
|
-
{ pattern: /className
|
5
|
+
{ pattern: /class:\s*["]([^"]*)["]/, prefix: "class: " },
|
6
|
+
{ pattern: /class=\s*["]([^"]*)["]/, prefix: "class=" },
|
7
|
+
{ pattern: /className=\s*["]([^"]*)["]/, prefix: "className=" }
|
8
8
|
].freeze
|
9
9
|
|
10
10
|
# Default sorting order for Tailwind classes
|
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = "tailwindcss-formatter"
|
7
7
|
spec.version = Tailwindcss::Formatter::VERSION
|
8
8
|
spec.required_ruby_version = ">= 3.0.0"
|
9
|
-
spec.licenses = %w
|
9
|
+
spec.licenses = %w[MIT]
|
10
10
|
|
11
11
|
spec.authors = ["Ben Barber"]
|
12
12
|
spec.email = ["contact@benbarber.co.uk"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tailwindcss-formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Barber
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|