Merge pull request #322 from bhollis/master

Fix ignore with a regex
This commit is contained in:
Thomas Reynolds 2012-03-25 11:17:27 -07:00
commit c69fac9028
2 changed files with 28 additions and 18 deletions

View file

@ -33,6 +33,26 @@ Feature: Ignoring paths
| build/reports/another.html |
| build/images/icons/messages.png |
Scenario: Ignore a regex
Given a fixture app "ignore-app"
And a file named "config.rb" with:
"""
ignore /^.*\.erb/
ignore /^reports\/.*/
ignore /^images\.*\.png/
"""
And a successfully built app at "ignore-app"
Then the following files should exist:
| build/plain.html |
| build/images/portrait.jpg |
| build/images/pic.png |
And the following files should not exist:
| build/about.html |
| build/index.html |
| build/reports/index.html |
| build/reports/another.html |
| build/images/icons/messages.png |
Scenario: Ignore with directory indexes (source file)
Given a fixture app "ignore-app"
And a file named "config.rb" with:

View file

@ -17,9 +17,6 @@ module Middleman::Sitemap
def initialize(app)
@app = app
@pages = {}
@ignored_paths = []
@ignored_globs = []
@ignored_regexes = []
@ignored_callbacks = []
@reroute_callbacks = []
end
@ -41,14 +38,15 @@ module Middleman::Sitemap
# @param [String, Regexp] path, path glob expression, or path regex
# @return [void]
def ignore(path=nil, &block)
if !path.nil? && path.include?("*")
path_clean = normalize_path(path)
@ignored_globs << path_clean unless @ignored_globs.include?(path_clean)
if path.is_a? Regexp
@ignored_callbacks << Proc.new {|p| p =~ path }
elsif path.is_a? String
path_clean = normalize_path(path)
@ignored_paths << path_clean unless @ignored_paths.include?(path_clean)
elsif path.is_a? Regexp
@ignored_regexes << path unless @ignored_regexes.include?(path)
if path_clean.include?("*") # It's a glob
@ignored_callbacks << Proc.new {|p| File.fnmatch(path_clean, p) }
else
@ignored_callbacks << Proc.new {|p| p == path_clean }
end
elsif block_given?
@ignored_callbacks << block
end
@ -107,15 +105,7 @@ module Middleman::Sitemap
# @return [Boolean]
def ignored?(path)
path_clean = normalize_path(path)
return true if @ignored_paths.include?(path_clean)
return true if @ignored_globs.any? { |g| File.fnmatch(g, path_clean) }
return true if @ignored_regexes.any? { |r| r.match(path_clean) }
return true if @ignored_callbacks.any? { |b| b.call(path_clean) }
# TODO: We should also check ignored_sitemap_matchers here
false
@ignored_callbacks.any? { |b| b.call(path_clean) }
end
# Remove a file from the store