Official url: github.com/ktheory/juicer-rails
In development mode, juicer-rails will serve expanded assets for easier debugging. In production mode, juicer-rails serves one minified file.
Special thanks to:
Christian Johansen (et al) for making juicer.
Jeremy Ashkenas for suggesting more efficient conditional CSS
In your rails project:
script/plugin install git://github.com/ktheory/juicer-rails.git
juicer-rails requires the latest, unreleased version of juicer. (This should change soon.) For now, build your own juicer gem:
git clone git://github.com/cjohansen/juicer.git cd juicer rake build sudo gem install pkg/juicer-0.9.9.gem
In production, this will return a single script tag for the asset. The name of the asset is determined by putting min before the file extension.
If you have asset hosts configured, it will honor those.
Stylesheets work similarly. Say app.css depends on reset.css.
juiced_tag "/stylesheets/app.css" # in development => <link href="/stylesheets/reset.css" media="screen" rel="stylesheet" type="text/css" /> <link href="/stylesheets/app.css" media="screen" rel="stylesheet" type="text/css" /> juiced_tag "/stylesheets/app.css" # in production => <link href="/stylesheets/app.min.css" media="screen" rel="stylesheet" type="text/css" />
Juicer can also embed images in your stylesheets. Of course, this doesn't work in IE. Embedding is disabled by default, but you can turn it on in the rails initializer:
Juicer::ActionViewHelper.embed_images = true
Now we have:
juiced_tag "/stylesheets/app.css" # in production, with embedding => <!--[if (!IE)|(gte IE 8)]><!--> <link rel="stylesheet" type="text/css" href="/stylesheets/app.embedded.css" /> <!--<![endif]--> <!--[if lte IE 7]> <link rel="stylesheet" type="text/css" href="/stylesheets/app.min.css" /> <![endif]-->
Note on Patches/Pull Requests
Fork the project.
Make your feature addition or bug fix.
Add tests for it. This is important so I don't break it in a future version unintentionally.
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
Send me a pull request. Bonus points for topic branches.
Copyright © 2010 Aaron Suggs. See LICENSE for details.