html_scss_class_checker 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/changelog-update.yml +62 -0
- data/.github/workflows/gem-push.yml +44 -0
- data/.gitignore +1 -0
- data/.rspec +1 -1
- data/CONTRIBUTING.md +51 -51
- data/Gemfile +17 -3
- data/Gemfile.lock +39 -1
- data/LICENSE +21 -21
- data/README.md +76 -74
- data/Rakefile +44 -12
- data/bin/console +7 -7
- data/bin/setup +22 -22
- data/docs/api.md +97 -0
- data/docs/development.md +87 -87
- data/docs/testing.md +73 -73
- data/docs/usage.md +89 -89
- data/html_scss_class_checker.gemspec +31 -27
- data/lib/html_scss_class_checker/class_checker.rb +33 -33
- data/lib/html_scss_class_checker/class_extractor.rb +14 -14
- data/lib/html_scss_class_checker/file_processor.rb +23 -23
- data/lib/html_scss_class_checker.rb +18 -18
- data/scripts/CreateGemStructure.ps1 +38 -38
- data/scripts/classes +1 -1
- metadata +73 -15
data/docs/api.md
CHANGED
@@ -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).
|
data/docs/development.md
CHANGED
@@ -1,87 +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`!
|
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
CHANGED
@@ -1,73 +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.
|
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
CHANGED
@@ -1,89 +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/).
|
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/).
|
@@ -1,27 +1,31 @@
|
|
1
|
-
Gem::Specification.new do |spec|
|
2
|
-
spec.name = "html_scss_class_checker"
|
3
|
-
spec.version = "0.
|
4
|
-
spec.authors = ["Thaddeus Thomas"]
|
5
|
-
spec.email = ["
|
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 = "
|
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"
|
25
|
-
spec.add_development_dependency "rake"
|
26
|
-
|
27
|
-
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "html_scss_class_checker"
|
3
|
+
spec.version = "0.2.0"
|
4
|
+
spec.authors = ["Thaddeus Thomas"]
|
5
|
+
spec.email = ["thaddeus@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 = "https://github.com/Visionary-Code-Works/HtmlScssClassChecker"
|
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"
|
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"
|
30
|
+
# Add other development dependencies here
|
31
|
+
end
|