html_scss_class_checker 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2c024f63fc53ed959e7317d0cda0cc20938a20ca90bd147d84263164e64c82d1
4
+ data.tar.gz: 32ed1e7d158c29ca7fe882e9ca406cb90cd01c7f915b57af4be1a725314b4aa8
5
+ SHA512:
6
+ metadata.gz: 537969a92541a816ee3bf7af9c5c6ed47b0ce8832011d983d1cfea76bdccf55c276560ff33d3340222a7063560f4a29068e55b30009d7bb8fc04d0662d1b113d
7
+ data.tar.gz: be4b97c12a848e28dfc676ca7c76bba821ea3c15f867628c00092d30f8ebd93ddcb41253ed35fc3251fd684689af2ae83de2d5af27094aa68b736614f6933a86
data/.gitignore ADDED
@@ -0,0 +1,117 @@
1
+ # File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
2
+ # Created by https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,powershell,ruby
3
+ # Edit at https://www.toptal.com/developers/gitignore?templates=windows,visualstudiocode,powershell,ruby
4
+
5
+ ### PowerShell ###
6
+ # Exclude packaged modules
7
+ *.zip
8
+
9
+ # Exclude .NET assemblies from source
10
+ *.dll
11
+
12
+ ### Ruby ###
13
+ *.gem
14
+ *.rbc
15
+ /.config
16
+ /coverage/
17
+ /InstalledFiles
18
+ /pkg/
19
+ /spec/reports/
20
+ /spec/examples.txt
21
+ /test/tmp/
22
+ /test/version_tmp/
23
+ /tmp/
24
+
25
+ # Used by dotenv library to load environment variables.
26
+ # .env
27
+
28
+ # Ignore Byebug command history file.
29
+ .byebug_history
30
+
31
+ ## Specific to RubyMotion:
32
+ .dat*
33
+ .repl_history
34
+ build/
35
+ *.bridgesupport
36
+ build-iPhoneOS/
37
+ build-iPhoneSimulator/
38
+
39
+ ## Specific to RubyMotion (use of CocoaPods):
40
+ #
41
+ # We recommend against adding the Pods directory to your .gitignore. However
42
+ # you should judge for yourself, the pros and cons are mentioned at:
43
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
44
+ # vendor/Pods/
45
+
46
+ ## Documentation cache and generated files:
47
+ /.yardoc/
48
+ /_yardoc/
49
+ /doc/
50
+ /rdoc/
51
+
52
+ ## Environment normalization:
53
+ /.bundle/
54
+ /vendor/bundle
55
+ /lib/bundler/man/
56
+
57
+ # for a library or gem, you might want to ignore these files since the code is
58
+ # intended to run in multiple environments; otherwise, check them in:
59
+ # Gemfile.lock
60
+ # .ruby-version
61
+ # .ruby-gemset
62
+
63
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
64
+ .rvmrc
65
+
66
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
67
+ # .rubocop-https?--*
68
+
69
+ ### VisualStudioCode ###
70
+ .vscode/*
71
+ !.vscode/settings.json
72
+ !.vscode/tasks.json
73
+ !.vscode/launch.json
74
+ !.vscode/extensions.json
75
+ !.vscode/*.code-snippets
76
+
77
+ # Local History for Visual Studio Code
78
+ .history/
79
+
80
+ # Built Visual Studio Code Extensions
81
+ *.vsix
82
+
83
+ ### VisualStudioCode Patch ###
84
+ # Ignore all local history of files
85
+ .history
86
+ .ionide
87
+
88
+ ### Windows ###
89
+ # Windows thumbnail cache files
90
+ Thumbs.db
91
+ Thumbs.db:encryptable
92
+ ehthumbs.db
93
+ ehthumbs_vista.db
94
+
95
+ # Dump file
96
+ *.stackdump
97
+
98
+ # Folder config file
99
+ [Dd]esktop.ini
100
+
101
+ # Recycle Bin used on file shares
102
+ $RECYCLE.BIN/
103
+
104
+ # Windows Installer files
105
+ *.cab
106
+ *.msi
107
+ *.msix
108
+ *.msm
109
+ *.msp
110
+
111
+ # Windows shortcuts
112
+ *.lnk
113
+
114
+ # End of https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,powershell,ruby
115
+
116
+ # Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
117
+
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+
4
+
5
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,51 @@
1
+ # Contributing to HtmlScssClassChecker
2
+
3
+ Thank you for your interest in contributing to `HtmlScssClassChecker`! This document provides guidelines for contributions to this project. By contributing to this project, you agree to abide by its terms.
4
+
5
+ ## Code of Conduct
6
+
7
+ Our project adheres to a [Code of Conduct](/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to [support@vcwtech.com](mailto:support@vcwtech.com).
8
+
9
+ ## How to Contribute
10
+
11
+ 1. **Report Bugs**: If you find a bug, please open an issue in the repository, using the bug report template. Include as much detail as possible, such as steps to reproduce the bug, expected behavior, and actual behavior.
12
+
13
+ 2. **Suggest Enhancements**: For ideas about new features or improvements, open an issue using the feature request template.
14
+
15
+ 3. **Submit Pull Requests**: Contributions to the codebase are made through pull requests. Before submitting a pull request, please read and follow the pull request guidelines below.
16
+
17
+ ## Pull Request Guidelines
18
+
19
+ 1. **Fork the Repository**: Start by forking the repository and cloning it to your local machine.
20
+
21
+ 2. **Create a New Branch**: Create a branch for your changes, using a name that reflects the purpose of your contribution, such as `feature/add-new-feature` or `bugfix/fix-some-bug`.
22
+
23
+ 3. **Make Your Changes**: Implement your changes, adhering to the coding standards and best practices of the project.
24
+
25
+ 4. **Write Tests**: Add or update tests to cover your changes. Ensure all tests pass.
26
+
27
+ 5. **Document Your Changes**: Update the README or other documentation as necessary to reflect your changes.
28
+
29
+ 6. **Commit Your Changes**: Make sure your commit messages are clear and follow best practices.
30
+
31
+ 7. **Push to Your Fork**: Push your changes to your forked repository.
32
+
33
+ 8. **Open a Pull Request**: Open a pull request against the main repository. Describe your changes and reference any relevant issues.
34
+
35
+ 9. **Code Review**: Once your pull request is open, it will be reviewed by maintainers. Engage in the code review process, addressing any feedback.
36
+
37
+ ## Development Setup
38
+
39
+ For instructions on setting up a development environment, please refer to [DEVELOPMENT.md](/DEVELOPMENT.md).
40
+
41
+ ## Testing
42
+
43
+ Before submitting pull requests, ensure that all tests are passing. For information on running and writing tests, see [TESTING.md](/TESTING.md).
44
+
45
+ ## Questions or Suggestions
46
+
47
+ If you have questions or suggestions, feel free to open an issue or reach out to the maintainers at [support@vcwtech.com](mailto:support@vcwtech.com).
48
+
49
+ ---
50
+
51
+ We look forward to your contributions and are excited to see what we can build together in this community!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ group :development, :test do
2
+ gem 'rspec'
3
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,25 @@
1
+ GEM
2
+ specs:
3
+ diff-lcs (1.5.0)
4
+ rspec (3.12.0)
5
+ rspec-core (~> 3.12.0)
6
+ rspec-expectations (~> 3.12.0)
7
+ rspec-mocks (~> 3.12.0)
8
+ rspec-core (3.12.2)
9
+ rspec-support (~> 3.12.0)
10
+ rspec-expectations (3.12.3)
11
+ diff-lcs (>= 1.2.0, < 2.0)
12
+ rspec-support (~> 3.12.0)
13
+ rspec-mocks (3.12.6)
14
+ diff-lcs (>= 1.2.0, < 2.0)
15
+ rspec-support (~> 3.12.0)
16
+ rspec-support (3.12.1)
17
+
18
+ PLATFORMS
19
+ x64-mingw-ucrt
20
+
21
+ DEPENDENCIES
22
+ rspec
23
+
24
+ BUNDLED WITH
25
+ 2.4.22
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Visionary Code Works
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # HtmlScssClassChecker
2
+
3
+ HtmlScssClassChecker is a Ruby gem for extracting and comparing class names from HTML and SCSS files. It helps in identifying unmatched or unused classes, enhancing the maintainability of front-end codebases.
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
+ To use HtmlScssClassChecker, you need to set up a configuration JSON file (`config.json`) specifying known classes and directories to be checked:
28
+
29
+ ```json
30
+ {
31
+ "known_classes": ["class1", "class2"],
32
+ "html_directories": ["_includes", "_layouts"],
33
+ "scss_directories": ["_sass"]
34
+ }
35
+ ```
36
+
37
+ Run the checker with:
38
+
39
+ ```ruby
40
+ require 'html_scss_class_checker'
41
+
42
+ checker = HtmlScssClassChecker::ClassChecker.new(config)
43
+ checker.check
44
+
45
+ puts "Unmatched Classes:"
46
+ puts checker.unmatched_classes.to_a
47
+ ```
48
+
49
+ More detailed usage instructions will be provided in the [Usage Documentation](/docs/usage.md).
50
+
51
+ ## Contributing
52
+
53
+ Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change. Please ensure to update tests as appropriate.
54
+
55
+ See [CONTRIBUTING.md](/CONTRIBUTING.md) for detailed guidelines.
56
+
57
+ ## Documentation
58
+
59
+ For full documentation, visit [our documentation page](/docs).
60
+
61
+ ## License
62
+
63
+ Distributed under the MIT License. See [LICENSE](/LICENSE) for more information.
64
+
65
+ ## Additional Resources
66
+
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
+
69
+ - [Changelog](/CHANGELOG.md): Detailed list of changes in each version.
70
+ - [Code of Conduct](/CODE_OF_CONDUCT.md): Guidelines for participation in the community.
71
+ - [Development Guide](/docs/development.md): Instructions for setting up a development environment and working on the gem.
72
+ - [Testing Guide](/docs/testing.md): Information on how to run and write tests for the gem.
73
+ - [Usage Documentation](`/docs/usage.md`): Provide detailed instructions on how to use the gem, including various configurations and options.
74
+ - [Contributing Guidelines](`/CONTRIBUTING.md`):** Outline how others can contribute to your project. Include information on coding standards, pull request processes, and issue reporting guidelines.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ # Define a task for running tests (if you're using RSpec)
5
+ Rake::TestTask.new(:spec) do |t|
6
+ t.libs.push "spec"
7
+ t.ruby_opts = ["-W0"] # Suppresses Ruby warnings
8
+ t.pattern = "spec/**/*_spec.rb" # Location of spec files
9
+ end
10
+
11
+ # Set the default task to run tests
12
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'irb'
4
+ require 'html_scss_class_checker' # Require your gem
5
+
6
+ # Start an IRB session with your gem loaded
7
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+ require 'json'
5
+
6
+ # Example setup tasks
7
+ puts "Setting up the HtmlScssClassChecker gem..."
8
+
9
+ # Create a default configuration file if it doesn't exist
10
+ config_path = File.join(Dir.pwd, 'config.json')
11
+ unless File.exist?(config_path)
12
+ default_config = {
13
+ 'known_classes' => [],
14
+ 'html_directories' => ['_includes', '_layouts'],
15
+ 'scss_directories' => ['_sass']
16
+ }
17
+
18
+ File.write(config_path, JSON.pretty_generate(default_config))
19
+ puts "Created default config.json file."
20
+ end
21
+
22
+ puts "Setup complete."
data/docs/api.md ADDED
File without changes
@@ -0,0 +1,87 @@
1
+ # Development Guide for HtmlScssClassChecker
2
+
3
+ This document provides guidelines and instructions for developers who wish to contribute to the development of the `HtmlScssClassChecker` gem. This guide covers setting up a development environment, making changes, and submitting contributions.
4
+
5
+ ## Setting Up a Development Environment
6
+
7
+ 1. **Clone the Repository**:
8
+ First, clone the repository to your local machine. Use the following command, replacing `REPO_URL` with the actual URL of the repository:
9
+
10
+ ```bash
11
+ git clone REPO_URL
12
+ cd html_scss_class_checker
13
+ ```
14
+
15
+ 2. **Install Dependencies**:
16
+ Make sure you have Bundler installed, then run:
17
+
18
+ ```bash
19
+ bundle install
20
+ ```
21
+
22
+ This will install all the necessary dependencies for the gem.
23
+
24
+ 3. **Create a Feature Branch**:
25
+ When working on a new feature or bug fix, create a new branch:
26
+
27
+ ```bash
28
+ git checkout -b feature/my-new-feature
29
+ ```
30
+
31
+ or
32
+
33
+ ```bash
34
+ git checkout -b bugfix/my-bug-fix
35
+ ```
36
+
37
+ ## Making Changes
38
+
39
+ 1. **Code Changes**:
40
+ Make your code changes, ensuring to follow the coding standards and guidelines of the project. Add or modify tests as appropriate for your changes.
41
+
42
+ 2. **Running Tests**:
43
+ Run the test suite to ensure your changes haven't introduced any regressions:
44
+
45
+ ```bash
46
+ rake spec
47
+ ```
48
+
49
+ 3. **Update Documentation**:
50
+ If your changes introduce new features or modify existing behavior, update the documentation accordingly.
51
+
52
+ 4. **Commit Your Changes**:
53
+ Once you're satisfied with your changes and all tests pass, commit your changes:
54
+
55
+ ```bash
56
+ git add .
57
+ git commit -m "Add my new feature"
58
+ ```
59
+
60
+ ## Submitting Contributions
61
+
62
+ 1. **Push Your Branch**:
63
+ Push the feature or bugfix branch to your fork:
64
+
65
+ ```bash
66
+ git push origin feature/my-new-feature
67
+ ```
68
+
69
+ 2. **Create a Pull Request**:
70
+ Go to the original `HtmlScssClassChecker` repository on GitHub and create a new pull request. Provide a clear description of the changes and any relevant issue numbers.
71
+
72
+ 3. **Code Review**:
73
+ Once your pull request is opened, it will be reviewed by the maintainers. Engage in the code review process, addressing any feedback or comments.
74
+
75
+ 4. **Merging**:
76
+ After your pull request has been approved, it will be merged into the main branch.
77
+
78
+ ## Additional Resources
79
+
80
+ - **Ruby Style Guide**: Familiarize yourself with the [Ruby Style Guide](https://github.com/rubocop/ruby-style-guide) to maintain consistency in code.
81
+ - **Testing with RSpec**: Learn more about testing Ruby applications with [RSpec](https://rspec.info/).
82
+
83
+ ## Questions and Support
84
+
85
+ If you have any questions or need help with setting up your development environment, feel free to open an issue in the repository for assistance.
86
+
87
+ Thank you for contributing to `HtmlScssClassChecker`!
data/docs/testing.md ADDED
@@ -0,0 +1,73 @@
1
+ # Testing Guide for HtmlScssClassChecker
2
+
3
+ This document provides guidelines and best practices for writing and running tests for the `HtmlScssClassChecker` gem. Effective testing is crucial to ensure the reliability and stability of the gem.
4
+
5
+ ## Setting Up for Testing
6
+
7
+ Before running the tests, ensure that you have set up your development environment as described in [DEVELOPMENT.md](/DEVELOPMENT.md). This setup includes cloning the repository and installing all required dependencies.
8
+
9
+ ## Running Tests
10
+
11
+ To run the test suite, use the following command:
12
+
13
+ ```bash
14
+ rake spec
15
+ ```
16
+
17
+ This command will execute all tests written in the `spec` directory. Make sure that all tests pass before submitting any changes or pull requests.
18
+
19
+ ## Writing Tests
20
+
21
+ When adding new features or fixing bugs, it's essential to write corresponding tests. The `HtmlScssClassChecker` gem uses RSpec for testing. Here are some guidelines for writing tests:
22
+
23
+ 1. **Descriptive Test Cases**: Write clear and descriptive test cases. Each test case should express the intended functionality or the specific condition it's testing.
24
+
25
+ 2. **Small and Focused**: Keep tests small and focused on one aspect of the code. Each test should only test one behavior.
26
+
27
+ 3. **Use Contexts**: Group related tests using `context` blocks in RSpec. This helps to organize tests and makes the test file easier to read.
28
+
29
+ 4. **Test Edge Cases**: Consider edge cases and error conditions, not just the happy path.
30
+
31
+ 5. **DRY (Don't Repeat Yourself)**: Reuse test setup code where possible, but avoid complex dependencies between tests.
32
+
33
+ 6. **Mocks and Stubs**: Use mocks and stubs to isolate tests from dependencies, particularly for external services or file access.
34
+
35
+ ## Example Test Structure
36
+
37
+ Here’s an example structure for an RSpec test in `HtmlScssClassChecker`:
38
+
39
+ ```ruby
40
+ RSpec.describe HtmlScssClassChecker::SomeClass do
41
+ describe '#some_method' do
42
+ context 'when some condition is met' do
43
+ it 'behaves in a certain way' do
44
+ # Setup
45
+ # Exercise
46
+ # Verify
47
+ end
48
+ end
49
+
50
+ context 'when another condition is met' do
51
+ it 'behaves in a different way' do
52
+ # Setup
53
+ # Exercise
54
+ # Verify
55
+ end
56
+ end
57
+ end
58
+ end
59
+ ```
60
+
61
+ ## Testing Best Practices
62
+
63
+ - **Independence**: Tests should not rely on the state produced by other tests.
64
+ - **Reproducibility**: Tests should produce the same results regardless of the environment in which they are run.
65
+ - **Automated**: Automate tests as part of your build or CI/CD pipeline.
66
+
67
+ ## Continuous Integration
68
+
69
+ Consider setting up a Continuous Integration (CI) service like Travis CI, GitHub Actions, or CircleCI to automatically run tests on every commit or pull request. This ensures that all changes are tested before they are merged.
70
+
71
+ ---
72
+
73
+ For more information on RSpec and testing in Ruby, refer to the [RSpec documentation](https://relishapp.com/rspec/). If you encounter any issues or have questions about testing `HtmlScssClassChecker`, feel free to open an issue in the repository.
data/docs/usage.md ADDED
@@ -0,0 +1,89 @@
1
+ # HtmlScssClassChecker Usage Guide
2
+
3
+ This document provides detailed instructions on how to use the `HtmlScssClassChecker` gem. This gem is designed to help front-end developers identify unused or unmatched HTML and SCSS classes, improving the maintainability and efficiency of their codebases.
4
+
5
+ ## Installation
6
+
7
+ Before using the gem, ensure it is installed in your Ruby environment:
8
+
9
+ ```bash
10
+ gem install html_scss_class_checker
11
+ ```
12
+
13
+ Or, if you are using Bundler, add it to your Gemfile and run `bundle install`:
14
+
15
+ ```ruby
16
+ gem 'html_scss_class_checker'
17
+ ```
18
+
19
+ ## Configuration
20
+
21
+ Create a configuration file named `config.json` in your project root (or another location of your choosing) with the following structure:
22
+
23
+ ```json
24
+ {
25
+ "known_classes": ["list", "of", "known", "classes"],
26
+ "html_directories": ["path/to/html/files"],
27
+ "scss_directories": ["path/to/scss/files"]
28
+ }
29
+ ```
30
+
31
+ - `known_classes`: An array of class names that you expect to find in your HTML and SCSS files.
32
+ - `html_directories`: An array of directories where your HTML files are located.
33
+ - `scss_directories`: An array of directories where your SCSS files are located.
34
+
35
+ ## Basic Usage
36
+
37
+ To run the class checker, use the following Ruby script:
38
+
39
+ ```ruby
40
+ require 'html_scss_class_checker'
41
+
42
+ # Load configuration
43
+ config_file = 'config.json' # Replace with your config file path
44
+ config = JSON.parse(File.read(config_file))
45
+
46
+ # Initialize and run checker
47
+ checker = HtmlScssClassChecker::ClassChecker.new(config)
48
+ checker.check
49
+
50
+ # Output unmatched classes
51
+ puts "Unmatched Classes:"
52
+ puts checker.unmatched_classes.to_a
53
+
54
+ # Output class mapping in each file
55
+ puts "\nClasses in each file:"
56
+ checker.file_class_mapping.each do |file, classes|
57
+ puts "#{file}: #{classes.to_a}"
58
+ end
59
+ ```
60
+
61
+ This script will read the configuration from `config.json`, initialize the class checker, and then output any unmatched classes along with a mapping of classes to files.
62
+
63
+ ## Advanced Usage
64
+
65
+ ### Custom Configurations
66
+
67
+ You can modify the `config.json` to suit your project's structure and requirements. For instance, you may have multiple HTML and SCSS directories or a specific set of known classes you want to validate against.
68
+
69
+ ### Integrating with Build Tools
70
+
71
+ You can integrate `HtmlScssClassChecker` into your build process by creating a Rake task or a script that is run as part of your build or deployment pipeline. This can help in catching class inconsistencies before they reach production.
72
+
73
+ ## Troubleshooting
74
+
75
+ If you encounter issues while using the gem, consider the following:
76
+
77
+ - Ensure all paths in your `config.json` are correct and accessible.
78
+ - Check if all necessary dependencies are installed.
79
+ - Validate the format of your `config.json`.
80
+
81
+ ## Contributions and Feedback
82
+
83
+ Contributions to the `HtmlScssClassChecker` gem are welcome! If you have suggestions for improvement or encounter any issues, please feel free to open an issue or submit a pull request on the repository.
84
+
85
+ ---
86
+
87
+ For further details, refer to the [README.md](/README.md) and the [API Documentation](/docs/api.md) (if available).
88
+
89
+ This guide assumes a basic understanding of Ruby and gem management. For more information on these topics, visit the [official Ruby documentation](https://www.ruby-lang.org/en/documentation/).
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "html_scss_class_checker"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Thaddeus Thomas"]
5
+ spec.email = ["support@vcwtech.com"]
6
+
7
+ spec.summary = %q{A Ruby gem for identifying unused or unmatched HTML and SCSS classes.}
8
+ 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"
10
+ spec.license = "MIT"
11
+
12
+ # Specify which files should be included in the gem
13
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
14
+ f.match(%r{^(test|spec|features)/})
15
+ end
16
+ spec.bindir = "bin"
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ # Add runtime dependency
21
+ spec.add_runtime_dependency "json"
22
+
23
+ # Add development dependencies
24
+ spec.add_development_dependency "bundler", "~> 2.0"
25
+ spec.add_development_dependency "rake", "~> 13.0"
26
+ # Add other development dependencies here
27
+ end
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+ require 'set'
3
+
4
+ module HtmlScssClassChecker
5
+ class ClassChecker
6
+ attr_reader :unmatched_classes, :file_class_mapping
7
+
8
+ def initialize(config)
9
+ @known_classes = Set.new(config['known_classes'])
10
+ @html_directories = config['html_directories']
11
+ @scss_directories = config['scss_directories']
12
+ @unmatched_classes = Set.new
13
+ @file_class_mapping = {}
14
+ end
15
+
16
+ def check
17
+ process_directories(@html_directories, 'html')
18
+ process_directories(@scss_directories, 'scss')
19
+ end
20
+
21
+ private
22
+
23
+ def process_directories(directories, file_type)
24
+ directories.each do |directory|
25
+ Dir.glob("#{directory}/**/*.#{file_type}").each do |file|
26
+ classes = FileProcessor.new(file, file_type).list_classes
27
+ @unmatched_classes.merge(classes - @known_classes)
28
+ @file_class_mapping[file] = classes
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ require 'json'
2
+ require 'set'
3
+
4
+ module HtmlScssClassChecker
5
+ class ClassExtractor
6
+ def self.extract_from_html(content)
7
+ content.scan(/class="([^"]+)"/).flatten.map { |cls| cls.split }.flatten.to_set
8
+ end
9
+
10
+ def self.extract_from_scss(content)
11
+ content.scan(/\.[\w-]+/).flatten.map { |cls| cls.delete_prefix('.') }.to_set
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ require 'json'
2
+ require 'set'
3
+
4
+ module HtmlScssClassChecker
5
+ class FileProcessor
6
+ def initialize(file_path, file_type)
7
+ @file_path = file_path
8
+ @file_type = file_type
9
+ end
10
+
11
+ def list_classes
12
+ content = File.read(@file_path)
13
+ case @file_type
14
+ when 'html'
15
+ ClassExtractor.extract_from_html(content)
16
+ when 'scss'
17
+ ClassExtractor.extract_from_scss(content)
18
+ else
19
+ Set.new
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ require 'html_scss_class_checker/class_extractor'
2
+ require 'html_scss_class_checker/file_processor'
3
+ require 'html_scss_class_checker/class_checker'
4
+
5
+ # Read configuration from JSON file
6
+ config_file = 'config.json' # Update this path as needed
7
+ config = JSON.parse(File.read(config_file))
8
+
9
+ checker = HtmlScssClassChecker::ClassChecker.new(config)
10
+ checker.check
11
+
12
+ puts "Unmatched Classes:"
13
+ puts checker.unmatched_classes.to_a
14
+
15
+ puts "\nClasses in each file:"
16
+ checker.file_class_mapping.each do |file, classes|
17
+ puts "#{file}: #{classes.to_a}"
18
+ end
@@ -0,0 +1,38 @@
1
+ # Define directories and files to create
2
+ $gemName = "html_scss_class_checker"
3
+ $directories = @(
4
+ "$gemName/bin",
5
+ "$gemName/lib/$gemName",
6
+ "$gemName/spec"
7
+ )
8
+
9
+ $files = @(
10
+ "$gemName/bin/console",
11
+ "$gemName/bin/setup",
12
+ "$gemName/lib/$gemName/class_extractor.rb",
13
+ "$gemName/lib/$gemName/file_processor.rb",
14
+ "$gemName/lib/$gemName/class_checker.rb",
15
+ "$gemName/lib/$gemName.rb",
16
+ "$gemName/spec/class_extractor_spec.rb",
17
+ "$gemName/spec/file_processor_spec.rb",
18
+ "$gemName/spec/class_checker_spec.rb",
19
+ "$gemName/spec/spec_helper.rb",
20
+ "$gemName/$gemName.gemspec",
21
+ "$gemName/Gemfile",
22
+ "$gemName/Rakefile",
23
+ "$gemName/LICENSE.txt",
24
+ "$gemName/README.md",
25
+ "$gemName/.gitignore"
26
+ )
27
+
28
+ # Create directories
29
+ foreach ($dir in $directories) {
30
+ New-Item -Path $dir -ItemType Directory -Force
31
+ }
32
+
33
+ # Create files
34
+ foreach ($file in $files) {
35
+ New-Item -Path $file -ItemType File -Force
36
+ }
37
+
38
+ Write-Host "Gem structure for '$gemName' created successfully."
data/scripts/classes ADDED
@@ -0,0 +1 @@
1
+ grep -ohr 'class="[^"]*"' ./ | sort | uniq
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: html_scss_class_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thaddeus Thomas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-12-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ description: HtmlScssClassChecker is designed to streamline the process of frontend
56
+ development by scanning HTML and SCSS files and identifying classes that are either
57
+ undefined or unused. This gem aims to facilitate cleaner, more maintainable, and
58
+ efficient codebases by providing developers with the tools to easily audit and synchronize
59
+ their HTML and SCSS class definitions. Its an essential tool for web developers
60
+ looking to optimize their front-end code and ensure consistency across their stylesheets
61
+ and markup.
62
+ email:
63
+ - support@vcwtech.com
64
+ executables:
65
+ - console
66
+ - setup
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - ".gitignore"
71
+ - ".rspec"
72
+ - ".ruby-version"
73
+ - CHANGELOG.md
74
+ - CONTRIBUTING.md
75
+ - Gemfile
76
+ - Gemfile.lock
77
+ - LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - bin/console
81
+ - bin/setup
82
+ - docs/api.md
83
+ - docs/development.md
84
+ - docs/testing.md
85
+ - docs/usage.md
86
+ - html_scss_class_checker.gemspec
87
+ - lib/html_scss_class_checker.rb
88
+ - lib/html_scss_class_checker/class_checker.rb
89
+ - lib/html_scss_class_checker/class_extractor.rb
90
+ - lib/html_scss_class_checker/file_processor.rb
91
+ - scripts/CreateGemStructure.ps1
92
+ - scripts/classes
93
+ homepage: http://example.com/gems/html_scss_class_checker
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubygems_version: 3.4.10
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A Ruby gem for identifying unused or unmatched HTML and SCSS classes.
116
+ test_files: []