tailwindcss-formatter 0.1.0 → 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 +4 -4
- data/README.md +39 -12
- data/lib/tailwindcss/formatter/class_sorter.rb +44 -15
- data/lib/tailwindcss/formatter/constants.rb +3 -3
- data/lib/tailwindcss/formatter/version.rb +1 -1
- data/tailwindcss-formatter.gemspec +6 -3
- metadata +7 -4
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
|
data/README.md
CHANGED
@@ -1,35 +1,62 @@
|
|
1
1
|
# Tailwindcss::Formatter
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
This Ruby Gem provides a CLI interface for effortlessly organising and formating Tailwind
|
4
|
+
CSS class declarations in your HTML and ERB templates, following the recommended class
|
5
|
+
order for cleaner and more maintainable code.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
Install the gem and add to the application's Gemfile by executing:
|
9
|
+
Install the gem and add it to the application's Gemfile by executing:
|
12
10
|
|
13
11
|
```bash
|
14
|
-
bundle add
|
12
|
+
bundle add tailwindcss-formatter
|
15
13
|
```
|
16
14
|
|
17
15
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
18
16
|
|
19
17
|
```bash
|
20
|
-
gem install
|
18
|
+
gem install tailwindcss-formatter
|
21
19
|
```
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
Once installed, you can run the formatter from the CLI to format your files. It runs
|
24
|
+
in dry mode by default, so you will need to specify the `-w | --write` flag to have the
|
25
|
+
modifications written back to the files in place.
|
26
|
+
|
27
|
+
It takes a glob or file path as the first argument. If you leave this empty, it will
|
28
|
+
use the default, which is set up for a typical Rails project: `"app/**/*.html.erb"`.
|
29
|
+
|
30
|
+
Example with glob pattern to match files:
|
31
|
+
|
32
|
+
```bash
|
33
|
+
tailwindcss-format "app/**/*.html.erb"
|
34
|
+
```
|
35
|
+
|
36
|
+
Example passing the `--write` flag so the formatting is written to the files in place:
|
37
|
+
|
38
|
+
```bash
|
39
|
+
tailwindcss-format "app/**/*.html.erb" -w
|
40
|
+
```
|
41
|
+
|
42
|
+
### Flags
|
43
|
+
|
44
|
+
`-w | --write` Writes the formatted class strings back to the file in place.
|
45
|
+
|
46
|
+
`-c | --check-formatted` Raises exit code 1 if unformatted class declarations are detected.
|
26
47
|
|
27
48
|
## Development
|
28
49
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec`
|
50
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec`
|
51
|
+
to run the tests. You can also run `bin/console` for an interactive prompt that will allow
|
52
|
+
you to experiment.
|
30
53
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a
|
54
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a
|
55
|
+
new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
|
56
|
+
which will create a git tag for the version, push git commits and the created tag, and push
|
57
|
+
the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
58
|
|
33
59
|
## Contributing
|
34
60
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at
|
61
|
+
Bug reports and pull requests are welcome on GitHub at
|
62
|
+
https://github.com/benbarber/tailwindcss-formatter.
|
@@ -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
|
@@ -5,12 +5,15 @@ require_relative "lib/tailwindcss/formatter/version"
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "tailwindcss-formatter"
|
7
7
|
spec.version = Tailwindcss::Formatter::VERSION
|
8
|
+
spec.required_ruby_version = ">= 3.0.0"
|
9
|
+
spec.licenses = %w[MIT]
|
10
|
+
|
8
11
|
spec.authors = ["Ben Barber"]
|
9
12
|
spec.email = ["contact@benbarber.co.uk"]
|
10
|
-
|
11
|
-
spec.summary = "Format and sort Tailwind CSS classes based on the recommended class order."
|
12
13
|
spec.homepage = "https://github.com/benbarber/tailwindcss-formatter#readme"
|
13
|
-
|
14
|
+
|
15
|
+
spec.summary = "Effortlessly organize and format Tailwind CSS class declarations in your HTML and ERB
|
16
|
+
templates, following the recommended class order for cleaner and more maintainable code."
|
14
17
|
|
15
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
16
19
|
spec.metadata["source_code_uri"] = "https://github.com/benbarber/tailwindcss-formatter"
|
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:
|
@@ -26,7 +26,8 @@ files:
|
|
26
26
|
- lib/tailwindcss/formatter/version.rb
|
27
27
|
- tailwindcss-formatter.gemspec
|
28
28
|
homepage: https://github.com/benbarber/tailwindcss-formatter#readme
|
29
|
-
licenses:
|
29
|
+
licenses:
|
30
|
+
- MIT
|
30
31
|
metadata:
|
31
32
|
homepage_uri: https://github.com/benbarber/tailwindcss-formatter#readme
|
32
33
|
source_code_uri: https://github.com/benbarber/tailwindcss-formatter
|
@@ -50,5 +51,7 @@ requirements: []
|
|
50
51
|
rubygems_version: 3.5.21
|
51
52
|
signing_key:
|
52
53
|
specification_version: 4
|
53
|
-
summary:
|
54
|
+
summary: Effortlessly organize and format Tailwind CSS class declarations in your
|
55
|
+
HTML and ERB templates, following the recommended class order for cleaner and more
|
56
|
+
maintainable code.
|
54
57
|
test_files: []
|