Skip to content

ydah/slim-embedded-minify

Repository files navigation

SlimEmbeddedMinify

Gem Version test RubyDoc

A slim file to minify embedded code.

Overview

Remove comments and unnecessary blank lines in the css or javascript embedding of your Slim files when embedding them in HTML.

Example

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>

Installation

Add this line to your application's Gemfile:

# Gemfile
gem 'slim'
gem 'slim-embedded-minify'

And then execute:

bundle install

Usage

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'

Supported Embedded Engines

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)

Note on Compile-time Engines

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.

Contributing

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.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

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.

About

A slim file to minify embedded code.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors