New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

crush

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crush

  • 0.3.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Crush

Crush is a set of Tilt templates for the various JavaScript and CSS compression libraries in Ruby.

See here for more information about Tilt templates: http://github.com/rtomayko/tilt

Well, they're not really templates. They're more like engines or processors. But, anyway, they fit in very well with Tilt, because each one likes to do things a little differently. Tilt + Crush cures the headache by providing a generic API to use any of the engines you need.

Basic Usage

Step 1, Install:

gem install crush

Step 2, Compress:

require "crush"
Crush.register
Tilt.new("application.js").render
# => compressed JavaScript...

Tilt Mappings

If you look closely at the above example, you had to call Crush.register before you could use any of the engines. That's because, by default, Crush does not automatically register its templates with Tilt. But, fear not, it's insanely easy to register them.

require "crush"
Crush.register
# or you can use this shortcut to do the same thing:
require "crush/all"

If you only want to use the JavaScript templates:

require "crush"
Crush.register_js
# or just:
require "crush/js"

CSS engines only:

require "crush"
Crush.register_css
# or, because I love shortcuts so much:
require "crush/css"

And finally, it's not hard to register only the ones you need, manually:

require "crush"
Tilt.register Crush::Uglifier, "js"
Tilt.register Crush::Rainpress, "css"

Generic API

The included templates are actually subclasses of Crush::Engine, which adds a few methods somewhat common to compression libraries.

Crush::Engine.compress takes the given string and immediately compresses it. It is also aliased as compile.

Crush::CSSMin.compress "body { color: red; }"
# => "body{color:red;}"

# Using Tilt's interface:
Tilt[:css].compress "body { color: red; }"
# => "body{color:red;}"

Crush::Engines do not require data from a file or block like Tilt::Templates. They can be initialized and given data through the Crush::Engine#compress instance method, which is also aliased as compile.

engine = Crush::CSSMin.new
# Does not through an ArgumentError like a Tilt::Template
engine.compress "body { color: red; }"
# => "body{color:red;}"

Included Engines

Support fo these compression engines are included:

ENGINES                    EXTENSIONS  REQUIRED LIBRARIES
-------------------------- ----------- -----------------------
JSMin                      .js         jsmin
Packr                      .js         packr
YUI::JavaScriptCompressor  .js         yui/compressor
Closure::Compiler          .js         closure-compiler
Uglifier                   .js         uglifier
CSSMin                     .css        cssmin
Rainpress                  .css        rainpress
YUI::CssCompressor         .css        yui/compressor    

Copyright (c) 2011 Peter Browne. See LICENSE for details.

FAQs

Package last updated on 30 Aug 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc