From ffe9226aac3992c4f9afc910e039cbaf41c91019 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Mon, 28 Apr 2014 10:21:14 -0700 Subject: [PATCH] Remove root config options for minification --- CHANGELOG.md | 2 ++ middleman-core/features/minify_css.feature | 8 ++---- .../features/minify_javascript.feature | 12 +++------ .../middleman-core/extensions/minify_css.rb | 24 ++++++++--------- .../extensions/minify_javascript.rb | 27 ++++++++----------- 5 files changed, 29 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57672727..31e38c34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ master === +* Removed `css_compressor` setting, use `activate :minify_css, :compressor =>` instead. +* Removed `js_compressor` setting, use `activate :minify_javascript, :compressor =>` instead. * Removed ability to server folders of content statically (non-Middleman projects). * Prevent local templates being loaded when $HOME is not set * Removed "Implied Extension feature" diff --git a/middleman-core/features/minify_css.feature b/middleman-core/features/minify_css.feature index 0c707861..e6bc948f 100644 --- a/middleman-core/features/minify_css.feature +++ b/middleman-core/features/minify_css.feature @@ -36,9 +36,7 @@ Feature: Minify CSS end end - activate :minify_css - - set :css_compressor, ::PassThrough + activate :minify_css, :compressor => ::PassThrough """ And the Server is running at "passthrough-app" When I go to "/stylesheets/site.css" @@ -71,9 +69,7 @@ Feature: Minify CSS end end - activate :minify_css, :inline => true - - set :css_compressor, ::PassThrough + activate :minify_css, :inline => true, :compressor => ::PassThrough page "/inline-css.html", :layout => false """ diff --git a/middleman-core/features/minify_javascript.feature b/middleman-core/features/minify_javascript.feature index 7d6b71ff..73e05f44 100644 --- a/middleman-core/features/minify_javascript.feature +++ b/middleman-core/features/minify_javascript.feature @@ -49,9 +49,7 @@ Feature: Minify Javascript end end - activate :minify_javascript, :inline => true - - set :js_compressor, ::PassThrough + activate :minify_javascript, :inline => true, :compressor => ::PassThrough page "/inline-js.html", :layout => false """ @@ -195,9 +193,7 @@ Feature: Minify Javascript end end - activate :minify_javascript, :inline => true - - set :js_compressor, ::PassThrough + activate :minify_javascript, :inline => true, :compressor => ::PassThrough page "/inline-coffeescript.html", :layout => false """ @@ -215,9 +211,7 @@ Feature: Minify Javascript end end - activate :minify_javascript - - set :js_compressor, ::PassThrough + activate :minify_javascript, :compressor => ::PassThrough """ And the Server is running at "passthrough-app" When I go to "/javascripts/coffee_test.js" diff --git a/middleman-core/lib/middleman-core/extensions/minify_css.rb b/middleman-core/lib/middleman-core/extensions/minify_css.rb index 1945f4c1..dcf89e91 100644 --- a/middleman-core/lib/middleman-core/extensions/minify_css.rb +++ b/middleman-core/lib/middleman-core/extensions/minify_css.rb @@ -1,20 +1,15 @@ # Minify CSS Extension class Middleman::Extensions::MinifyCss < ::Middleman::Extension - option :compressor, nil, 'Set the CSS compressor to use.' option :inline, false, 'Whether to minify CSS inline within HTML files' option :ignore, [], 'Patterns to avoid minifying' - - def initialize(app, options_hash={}, &block) - super - - app.config.define_setting :css_compressor, nil, 'Set the CSS compressor to use. Deprecated in favor of the :compressor option when activating :minify_css' - end + option :compressor, Proc.new { + require 'sass' + SassCompressor + }, 'Set the CSS compressor to use.' def after_configuration - chosen_compressor = app.config[:css_compressor] || options[:compressor] || SassCompressor - # Setup Rack middleware to minify CSS - app.use Rack, :compressor => chosen_compressor, + app.use Rack, :compressor => options[:compressor], :ignore => Array(options[:ignore]) + [/\.min\./], :inline => options[:inline] end @@ -36,9 +31,12 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension # @param [Hash] options def initialize(app, options={}) @app = app - @compressor = options[:compressor] - @ignore = options[:ignore] - @inline = options[:inline] + @ignore = options.fetch(:ignore) + @inline = options.fetch(:inline) + + @compressor = options.fetch(:compressor) + @compressor = @compressor.to_proc if @compressor.respond_to? :to_proc + @compressor = @compressor.call if @compressor.is_a? Proc end # Rack interface diff --git a/middleman-core/lib/middleman-core/extensions/minify_javascript.rb b/middleman-core/lib/middleman-core/extensions/minify_javascript.rb index ecacae4c..240e9a5d 100644 --- a/middleman-core/lib/middleman-core/extensions/minify_javascript.rb +++ b/middleman-core/lib/middleman-core/extensions/minify_javascript.rb @@ -1,23 +1,15 @@ # Minify Javascript Extension class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension - option :compressor, nil, 'Set the JS compressor to use.' option :inline, false, 'Whether to minify JS inline within HTML files' option :ignore, [], 'Patterns to avoid minifying' - - def initialize(app, options_hash={}, &block) - super - - app.config.define_setting :js_compressor, nil, 'Set the JS compressor to use. Deprecated in favor of the :compressor option when activating :minify_js' - end + option :compressor, Proc.new { + require 'uglifier' + ::Uglifier.new + }, 'Set the JS compressor to use.' def after_configuration - chosen_compressor = app.config[:js_compressor] || options[:compressor] || begin - require 'uglifier' - ::Uglifier.new - end - # Setup Rack middleware to minify CSS - app.use Rack, :compressor => chosen_compressor, + app.use Rack, :compressor => options[:compressor], :ignore => Array(options[:ignore]) + [/\.min\./], :inline => options[:inline] end @@ -30,9 +22,12 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension # @param [Hash] options def initialize(app, options={}) @app = app - @compressor = options[:compressor] - @ignore = options[:ignore] - @inline = options[:inline] + @ignore = options.fetch(:ignore) + @inline = options.fetch(:inline) + + @compressor = options.fetch(:compressor) + @compressor = @compressor.to_proc if @compressor.respond_to? :to_proc + @compressor = @compressor.call if @compressor.is_a? Proc end # Rack interface