Permalink
Browse files

Add shorthand for js and css compressors

  • Loading branch information...
1 parent ed2820d commit dab96a267eeccd7380ad99fa19cefdfd3cd5ad2b @josh josh committed Apr 22, 2011
Showing with 40 additions and 0 deletions.
  1. +37 −0 actionpack/lib/sprockets/railtie.rb
  2. +3 −0 railties/lib/rails/application/configuration.rb
@@ -57,7 +57,44 @@ def asset_environment(app)
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)
@lucasmazza
lucasmazza May 16, 2011 Member

Why not YUI::CssCompressor ?

@josevalim
josevalim May 16, 2011 Member

Yeah, that is a bug. And a embarrassing one. Pull request with a fix please?

+ else
+ sym
+ end
+ end
end
end
@@ -35,6 +35,9 @@ def initialize(*)
@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

0 comments on commit dab96a2

Please sign in to comment.