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..f6e15a8 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(:munge => true) + compressor.compress(input_string) + end + end # module Engines end