Giter VIP home page Giter VIP logo

cssminify's Introduction

CSSminify Travis Build Gem Version

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 has been forked from it's original author, with patches from r7com, and pushed to rubygems as cssminify2.


Installation

Install CSSminify2 from RubyGems:

gem install cssminify2

Or include it in your project's Gemfile:

gem 'cssminify2'

Usage

require 'cssminify2'

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

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

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

# Alternatively use instance method...
compressor = CSSminify2.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):

CSSminify2.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 = CSSminify2.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 ([email protected]) Copyright (c) 2016 Matt Spurrier ([email protected]) See LICENSE for details.

YUI compressor

See file.

cssminify's People

Contributors

aafanasev avatar bbbenji avatar digitalsparky avatar gizmokid2005 avatar iawaheed avatar matthiassiegel avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.