From d1c71e473d14ea186d7569c738a857babe36f225 Mon Sep 17 00:00:00 2001 From: Ian MacLeod Date: Mon, 9 Jun 2014 17:34:33 -0700 Subject: [PATCH 1/6] `Rubocop` is now `RuboCop` See https://github.com/bbatsov/rubocop/commit/ff167d8f202baf7a68955db0aaf0dc29afb7e7ee --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 05da4ae9..5176f04e 100644 --- a/Rakefile +++ b/Rakefile @@ -58,7 +58,7 @@ end require 'rubocop/rake_task' desc 'Run RuboCop to check code consistency' -Rubocop::RakeTask.new(:rubocop) do |task| +RuboCop::RakeTask.new(:rubocop) do |task| task.fail_on_error = false end From fe5247d9d9482858f6753531ad1e135afe6366b5 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Mon, 16 Jun 2014 08:57:56 -0700 Subject: [PATCH 2/6] Add to 404 so Livereload can add its script to the page --- middleman-core/lib/middleman-core/core_extensions/request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleman-core/lib/middleman-core/core_extensions/request.rb b/middleman-core/lib/middleman-core/core_extensions/request.rb index e78f0ffe..aabb708e 100644 --- a/middleman-core/lib/middleman-core/core_extensions/request.rb +++ b/middleman-core/lib/middleman-core/core_extensions/request.rb @@ -281,7 +281,7 @@ module Middleman # Halt request and return 404 def not_found(res, path) res.status = 404 - res.write "

File Not Found

#{path}

" + res.write "

File Not Found

#{path}

" res.finish end From 5c991ba4dc8d2af9cf373b90df2eb1ecc92f2993 Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Sun, 22 Jun 2014 20:46:39 -0700 Subject: [PATCH 3/6] Add a protective require --- middleman-core/lib/middleman-core/extension.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/middleman-core/lib/middleman-core/extension.rb b/middleman-core/lib/middleman-core/extension.rb index 887a05fb..48653bef 100644 --- a/middleman-core/lib/middleman-core/extension.rb +++ b/middleman-core/lib/middleman-core/extension.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/class/attribute' +require 'middleman-core/configuration' module Middleman class Extension From 13ba9dae62f46b850cbd8565b85c9d197a4f020a Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Tue, 24 Jun 2014 13:34:24 -0700 Subject: [PATCH 4/6] Make option documentation consistent. --- middleman-core/lib/middleman-more/extensions/asset_hash.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleman-core/lib/middleman-more/extensions/asset_hash.rb b/middleman-core/lib/middleman-more/extensions/asset_hash.rb index b087cff2..3f915033 100644 --- a/middleman-core/lib/middleman-more/extensions/asset_hash.rb +++ b/middleman-core/lib/middleman-more/extensions/asset_hash.rb @@ -2,7 +2,7 @@ require 'middleman-core/util' class Middleman::Extensions::AssetHash < ::Middleman::Extension option :exts, %w(.jpg .jpeg .png .gif .js .css .otf .woff .eot .ttf .svg), 'List of extensions that get asset hashes appended to them.' - option :ignore, [], 'Regexes of filenames to skip adding asset hashes to' + option :ignore, [], 'Patterns to avoid adding asset hashes to' def initialize(app, options_hash={}, &block) super From b819d383588dd45d02874b279ed50f1372ccedda Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Fri, 2 May 2014 10:19:18 -0700 Subject: [PATCH 5/6] Test gzip extensions option. --- middleman-core/features/gzip.feature | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/middleman-core/features/gzip.feature b/middleman-core/features/gzip.feature index 93ae2cf5..9240b05b 100644 --- a/middleman-core/features/gzip.feature +++ b/middleman-core/features/gzip.feature @@ -3,12 +3,12 @@ Feature: GZIP assets during build Scenario: Built assets should be gzipped Given a successfully built app at "gzip-app" Then the following files should exist: - | build/javascripts/test.js.gz | - | build/stylesheets/test.css.gz | + | build/index.html | | build/index.html.gz | | build/javascripts/test.js | + | build/javascripts/test.js.gz | | build/stylesheets/test.css | - | build/index.html | + | build/stylesheets/test.css.gz | When I run `file build/javascripts/test.js.gz` Then the output should contain "gzip" @@ -18,4 +18,19 @@ Feature: GZIP assets during build Then I should see "test_function" When I go to "/stylesheets/test.css" Then I should see "test_selector" - \ No newline at end of file + + Scenario: Only specified extensions should be gzipped + Given a fixture app "gzip-app" + And a file named "config.rb" with: + """ + activate :gzip, exts: %w(.js .html .htm) + """ + And a successfully built app at "gzip-app" + Then the following files should exist: + | build/index.html | + | build/index.html.gz | + | build/javascripts/test.js | + | build/javascripts/test.js.gz | + | build/stylesheets/test.css | + And the following files should not exist: + | build/stylesheets/test.css.gz | From 429e7d64bd306c5139748ad578c47616bc4dfef2 Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Fri, 2 May 2014 11:41:59 -0700 Subject: [PATCH 6/6] Accept list of paths to exclude from gzipping. --- middleman-core/features/gzip.feature | 16 ++++++++++++++++ .../lib/middleman-more/extensions/gzip.rb | 12 +++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/middleman-core/features/gzip.feature b/middleman-core/features/gzip.feature index 9240b05b..5a5a4265 100644 --- a/middleman-core/features/gzip.feature +++ b/middleman-core/features/gzip.feature @@ -34,3 +34,19 @@ Feature: GZIP assets during build | build/stylesheets/test.css | And the following files should not exist: | build/stylesheets/test.css.gz | + + Scenario: Gzipped files are not produced for ignored paths + Given a fixture app "gzip-app" + And a file named "config.rb" with: + """ + activate :gzip, ignore: ['index.html', %r(javascripts/.*)] + """ + And a successfully built app at "gzip-app" + Then the following files should exist: + | build/index.html | + | build/javascripts/test.js | + | build/stylesheets/test.css | + | build/stylesheets/test.css.gz | + And the following files should not exist: + | build/index.html.gz | + | build/javascripts/test.js.gz | diff --git a/middleman-core/lib/middleman-more/extensions/gzip.rb b/middleman-core/lib/middleman-more/extensions/gzip.rb index 21b40f06..ed875d19 100644 --- a/middleman-core/lib/middleman-more/extensions/gzip.rb +++ b/middleman-core/lib/middleman-more/extensions/gzip.rb @@ -11,6 +11,7 @@ # class Middleman::Extensions::Gzip < ::Middleman::Extension option :exts, %w(.js .css .html .htm), 'File extensions to Gzip when building.' + option :ignore, [], 'Patterns to avoid gzipping' def initialize(app, options_hash={}) super @@ -29,7 +30,7 @@ class Middleman::Extensions::Gzip < ::Middleman::Extension # Fill a queue with inputs in_queue = Queue.new paths.each do |path| - in_queue << path if options.exts.include?(path.extname) + in_queue << path if should_gzip?(path) end num_paths = in_queue.size @@ -93,4 +94,13 @@ class Middleman::Extensions::Gzip < ::Middleman::Extension [output_filename, old_size, new_size] end + + private + + # Whether a path should be gzipped + # @param [Pathname] path A destination path + # @return [Boolean] + def should_gzip?(path) + options.exts.include?(path.extname) && options.ignore.none? { |ignore| Middleman::Util.path_match(ignore, path.to_s) } + end end