From fa0b78a35e7cc4ad5212b410c9692ab8919b83e3 Mon Sep 17 00:00:00 2001 From: Dinesh Majrekar Date: Thu, 9 Jun 2011 13:17:46 +0100 Subject: [PATCH 1/2] Added YuiCompressor as an available engine for CSS and JS minification - https://github.com/sstephenson/ruby-yui-compressor/ --- asset_hat.gemspec | 3 +++ lib/asset_hat/css.rb | 14 +++++++++++++- lib/asset_hat/js.rb | 15 ++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/asset_hat.gemspec b/asset_hat.gemspec index d138779..dce9d36 100644 --- a/asset_hat.gemspec +++ b/asset_hat.gemspec @@ -113,6 +113,7 @@ Gem::Specification.new do |s| s.add_development_dependency(%q, ["~> 2.10.2"]) s.add_runtime_dependency(%q, ["~> 1.0.2"]) s.add_runtime_dependency(%q, ["~> 1.0.1"]) + s.add_runtime_dependency(%q, ["~> 0.9.6"]) else s.add_dependency(%q, ["~> 0.8.6"]) s.add_dependency(%q, ["~> 0.1.12"]) @@ -120,6 +121,7 @@ Gem::Specification.new do |s| s.add_dependency(%q, ["~> 2.10.2"]) s.add_dependency(%q, ["~> 1.0.2"]) s.add_dependency(%q, ["~> 1.0.1"]) + s.add_dependency(%q, ["~> 0.9.6"]) end else s.add_dependency(%q, ["~> 0.8.6"]) @@ -128,6 +130,7 @@ Gem::Specification.new do |s| s.add_dependency(%q, ["~> 2.10.2"]) s.add_dependency(%q, ["~> 1.0.2"]) s.add_dependency(%q, ["~> 1.0.1"]) + s.add_dependency(%q, ["~> 0.9.6"]) end end diff --git a/lib/asset_hat/css.rb b/lib/asset_hat/css.rb index b68e74e..b2911b1 100644 --- a/lib/asset_hat/css.rb +++ b/lib/asset_hat/css.rb @@ -1,11 +1,12 @@ require 'cssmin' +require 'yui/compressor' module AssetHat # Methods for minifying and optimizing CSS. module CSS # A list of supported minification # engine names. - ENGINES = [:weak, :cssmin] + ENGINES = [:weak, :cssmin, :yui] # Returns the expected path for the minified version of a CSS asset: # @@ -121,6 +122,17 @@ def self.cssmin(input_string) output end + + # Ruby-YUI Compressor provides a Ruby interface to the YUI Compressor + # Java library for minifying JavaScript and CSS assets. + # + # Sources: + # - http://github.com/sstephenson/ruby-yui-compressor/ + # - http://rubygems.org/gems/yui-compressor + def self.yui(input_string) + compressor = YUI::CssCompressor.new + compressor.compress(input_string) + end end diff --git a/lib/asset_hat/js.rb b/lib/asset_hat/js.rb index c308245..37819e2 100644 --- a/lib/asset_hat/js.rb +++ b/lib/asset_hat/js.rb @@ -1,4 +1,5 @@ require 'jsmin' +require 'yui/compressor' require File.join(File.dirname(__FILE__), 'js', 'vendors') module AssetHat @@ -6,7 +7,7 @@ module AssetHat module JS # A list of supported minification # engine names. - ENGINES = [:weak, :jsmin] + ENGINES = [:weak, :jsmin, :yui] # A list of supported # 3rd-party JavaScript plugin/vendor names. @@ -79,6 +80,18 @@ def self.weak(input_string) def self.jsmin(input_string) JSMin.minify(input_string + "\n") end + + # Ruby-YUI Compressor provides a Ruby interface to the YUI Compressor + # Java library for minifying JavaScript and CSS assets. + # + # Sources: + # - http://github.com/sstephenson/ruby-yui-compressor/ + # - http://rubygems.org/gems/yui-compressor + def self.yui(input_string) + compressor = YUI::JavaScriptCompressor.new + compressor.compress(input_string) + end + end # module Engines end From 7467b70f190b9a2a4bdb58008d99f05d34aee0e6 Mon Sep 17 00:00:00 2001 From: Dinesh Majrekar Date: Thu, 16 Jun 2011 16:29:24 +0100 Subject: [PATCH 2/2] Added a munge option when compressing JS with YUI --- lib/asset_hat/js.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/asset_hat/js.rb b/lib/asset_hat/js.rb index 37819e2..f6e15a8 100644 --- a/lib/asset_hat/js.rb +++ b/lib/asset_hat/js.rb @@ -88,7 +88,7 @@ def self.jsmin(input_string) # - http://github.com/sstephenson/ruby-yui-compressor/ # - http://rubygems.org/gems/yui-compressor def self.yui(input_string) - compressor = YUI::JavaScriptCompressor.new + compressor = YUI::JavaScriptCompressor.new(:munge => true) compressor.compress(input_string) end