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 | |
parent | ed2820d6ecef7533970952437b974c7fa10192e1 (diff) | |
download | rails-dab96a267eeccd7380ad99fa19cefdfd3cd5ad2b.tar.gz rails-dab96a267eeccd7380ad99fa19cefdfd3cd5ad2b.tar.bz2 rails-dab96a267eeccd7380ad99fa19cefdfd3cd5ad2b.zip |
Add shorthand for js and css compressors
-rw-r--r-- | actionpack/lib/sprockets/railtie.rb | 37 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 3 |
2 files changed, 40 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 diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index bd8c314da6..f818313955 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -35,6 +35,9 @@ module Rails @assets.paths = [] @assets.precompile = [ /\w+\.(?!js|css)$/, "application.js", "application.css" ] @assets.prefix = "/assets" + + @assets.js_compressor = nil + @assets.css_compressor = nil end def compiled_asset_path |