tailwindcss-formatter 0.1.0
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 +7 -0
- data/README.md +35 -0
- data/exe/tailwindcss-format +7 -0
- data/lib/tailwindcss/formatter/class_sorter.rb +63 -0
- data/lib/tailwindcss/formatter/constants.rb +4964 -0
- data/lib/tailwindcss/formatter/version.rb +7 -0
- data/lib/tailwindcss/formatter.rb +79 -0
- data/tailwindcss-formatter.gemspec +37 -0
- metadata +54 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
|
5
|
+
require_relative "formatter/version"
|
6
|
+
require_relative "formatter/class_sorter"
|
7
|
+
|
8
|
+
module Tailwindcss
|
9
|
+
module Formatter
|
10
|
+
# This class handles the command-line interface (CLI) for the TailwindCSS formatter.
|
11
|
+
# It processes command-line arguments and passes them to the ClassSorter
|
12
|
+
class CLI
|
13
|
+
def self.start(argv)
|
14
|
+
options = parse_options(argv)
|
15
|
+
files = find_files(options[:glob])
|
16
|
+
process_files(files, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.parse_options(argv)
|
20
|
+
options = { glob: "app/**/*.html.erb", check_formatted: false, write: false }
|
21
|
+
|
22
|
+
# Check if the first argument is a glob pattern (positional argument)
|
23
|
+
options[:glob] = argv.shift if argv.any? && !argv.first.start_with?("-")
|
24
|
+
|
25
|
+
option_parser(options).parse!(argv)
|
26
|
+
options
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.option_parser(options)
|
30
|
+
OptionParser.new do |opts|
|
31
|
+
opts.banner = "Usage: tailwindcss-formatter [options]\n
|
32
|
+
Example: tailwindcss-formatter \"app/**/*.html.erb\""
|
33
|
+
|
34
|
+
add_glob_option(opts, options)
|
35
|
+
add_write_option(opts, options)
|
36
|
+
add_check_formatted_option(opts, options)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.add_glob_option(opts, options)
|
41
|
+
opts.on("-g", "--glob GLOB", "Glob path to match files (default: \"app/**/*.html.erb\")") do |glob|
|
42
|
+
options[:glob] = glob
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.add_write_option(opts, options)
|
47
|
+
opts.on("-w", "--write [FLAG]", TrueClass, "Write any formatting back to the files (default: false)") do
|
48
|
+
options[:write] = true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.add_check_formatted_option(opts, options)
|
53
|
+
opts.on("-c", "--check-formatted [FLAG]", TrueClass,
|
54
|
+
"Raises exit 1 if unformatted class strings are detected (default: false)") do
|
55
|
+
options[:check_formatted] = true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.find_files(glob)
|
60
|
+
files = Dir.glob(glob)
|
61
|
+
|
62
|
+
if files.empty?
|
63
|
+
puts "No files matched the glob pattern: #{glob}"
|
64
|
+
exit 1
|
65
|
+
end
|
66
|
+
|
67
|
+
files
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.process_files(files, options)
|
71
|
+
class_sorter = ClassSorter.new(check_formatted: options[:check_formatted], write: options[:write])
|
72
|
+
|
73
|
+
files.each do |file|
|
74
|
+
class_sorter.process_file(file)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/tailwindcss/formatter/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "tailwindcss-formatter"
|
7
|
+
spec.version = Tailwindcss::Formatter::VERSION
|
8
|
+
spec.authors = ["Ben Barber"]
|
9
|
+
spec.email = ["contact@benbarber.co.uk"]
|
10
|
+
|
11
|
+
spec.summary = "Format and sort Tailwind CSS classes based on the recommended class order."
|
12
|
+
spec.homepage = "https://github.com/benbarber/tailwindcss-formatter#readme"
|
13
|
+
spec.required_ruby_version = ">= 3.0.0"
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/benbarber/tailwindcss-formatter"
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/benbarber/tailwindcss-formatter/#changelog"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
File.basename(__FILE__)
|
22
|
+
spec.files = Dir["lib/**/*", "exe/**/*", "*.gemspec", "README.md", "LICENSE"]
|
23
|
+
|
24
|
+
# Specify the path for the executable
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = ["tailwindcss-format"]
|
27
|
+
|
28
|
+
# Add the lib directory to the load path
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Uncomment to register a new dependency of your gem
|
32
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
33
|
+
|
34
|
+
# For more information and examples about making a new gem, check out our
|
35
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tailwindcss-formatter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Barber
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- contact@benbarber.co.uk
|
16
|
+
executables:
|
17
|
+
- tailwindcss-format
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- README.md
|
22
|
+
- exe/tailwindcss-format
|
23
|
+
- lib/tailwindcss/formatter.rb
|
24
|
+
- lib/tailwindcss/formatter/class_sorter.rb
|
25
|
+
- lib/tailwindcss/formatter/constants.rb
|
26
|
+
- lib/tailwindcss/formatter/version.rb
|
27
|
+
- tailwindcss-formatter.gemspec
|
28
|
+
homepage: https://github.com/benbarber/tailwindcss-formatter#readme
|
29
|
+
licenses: []
|
30
|
+
metadata:
|
31
|
+
homepage_uri: https://github.com/benbarber/tailwindcss-formatter#readme
|
32
|
+
source_code_uri: https://github.com/benbarber/tailwindcss-formatter
|
33
|
+
changelog_uri: https://github.com/benbarber/tailwindcss-formatter/#changelog
|
34
|
+
rubygems_mfa_required: 'true'
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 3.0.0
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubygems_version: 3.5.21
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: Format and sort Tailwind CSS classes based on the recommended class order.
|
54
|
+
test_files: []
|