2023-08-24 06:41:11 -06:00
# Miniparser
2023-08-24 06:15:36 -06:00
2023-08-24 06:41:11 -06:00
Miniparser is a Ruby gem that takes code as input (HTML, JavaScript, or CSS), determines the code language, validates it, and then minifies it. It returns whether the code is valid or not, and if valid, provides the minified code.
2023-08-24 06:26:44 -06:00
## Installation
2023-08-24 06:33:49 -06:00
Add this line to your application's Gemfile:
```ruby
2023-08-24 06:41:11 -06:00
gem 'Miniparser'
2023-08-24 06:33:49 -06:00
```
2023-08-24 06:26:44 -06:00
2023-08-24 06:33:49 -06:00
And then execute:
2023-08-24 06:26:44 -06:00
2023-08-24 06:33:49 -06:00
```bash
$ bundle install
```
2023-08-24 06:26:44 -06:00
2023-08-24 06:33:49 -06:00
Or install it yourself as:
2023-08-24 06:26:44 -06:00
2023-08-24 06:33:49 -06:00
```bash
2023-08-24 06:41:11 -06:00
$ gem install Miniparser
2023-08-24 06:33:49 -06:00
```
2023-08-24 06:26:44 -06:00
## Usage
2023-08-24 06:45:25 -06:00
Miniparser provides two main methods to process either a file or a string containing HTML, JavaScript, or CSS code.
2023-08-24 06:33:49 -06:00
### Processing a File
You can process a file by calling the `type_file` method and passing the file path as an argument:
```ruby
2023-08-24 06:41:11 -06:00
result = Miniparser::Processor.type_file('path/to/yourfile.html')
2023-08-24 06:33:49 -06:00
```
2023-08-24 06:26:44 -06:00
2023-08-24 06:33:49 -06:00
### Processing a String
2023-08-24 06:26:44 -06:00
2023-08-24 06:33:49 -06:00
You can process a string containing code by calling the `type_string` method:
2023-08-24 06:26:44 -06:00
2023-08-24 06:33:49 -06:00
```ruby
2023-08-24 06:41:11 -06:00
result = Miniparser::Processor.type_string('< html > < head > < / head > < body > < / body > < / html > ')
2023-08-24 06:33:49 -06:00
```
Both methods return a hash containing the validation status, any errors, and the minified code if the input was valid:
```ruby
{
valid: true or false,
errors: "Error message if any",
minified_code: "Minified code if valid"
}
```
2023-08-24 06:26:44 -06:00
## Contributing
2023-08-24 06:33:49 -06:00
Bug reports and pull requests are welcome. Please adhere to the code of conduct.
2023-08-24 06:26:44 -06:00
## License
The gem is available as open source under the terms of the [MIT License ](https://opensource.org/licenses/MIT ).
2023-10-06 16:13:12 -06:00