Merge pull request #489 from bhollis/match
Add a Middleman::Util.path_match function and use it
This commit is contained in:
commit
bdfc270367
|
@ -56,6 +56,25 @@ module Middleman
|
||||||
end
|
end
|
||||||
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
|
# Simple shared cache implementation
|
||||||
class Cache
|
class Cache
|
||||||
# Initialize
|
# Initialize
|
||||||
|
|
|
@ -32,7 +32,7 @@ module Middleman
|
||||||
def manipulate_resource_list(resources)
|
def manipulate_resource_list(resources)
|
||||||
resources.each do |resource|
|
resources.each do |resource|
|
||||||
next unless @exts.include? resource.ext
|
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
|
if resource.template? # if it's a template, render it out
|
||||||
digest = Digest::SHA1.hexdigest(resource.render)[0..7]
|
digest = Digest::SHA1.hexdigest(resource.render)[0..7]
|
||||||
|
|
|
@ -66,7 +66,7 @@ module Middleman
|
||||||
|
|
||||||
headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
|
headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
|
||||||
response = [minified]
|
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)
|
uncompressed_source = ::Middleman::Util.extract_response_text(response)
|
||||||
minified_css = @compressor.compress(uncompressed_source)
|
minified_css = @compressor.compress(uncompressed_source)
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ module Middleman
|
||||||
|
|
||||||
headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
|
headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
|
||||||
response = [minified]
|
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)
|
uncompressed_source = ::Middleman::Util.extract_response_text(response)
|
||||||
minified_js = @compressor.compress(uncompressed_source)
|
minified_js = @compressor.compress(uncompressed_source)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue