Skip to content
This repository has been archived by the owner on Nov 30, 2018. It is now read-only.
/ cssminify Public archive

CSS minification with YUI compressor, but as native Ruby port

License

Notifications You must be signed in to change notification settings

matthiassiegel/cssminify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSSminify Build Status

CSS minification with YUI compressor, but as native Ruby port.

The CSSminify gem provides CSS compression using YUI compressor. Instead of wrapping around the Java or Javascript version of YUI compressor it uses a native Ruby port of the CSS engine. Therefore this gem has no dependencies.

In basic benchmarks the Ruby version performed about as good as the Java jar. It currently passes all CSS test cases included with the YUI compressor Java source code.

Main motivation for the Ruby port and this gem was to reduce dependencies like Java.


PLEASE NOTE: this project is no longer maintained.


Installation

Install CSSminify from RubyGems:

gem install cssminify

Or include it in your project's Gemfile:

gem 'cssminify'

Usage

require 'cssminify'

CSSminify.compress('/* a comment */ .test { display: block; }')
# => minified CSS

CSSminify.compress(File.read('path/to/styles.css'))
# => minified CSS

CSSminify.compress(File.open('path/to/styles.css'))
# => minified CSS

# Alternatively use instance method...
compressor = CSSminify.new
compressor.compress(File.read("path/to/styles.css"))
# => minified CSS

Files or strings are acceptable as input.

You can pass in a second argument to control the maximum output line length (default 5000 characters):

CSSminify.compress(File.read("path/to/styles.css"), 200)

Note: in most cases line length will only be approximated.

Rails asset pipeline

Rails 3.1 integrated Sprockets to provide asset packaging and minimising out of the box. For CSS compression it relies on the yui-compressor gem which requires Java. To use CSSminify instead, edit your config/application.rb file:

config.assets.css_compressor = CSSminify.new

Compatibility

Tested with Ruby 1.9.2, 1.9.3, jruby-19mode, rbx-19mode

Changelog

See CHANGES.

Copyright

CSSminify gem and documentation

Copyright (c) 2012 Matthias Siegel (matthias.siegel@gmail.com) See LICENSE for details.

YUI compressor

See file.

About

CSS minification with YUI compressor, but as native Ruby port

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published