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.
Before using the gem, ensure it is installed in your Ruby environment:
gem install html_scss_class_checkerOr, if you are using Bundler, add it to your Gemfile and run bundle install:
gem 'html_scss_class_checker'Create a configuration file named config.json in your project root (or another location of your choosing) with the following structure:
{
"known_classes": ["list", "of", "known", "classes"],
"html_directories": ["path/to/html/files"],
"scss_directories": ["path/to/scss/files"]
}known_classes: An array of class names that you expect to find in your HTML and SCSS files.html_directories: An array of directories where your HTML files are located.scss_directories: An array of directories where your SCSS files are located.
To run the class checker, use the following Ruby script:
require 'html_scss_class_checker'
# Load configuration
config_file = 'config.json' # Replace with your config file path
config = JSON.parse(File.read(config_file))
# Initialize and run checker
checker = HtmlScssClassChecker::ClassChecker.new(config)
checker.check
# Output unmatched classes
puts "Unmatched Classes:"
puts checker.unmatched_classes.to_a
# Output class mapping in each file
puts "\nClasses in each file:"
checker.file_class_mapping.each do |file, classes|
puts "#{file}: #{classes.to_a}"
endThis 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.
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.
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.
If you encounter issues while using the gem, consider the following:
- Ensure all paths in your
config.jsonare correct and accessible. - Check if all necessary dependencies are installed.
- Validate the format of your
config.json.
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.
For further details, refer to the README.md and the API Documentation (if available).
This guide assumes a basic understanding of Ruby and gem management. For more information on these topics, visit the official Ruby documentation.