diff --git a/middleman-core/lib/middleman-core/step_definitions/server_steps.rb b/middleman-core/lib/middleman-core/step_definitions/server_steps.rb index 141d9dae..81f32f92 100644 --- a/middleman-core/lib/middleman-core/step_definitions/server_steps.rb +++ b/middleman-core/lib/middleman-core/step_definitions/server_steps.rb @@ -12,6 +12,14 @@ Given /^"([^\"]*)" feature is "([^\"]*)"$/ do |feature, state| end end +Given /^"([^\"]*)" feature is "enabled" with "([^\"]*)"$/ do |feature, options_str| + @initialize_commands ||= [] + + options = eval("{#{options_str}}") + + @initialize_commands << lambda { activate(feature.to_sym, options) } +end + Given /^"([^\"]*)" is set to "([^\"]*)"$/ do |variable, value| @initialize_commands ||= [] @initialize_commands << lambda { set(variable.to_sym, value) } diff --git a/middleman-more/features/minify_javascript.feature b/middleman-more/features/minify_javascript.feature index 251fb90c..41ef8b19 100644 --- a/middleman-more/features/minify_javascript.feature +++ b/middleman-more/features/minify_javascript.feature @@ -78,7 +78,7 @@ Feature: Minify Javascript """ Scenario: Rendering inline js with the feature enabled - Given "minify_javascript" feature is "enabled" + Given "minify_javascript" feature is "enabled" with ":inline => true" And the Server is running at "minify-js-app" When I go to "/inline-js.html" Then I should see: @@ -115,7 +115,7 @@ Feature: Minify Javascript Then I should see "8" lines Scenario: Rendering inline js (coffeescript) with the feature enabled - Given "minify_javascript" feature is "enabled" + Given "minify_javascript" feature is "enabled" with ":inline => true" And the Server is running at "minify-js-app" When I go to "/inline-coffeescript.html" Then I should see "6" lines diff --git a/middleman-more/lib/middleman-more/extensions/minify_css.rb b/middleman-more/lib/middleman-more/extensions/minify_css.rb index 2f54a82e..af913613 100644 --- a/middleman-more/lib/middleman-more/extensions/minify_css.rb +++ b/middleman-more/lib/middleman-more/extensions/minify_css.rb @@ -12,6 +12,7 @@ module Middleman::Extensions app.set :css_compressor, false ignore = Array(options[:ignore]) << /\.min\./ + inline = options[:inline] || false app.after_configuration do unless respond_to?(:css_compressor) && css_compressor @@ -19,16 +20,18 @@ module Middleman::Extensions set :css_compressor, ::Rainpress end - # Setup Rack to watch for inline JS - use InlineCSSRack, :compressor => css_compressor, :ignore => ignore + # Setup Rack middleware to minify CSS + use MinifyCSSRack, :compressor => css_compressor, + :ignore => ignore, + :inline => inline end end alias :included :registered end end - # Rack middleware to look for JS in HTML and compress it - class InlineCSSRack + # Rack middleware to look for CSS and compress it + class MinifyCSSRack # Init # @param [Class] app @@ -37,6 +40,7 @@ module Middleman::Extensions @app = app @compressor = options[:compressor] @ignore = options[:ignore] + @inline = options[:inline] end # Rack interface @@ -47,7 +51,7 @@ module Middleman::Extensions path = env["PATH_INFO"] - if path.end_with?('.html') || path.end_with?('.php') + if (path.end_with?('.html') || path.end_with?('.php')) && @inline uncompressed_source = extract_response_text(response) minified = uncompressed_source.gsub(/(]*>\s*(?:\/\*\*\/)?\s*<\/style>)/m) do |match| diff --git a/middleman-more/lib/middleman-more/extensions/minify_javascript.rb b/middleman-more/lib/middleman-more/extensions/minify_javascript.rb index 405dcaed..21e7092f 100755 --- a/middleman-more/lib/middleman-more/extensions/minify_javascript.rb +++ b/middleman-more/lib/middleman-more/extensions/minify_javascript.rb @@ -12,6 +12,7 @@ module Middleman::Extensions app.set :js_compressor, false ignore = Array(options[:ignore]) << /\.min\./ + inline = options[:inline] || false # Once config is parsed app.after_configuration do @@ -20,15 +21,17 @@ module Middleman::Extensions set :js_compressor, ::Uglifier.new end - # Setup Rack to watch for inline JS - use InlineJavascriptRack, :compressor => js_compressor, :ignore => ignore + # Setup Rack middlware to minify JS + use MinifyJavascriptRack, :compressor => js_compressor, + :ignore => ignore, + :inline => inline end end alias :included :registered end - # Rack middleware to look for JS in HTML and compress it - class InlineJavascriptRack + # Rack middleware to look for JS and compress it + class MinifyJavascriptRack # Init # @param [Class] app @@ -37,6 +40,7 @@ module Middleman::Extensions @app = app @compressor = options[:compressor] @ignore = options[:ignore] + @inline = options[:inline] end # Rack interface @@ -48,7 +52,7 @@ module Middleman::Extensions path = env["PATH_INFO"] begin - if path.end_with?('.html') || path.end_with?('.php') + if (path.end_with?('.html') || path.end_with?('.php')) && @inline uncompressed_source = extract_response_text(response) minified = uncompressed_source.gsub(/(]*>\s*(?:\/\/(?:(?:)|(?:\]\]>)))?\s*<\/script>)/m) do |match|