Home > minify

minify

Minify is a project mainly written in Ruby, based on the MIT license.

Make your responses faster by minifying them!

minify

min·i·fy verb \ˈmi-nə-ˌfī\ : To minimize or reduce.

Minify your files/strings/rack responses based on their MIME type.

Documentation

Gem
GitHub

Installation

gem install minify

Usage

Minify Strings By MIME Type

require 'minify'

Minify::Parser.html("<html>    <head></head>   </html>")

This is the same as:

Minify::Parser.call("text/html", "<html>    <head></head>   </html>")
# => "<html><head></head></html>"

Easily register a MIME type:

Minify::Parser.register('text/plain') do |input, options|
  options = {
    :strip => true, :squeeze => true,
    :lstrip => false, :rstrip => false,
  }.merge(options)

  output = input.dup
  output.strip! if options[:strip]
  output.rstrip! if options[:rstrip]
  output.lstrip! if options[:lstrip]
  output.squeeze! if options[:squeeze]
  output
end

p Minify::Parser.plain("   Minify    me  please!  ") # => "Minify me please!"
p Minify::Parser.plain("   Minify    me  please!  ", :strip => false) # => " Minify me please! "

class Minify::Parser
  register('text/foobar') do |input|
    "FOOBAR!"
  end
end

p Minify::Parser.foobar("Hello world!") # => "FOOBAR!"
p Minify::Parser.call("text/foobar", "...Hello world?") # => "FOOBAR!"

WARNING The following isn't functional... yet

Minify Daemon

> cd proj_dir
> minify add public/index.html public/js/**/*.js

Minify has added the following files to the watch list:
  public/index.html
  public/js/plugins.js
  public/js/script.js

> minify start

Minify started

> minify status

Minify is running

> minify stop

Minify stopped

> minify list

Minify is watching:
  public/index.html
  public/js/plugins.js
  public/js/script.js

> minify add public/css/*.css

Minify has added the following files to the watch list:
  public/css/style.css
  public/css/ie.css

> minify remove plugins.js public/**/index.*

Minify has removed the following files to the watch list:
  public/js/plugins.js
  public/index.html

> minify list

Minify is watching:
  public/js/script.js
  public/css/style.css
  public/css/ie.css

All watched will copied to proj_dir/.minify and the original files will be minimized. Whenever the files in proj_dir/.minify are changed, we update the original files.

Remember to add .minify/**/* to your .gitignore file if you're using git.

Minify Rack Responses

Minify also acts as Rack middleware:

require 'my_app'
require 'minify'

use Minify
run MyApp

Minify Templating Engines

Minify will automatically set the options of your required templating engines to minify it's output. If it doesn't have the option to, we patch the option into it. Hopefully we can eventually send all patches upstream and eliminate the need for this.

Contributing to minify

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a testing/unstable/feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile or version.

Copyright

Copyright (c) 2011 Ryan Scott Lewis. See LICENSE for further details.

Previous:path-suck