diff options
author | Joshua Peek <josh@joshpeek.com> | 2011-04-22 10:49:55 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2011-04-22 10:49:55 -0500 |
commit | dab96a267eeccd7380ad99fa19cefdfd3cd5ad2b (patch) | |
tree | 0c98a72521328d7fd9d58788b579e780f62bd37f /actionpack | |
parent | ed2820d6ecef7533970952437b974c7fa10192e1 (diff) | |
download | rails-dab96a267eeccd7380ad99fa19cefdfd3cd5ad2b.tar.gz rails-dab96a267eeccd7380ad99fa19cefdfd3cd5ad2b.tar.bz2 rails-dab96a267eeccd7380ad99fa19cefdfd3cd5ad2b.zip |
Add shorthand for js and css compressors
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/sprockets/railtie.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index ccec65ba95..9c10decd60 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -57,7 +57,44 @@ module Sprockets env.static_root = File.join(app.root.join("public"), assets.prefix) env.paths.concat assets.paths env.logger = Rails.logger + env.js_compressor = expand_js_compressor(assets.js_compressor) + env.css_compressor = expand_css_compressor(assets.css_compressor) env end + + def expand_js_compressor(sym) + case sym + when :closure + require 'closure-compiler' + Closure::Compiler.new + when :uglifier + require 'uglifier' + Uglifier.new + when :yui + require 'yui/compressor' + YUI::JavaScriptCompressor.new + else + sym + end + end + + def expand_css_compressor(sym) + case sym + when :scss + require 'sass' + compressor = Object.new + def compressor.compress(source) + Sass::Engine.new(source, + :syntax => :scss, :style => :compressed + ).render + end + compressor + when :yui + require 'yui/compressor' + YUI::JavaScriptCompressor.new(:munge => true) + else + sym + end + end end end |