A slim file to minify embedded code.
Remove comments and unnecessary blank lines in the css or javascript embedding of your Slim files when embedding them in HTML.
You have a Slim file like this:
html
head
title My Slim Template
body
h1 Welcome to Slim!
css:
/* Slim supports embedded css */
body { background-color: #ddd; }
javascript:
// Slim supports embedded javascript
alert('Slim supports embedded javascript!')If this gem is not applied, the HTML will look like the following:
<html>
<head>
<title>My Slim Template</title>
</head>
<body>
<h1>
Welcome to Slim!
</h1>
<style>
/* Slim supports embedded css */
body { background-color: #ddd; }
</style>
<script>
// Slim supports embedded javascript
alert('Slim supports embedded javascript!')
</script>
</body>
</html>Applying this gem will remove unnecessary blank lines and comments:
<html>
<head>
<title>My Slim Template</title>
</head>
<body>
<h1>
Welcome to Slim!
</h1>
<style>
body { background-color: #ddd; }
</style>
<script>
alert('Slim supports embedded javascript!')
</script>
</body>
</html>Add this line to your application's Gemfile:
# Gemfile
gem 'slim'
gem 'slim-embedded-minify'And then execute:
bundle install
All you have to do is add this gem to your Gemfile. No additional configuration or changes to your code are required.
# Gemfile
gem 'slim'
gem 'slim-embedded-minify'This gem supports minification for the following Slim embedded engines:
| Engine | Comment Removal | Blank Line Removal |
|---|---|---|
css: |
/* */ |
✓ |
javascript: |
//, /* */ |
✓ |
scss: |
/* */ (after compilation) |
✓ |
sass: |
/* */ (after compilation) |
✓ |
less: |
/* */ (after compilation) |
✓ |
coffee: |
//, /* */ (after compilation) |
✓ |
For scss:, sass:, less:, and coffee: engines, the minification is applied
to the compiled output (CSS or JavaScript), not the source code. This means:
- SCSS/Sass/Less single-line comments (
//) are already removed during compilation - Only CSS-style comments (
/* */) remain and are removed by this gem - CoffeeScript comments become JavaScript comments after compilation and are then removed
These engines require their respective compiler gems to be installed; if a compiler is missing, Slim will raise an error when compiling the embedded code.
Bug reports and pull requests are welcome on GitHub at https://github.com/ydah/slim-embedded-minify. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Slim::Embedded::Minify project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.