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: 8b0a52e913a5ea017ecb958467341b07eb9079b113ecc611d0d531a97a786ce2
4
- data.tar.gz: 877921beb5246aea9a80c7b3b9fc47c561f86d3dfb8e6280f75e73ed29475e50
3
+ metadata.gz: f6c8cd02e4f4b52fd2a85a19148d5b28c2e8055b3c851d0547025886baf5dbe7
4
+ data.tar.gz: 672f2cc8364a601d5841acf22bd756a6ad5d668f1b132ab80679eb09a72e443a
5
5
  SHA512:
6
- metadata.gz: b009acc4da9a0b0c6012c992b59a0657670dd26533667eb6d4fe727fe2cda1f219f5cb2be6ac3fdc2eb4fcb89de59cc049edd6a98d99d903cf255d962176ebdf
7
- data.tar.gz: 15ebf800ea4c9a97dc49a04c2e360dd342dfe4a1d784bed3adb0ff3944bd420e26e2e2f149e52db057c1024f3eaf55c623b1e6d637a1698a386429a12021f9d2
6
+ metadata.gz: c56a232c431873d2453d2c96ed109208487b9df0936062d8463512ba735f079fc9dec77fb2b6bd22bba42568d2d569390906ca9b36aff43f5c502dcb77d76e36
7
+ data.tar.gz: fa64b62e76a020cf5b13ce6ebf24808e7a7606dfa0275f559b73561d73b53f88bd9cddcd24dc7a630e484831865c7a6b07e1bd6705fdea8cdd4ee878df41e72b
@@ -32,32 +32,61 @@ module Tailwindcss
32
32
  end
33
33
  end
34
34
 
35
- private
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
- def format_content(content)
38
- CLASS_REGEX_PATTERNS.each do |_regex|
39
- content = content.gsub(_regex[:pattern]) do |_match|
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
- content
45
- end
45
+ # Split the remaing class_string by whitespace
46
+ class_list += class_string.split(/\s+/)
46
47
 
47
- def sorted_class_string(class_string)
48
- class_list = class_string.split(/\s+/)
49
- sorted_list = class_list.sort_by do |class_name|
50
- order_index = CLASS_ORDER.index(class_name)
51
- order_index.nil? ? [1, class_name] : [0, order_index]
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
- sorted_list.join(" ")
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="\s*([^"]*)"/, prefix: "class=" },
7
- { pattern: /className="\s*([^"]*)"/, prefix: "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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tailwindcss
4
4
  module Formatter
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
@@ -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(MIT)
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.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-15 00:00:00.000000000 Z
11
+ date: 2024-10-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: