From cc3aebf5ccbad432b1149e081fc24305a0579a67 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Thu, 26 Apr 2012 14:15:35 -0700 Subject: [PATCH] Allow compressor to be passed to minify extensions as an activate option --- middleman-more/features/minify_css.feature | 25 ++++++++++++- .../features/minify_javascript.feature | 36 +++++++++++++++++++ .../middleman-more/extensions/minify_css.rb | 6 ++-- .../extensions/minify_javascript.rb | 6 ++-- 4 files changed, 66 insertions(+), 7 deletions(-) diff --git a/middleman-more/features/minify_css.feature b/middleman-more/features/minify_css.feature index 78a8d5e9..aaccf677 100644 --- a/middleman-more/features/minify_css.feature +++ b/middleman-more/features/minify_css.feature @@ -22,7 +22,7 @@ Feature: Minify CSS Then I should see "1" lines And I should see "only screen and (device-width" When I go to "/more-css/site.css" - Then I should see "1" lines + Then I should see "1" lines Scenario: Rendering external css with passthrough compressor Given a fixture app "passthrough-app" @@ -88,6 +88,29 @@ Feature: Minify CSS """ + Scenario: Rendering inline css with a passthrough minifier using activate-style compressor + Given a fixture app "passthrough-app" + And a file named "config.rb" with: + """ + module ::HelloCompressor + def self.compress(data) + "Hello" + end + end + + activate :minify_css, :inline => true, :compressor => ::HelloCompressor + + page "/inline-css.html", :layout => false + """ + And the Server is running at "passthrough-app" + When I go to "/inline-css.html" + Then I should see: + """ + + """ + Scenario: Rendering inline css with the feature enabled Given a fixture app "minify-css-app" And a file named "config.rb" with: diff --git a/middleman-more/features/minify_javascript.feature b/middleman-more/features/minify_javascript.feature index e4366b2f..06795274 100644 --- a/middleman-more/features/minify_javascript.feature +++ b/middleman-more/features/minify_javascript.feature @@ -92,6 +92,42 @@ Feature: Minify Javascript """ + Scenario: Rendering inline css with a passthrough minifier using activate-style compressor + Given a fixture app "passthrough-app" + And a file named "config.rb" with: + """ + module ::HelloCompressor + def self.compress(data) + "Hello" + end + end + + activate :minify_javascript, :inline => true, :compressor => ::HelloCompressor + + page "/inline-js.html", :layout => false + """ + And the Server is running at "passthrough-app" + When I go to "/inline-js.html" + Then I should see: + """ + + + + + """ + Scenario: Rendering inline js with the feature enabled Given a fixture app "minify-js-app" And a file named "config.rb" with: diff --git a/middleman-more/lib/middleman-more/extensions/minify_css.rb b/middleman-more/lib/middleman-more/extensions/minify_css.rb index af913613..5f3ea461 100644 --- a/middleman-more/lib/middleman-more/extensions/minify_css.rb +++ b/middleman-more/lib/middleman-more/extensions/minify_css.rb @@ -15,13 +15,13 @@ module Middleman::Extensions inline = options[:inline] || false app.after_configuration do - unless respond_to?(:css_compressor) && css_compressor + chosen_compressor = css_compressor || options[:compressor] || begin require "middleman-more/extensions/minify_css/rainpress" - set :css_compressor, ::Rainpress + ::Rainpress end # Setup Rack middleware to minify CSS - use MinifyCSSRack, :compressor => css_compressor, + use MinifyCSSRack, :compressor => chosen_compressor, :ignore => ignore, :inline => inline end diff --git a/middleman-more/lib/middleman-more/extensions/minify_javascript.rb b/middleman-more/lib/middleman-more/extensions/minify_javascript.rb index 21e7092f..f8ddd478 100755 --- a/middleman-more/lib/middleman-more/extensions/minify_javascript.rb +++ b/middleman-more/lib/middleman-more/extensions/minify_javascript.rb @@ -16,13 +16,13 @@ module Middleman::Extensions # Once config is parsed app.after_configuration do - unless respond_to?(:js_compressor) && js_compressor + chosen_compressor = js_compressor || options[:compressor] || begin require 'uglifier' - set :js_compressor, ::Uglifier.new + ::Uglifier.new end # Setup Rack middlware to minify JS - use MinifyJavascriptRack, :compressor => js_compressor, + use MinifyJavascriptRack, :compressor => chosen_compressor, :ignore => ignore, :inline => inline end