Skip to content

Commit 79f191a

Browse files
update gem
1 parent baf9cb4 commit 79f191a

File tree

10 files changed

+304
-8
lines changed

10 files changed

+304
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,4 @@ $RECYCLE.BIN/
115115

116116
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
117117

118+
changelog-update.yml

Gemfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
source 'https://rubygems.org'
2+
13
group :development, :test do
4+
# Gems used for both development and testing
25
gem 'rspec'
6+
7+
# Test coverage tool
8+
gem 'simplecov', require: false
9+
end
10+
11+
group :development do
12+
# Ruby code linter
13+
gem 'rubocop', require: false
14+
15+
# Documentation generator
16+
gem 'yard', require: false
317
end

Gemfile.lock

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
GEM
2+
remote: https://rubygems.org/
23
specs:
4+
ast (2.4.2)
35
diff-lcs (1.5.0)
6+
docile (1.4.0)
7+
json (2.7.1)
8+
language_server-protocol (3.17.0.3)
9+
parallel (1.24.0)
10+
parser (3.2.2.4)
11+
ast (~> 2.4.1)
12+
racc
13+
racc (1.7.3)
14+
rainbow (3.1.1)
15+
regexp_parser (2.8.3)
16+
rexml (3.2.6)
417
rspec (3.12.0)
518
rspec-core (~> 3.12.0)
619
rspec-expectations (~> 3.12.0)
@@ -14,12 +27,37 @@ GEM
1427
diff-lcs (>= 1.2.0, < 2.0)
1528
rspec-support (~> 3.12.0)
1629
rspec-support (3.12.1)
30+
rubocop (1.59.0)
31+
json (~> 2.3)
32+
language_server-protocol (>= 3.17.0)
33+
parallel (~> 1.10)
34+
parser (>= 3.2.2.4)
35+
rainbow (>= 2.2.2, < 4.0)
36+
regexp_parser (>= 1.8, < 3.0)
37+
rexml (>= 3.2.5, < 4.0)
38+
rubocop-ast (>= 1.30.0, < 2.0)
39+
ruby-progressbar (~> 1.7)
40+
unicode-display_width (>= 2.4.0, < 3.0)
41+
rubocop-ast (1.30.0)
42+
parser (>= 3.2.1.0)
43+
ruby-progressbar (1.13.0)
44+
simplecov (0.22.0)
45+
docile (~> 1.1)
46+
simplecov-html (~> 0.11)
47+
simplecov_json_formatter (~> 0.1)
48+
simplecov-html (0.12.3)
49+
simplecov_json_formatter (0.1.4)
50+
unicode-display_width (2.5.0)
51+
yard (0.9.34)
1752

1853
PLATFORMS
19-
x64-mingw-ucrt
54+
x86_64-linux
2055

2156
DEPENDENCIES
2257
rspec
58+
rubocop
59+
simplecov
60+
yard
2361

2462
BUNDLED WITH
2563
2.4.22

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Distributed under the MIT License. See [LICENSE](/LICENSE) for more information.
6464

6565
## Additional Resources
6666

67+
[![Update Changelog](https://github.com/Visionary-Code-Works/HtmlScssClassChecker/actions/workflows/changelog-update.yml/badge.svg)](https://github.com/Visionary-Code-Works/HtmlScssClassChecker/actions/workflows/changelog-update.yml)
68+
6769
- [Changelog](/CHANGELOG.md): Detailed list of changes in each version.
6870
- [Code of Conduct](/CODE_OF_CONDUCT.md): Guidelines for participation in the community.
6971
- [Development Guide](/docs/development.md): Instructions for setting up a development environment and working on the gem.

Rakefile

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,44 @@
11
require "bundler/gem_tasks"
22
require "rake/testtask"
3+
require 'simplecov' # Add SimpleCov for test coverage
34

4-
# Define a task for running tests (if you're using RSpec)
5+
# Rake task for building the gem.
6+
# This task uses Bundler to build the gem based on the specifications
7+
# defined in your gemspec file.
8+
require "bundler/gem_tasks"
9+
10+
# Define a task for running tests using RSpec.
11+
# This sets up RSpec to run all spec files located in the 'spec' directory.
512
Rake::TestTask.new(:spec) do |t|
613
t.libs.push "spec"
714
t.ruby_opts = ["-W0"] # Suppresses Ruby warnings
815
t.pattern = "spec/**/*_spec.rb" # Location of spec files
16+
17+
# SimpleCov start must be at the very top to capture all files
18+
SimpleCov.start do
19+
add_filter '/spec/' # Exclude spec directory from coverage
20+
end
21+
end
22+
23+
# Task for running RuboCop for code linting
24+
desc "Run RuboCop on the lib and spec directories"
25+
task :rubocop do
26+
sh "rubocop lib spec"
927
end
1028

11-
# Set the default task to run tests
29+
# Task for generating documentation using YARD or another documentation tool
30+
desc "Generate documentation"
31+
task :document do
32+
sh "yard doc" # or replace with your preferred documentation tool
33+
end
34+
35+
# Set the default task for Rake.
36+
# When running 'rake' without arguments, it will run the 'spec' task.
1237
task default: :spec
38+
39+
# Add a task for checking test coverage after running tests
40+
desc "Run specs with coverage"
41+
task :coverage do
42+
ENV['COVERAGE'] = 'true'
43+
Rake::Task["spec"].invoke
44+
end

docs/api.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# API Documentation for HtmlScssClassChecker Gem
2+
3+
The `HtmlScssClassChecker` gem provides a Ruby API for identifying unused or unmatched HTML and SCSS classes in your web projects. This document outlines how to use the gem's API.
4+
5+
## Installation
6+
7+
Add this line to your application's Gemfile:
8+
9+
```ruby
10+
gem 'html_scss_class_checker'
11+
```
12+
13+
And then execute:
14+
15+
```bash
16+
bundle install
17+
```
18+
19+
Or install it yourself as:
20+
21+
```bash
22+
gem install html_scss_class_checker
23+
```
24+
25+
## Usage
26+
27+
### Class Extraction
28+
29+
The gem provides methods to extract class names from HTML and SCSS files.
30+
31+
#### HTML Class Extraction
32+
33+
```ruby
34+
require 'html_scss_class_checker'
35+
36+
html_content = "<div class='test-class another-class'></div>"
37+
html_classes = HtmlScssClassChecker::ClassExtractor.extract_from_html(html_content)
38+
39+
puts html_classes
40+
# Output: Set['test-class', 'another-class']
41+
```
42+
43+
#### SCSS Class Extraction
44+
45+
```ruby
46+
scss_content = ".test-class { color: red; } .another-class { color: blue; }"
47+
scss_classes = HtmlScssClassChecker::ClassExtractor.extract_from_scss(scss_content)
48+
49+
puts scss_classes
50+
# Output: Set['test-class', 'another-class']
51+
```
52+
53+
### File Processing
54+
55+
You can process individual files to list the classes used in them.
56+
57+
```ruby
58+
html_file_processor = HtmlScssClassChecker::FileProcessor.new('path/to/file.html', 'html')
59+
html_classes = html_file_processor.list_classes
60+
61+
scss_file_processor = HtmlScssClassChecker::FileProcessor.new('path/to/style.scss', 'scss')
62+
scss_classes = scss_file_processor.list_classes
63+
```
64+
65+
### Class Checking
66+
67+
The main functionality of the gem is to check for unmatched classes between HTML and SCSS files.
68+
69+
```ruby
70+
config = {
71+
'known_classes' => ['known-class1', 'known-class2'],
72+
'html_directories' => ['path/to/html/files'],
73+
'scss_directories' => ['path/to/scss/files']
74+
}
75+
76+
checker = HtmlScssClassChecker::ClassChecker.new(config)
77+
checker.check
78+
79+
puts "Unmatched Classes: #{checker.unmatched_classes.to_a}"
80+
puts "Classes in each file: #{checker.file_class_mapping}"
81+
```
82+
83+
## Configuration
84+
85+
The `ClassChecker` requires a configuration hash with the following keys:
86+
87+
- `known_classes`: An array of class names that are known and should not be reported as unmatched.
88+
- `html_directories`: An array of directories to search for HTML files.
89+
- `scss_directories`: An array of directories to search for SCSS files.
90+
91+
## Contributing
92+
93+
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given. Please see [CONTRIBUTING.md](/CONTRIBUTING.md) for details.
94+
95+
## License
96+
97+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

html_scss_class_checker.gemspec

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Gem::Specification.new do |spec|
22
spec.name = "html_scss_class_checker"
3-
spec.version = "0.1.0"
3+
spec.version = "0.2.0"
44
spec.authors = ["Thaddeus Thomas"]
5-
spec.email = ["support@vcwtech.com"]
5+
spec.email = ["thaddeus@vcwtech.com"]
66

77
spec.summary = %q{A Ruby gem for identifying unused or unmatched HTML and SCSS classes.}
88
spec.description = %q{HtmlScssClassChecker is designed to streamline the process of frontend development by scanning HTML and SCSS files and identifying classes that are either undefined or unused. This gem aims to facilitate cleaner, more maintainable, and efficient codebases by providing developers with the tools to easily audit and synchronize their HTML and SCSS class definitions. Its an essential tool for web developers looking to optimize their front-end code and ensure consistency across their stylesheets and markup.}
9-
spec.homepage = "http://example.com/gems/html_scss_class_checker"
9+
spec.homepage = "https://github.com/Visionary-Code-Works/HtmlScssClassChecker"
1010
spec.license = "MIT"
1111

1212
# Specify which files should be included in the gem
@@ -21,7 +21,11 @@ Gem::Specification.new do |spec|
2121
spec.add_runtime_dependency "json"
2222

2323
# Add development dependencies
24-
spec.add_development_dependency "bundler", "~> 2.0"
25-
spec.add_development_dependency "rake", "~> 13.0"
24+
spec.add_development_dependency "bundler"
25+
spec.add_development_dependency "rake"
26+
spec.add_development_dependency "rspec"
27+
spec.add_development_dependency "simplecov"
28+
spec.add_development_dependency "rubocop"
29+
spec.add_development_dependency "yard"
2630
# Add other development dependencies here
2731
end

spec/fixtures/html/example.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Example HTML</title>
6+
<link rel="stylesheet" href="style.css">
7+
</head>
8+
<body>
9+
<div class="header">
10+
<h1 class="title">Example Page</h1>
11+
<nav class="navigation">
12+
<ul class="nav-list">
13+
<li class="nav-item">Home</li>
14+
<li class="nav-item">About</li>
15+
<li class="nav-item">Contact</li>
16+
</ul>
17+
</nav>
18+
</div>
19+
<main class="content">
20+
<section class="intro">
21+
<p class="text">Welcome to the example page.</p>
22+
</section>
23+
<footer class="footer">
24+
<p class="footer-text">© 2023 Example Company</p>
25+
</footer>
26+
</main>
27+
</body>
28+
</html>

spec/fixtures/scss/style.scss

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Main style file
2+
3+
$header-color: #333;
4+
$nav-color: #555;
5+
$text-color: #666;
6+
$footer-color: #777;
7+
8+
.header {
9+
background-color: $header-color;
10+
11+
.title {
12+
color: white;
13+
}
14+
}
15+
16+
.navigation {
17+
background-color: $nav-color;
18+
19+
.nav-list {
20+
list-style: none;
21+
22+
.nav-item {
23+
color: $text-color;
24+
&:hover {
25+
color: darken($text-color, 10%);
26+
}
27+
}
28+
}
29+
}
30+
31+
.content {
32+
.intro {
33+
.text {
34+
color: $text-color;
35+
}
36+
}
37+
}
38+
39+
.footer {
40+
background-color: $footer-color;
41+
.footer-text {
42+
color: white;
43+
}
44+
}

spec/spec_helper.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# spec_helper.rb
2+
3+
require 'rspec'
4+
require 'set'
5+
6+
# Require the gem
7+
require 'html_scss_class_checker'
8+
9+
# Configure RSpec
10+
RSpec.configure do |config|
11+
# Use the specified formatter
12+
config.formatter = :documentation
13+
14+
# Enable flags like --only-failures and --next-failure
15+
config.example_status_persistence_file_path = ".rspec_status"
16+
17+
# Disable RSpec exposing methods globally on `Module` and `main`
18+
config.disable_monkey_patching!
19+
20+
# Randomize test order
21+
config.order = :random
22+
Kernel.srand config.seed
23+
24+
# Mocking File reads for consistent test inputs
25+
config.before(:each) do
26+
allow(File).to receive(:read) { |file_path|
27+
if file_path.end_with?('.html')
28+
'<div class="shared-class unique-html-class"></div>'
29+
elsif file_path.end_with?('.scss')
30+
'.shared-class { color: red; } .unique-scss-class { color: blue; }'
31+
else
32+
''
33+
end
34+
}
35+
end
36+
end

0 commit comments

Comments
 (0)