Add a Middleman::Util.path_match function that handles matching on regexes, globs, and procs, and use it from asset_hash, minify_javascript, and minify_css. Fixes #480.

This commit is contained in:
Ben Hollis 2012-06-16 20:23:33 -07:00
parent 524fd49c47
commit 57f5701e72
4 changed files with 23 additions and 4 deletions

View file

@ -56,6 +56,25 @@ module Middleman
end
end
# Takes a matcher, which can be a literal string
# or a string containing glob expressions, or a
# regexp, or a proc, or anything else that responds
# to #match or #call, and returns whether or not the
# given path matches that matcher.
#
# @param matcher A matcher string/regexp/proc/etc
# @param path A path as a string
# @return [Boolean] Whether the path matches the matcher
def self.path_match(matcher, path)
if matcher.respond_to? :match
matcher.match path
elsif matcher.respond_to? :call
matcher.call path
else
File.fnmatch(matcher.to_s, path)
end
end
# Simple shared cache implementation
class Cache
# Initialize

View file

@ -32,7 +32,7 @@ module Middleman
def manipulate_resource_list(resources)
resources.each do |resource|
next unless @exts.include? resource.ext
next if @ignore.any? { |r| resource.destination_path.match(r) }
next if @ignore.any? { |ignore| Middleman::Util.path_match(ignore, resource.destination_path) }
if resource.template? # if it's a template, render it out
digest = Digest::SHA1.hexdigest(resource.render)[0..7]

View file

@ -66,7 +66,7 @@ module Middleman
headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
response = [minified]
elsif path.end_with?('.css') && @ignore.none? {|ignore| path =~ ignore }
elsif path.end_with?('.css') && @ignore.none? {|ignore| Middleman::Util.path_match(ignore, path) }
uncompressed_source = ::Middleman::Util.extract_response_text(response)
minified_css = @compressor.compress(uncompressed_source)

View file

@ -75,7 +75,7 @@ module Middleman
headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
response = [minified]
elsif path.end_with?('.js') && @ignore.none? {|ignore| path =~ ignore }
elsif path.end_with?('.js') && @ignore.none? {|ignore| Middleman::Util.path_match(ignore, path) }
uncompressed_source = ::Middleman::Util.extract_response_text(response)
minified_js = @compressor.compress(uncompressed_source)