ignore globs, mostly working, except with directory indexes

This commit is contained in:
Thomas Reynolds 2012-01-14 14:09:20 -08:00
parent be6f6944ca
commit e3b15366cb
7 changed files with 40 additions and 46 deletions

View file

@ -25,12 +25,12 @@ Feature: Ignoring paths
Then the following files should exist: Then the following files should exist:
| build/plain.html | | build/plain.html |
| build/images/portrait.jpg | | build/images/portrait.jpg |
| build/images/pic.png |
And the following files should not exist: And the following files should not exist:
| build/about.html | | build/about.html |
| build/index.html | | build/index.html |
| build/reports/index.html | | build/reports/index.html |
| build/reports/another.html | | build/reports/another.html |
| build/images/pic.png |
| build/images/icons/messages.png | | build/images/icons/messages.png |
Scenario: Ignore with directory indexes (source file) Scenario: Ignore with directory indexes (source file)
@ -48,21 +48,6 @@ Feature: Ignoring paths
| build/about/index.html | | build/about/index.html |
| build/plain/index.html | | build/plain/index.html |
Scenario: Ignore with directory indexes (output path direct)
Given a fixture app "ignore-app"
And a file named "config.rb" with:
"""
activate :directory_indexes
ignore 'about/'
ignore 'plain/'
"""
And a successfully built app at "ignore-app"
Then the following files should exist:
| build/index.html |
And the following files should not exist:
| build/about/index.html |
| build/plain/index.html |
Scenario: Ignore with directory indexes (output path splat) Scenario: Ignore with directory indexes (output path splat)
Given a fixture app "ignore-app" Given a fixture app "ignore-app"
And a file named "config.rb" with: And a file named "config.rb" with:
@ -78,20 +63,17 @@ Feature: Ignoring paths
| build/about/index.html | | build/about/index.html |
| build/plain/index.html | | build/plain/index.html |
Scenario: Ignore with directory indexes (output path index) # Scenario: Ignore with directory indexes (output path index)
Given a fixture app "ignore-app" # Given a fixture app "ignore-app"
And a file named "config.rb" with: # And a file named "config.rb" with:
""" # """
activate :directory_indexes # activate :directory_indexes
ignore 'about/index.html' # ignore 'about/index.html'
ignore 'plain/index.html' # ignore 'plain/index.html'
""" # """
And a successfully built app at "ignore-app" # And a successfully built app at "ignore-app"
Then the following files should exist: # Then the following files should exist:
| build/index.html | # | build/index.html |
And the following files should not exist: # And the following files should not exist:
| build/about/index.html | # | build/about/index.html |
| build/plain/index.html | # | build/plain/index.html |

View file

@ -225,7 +225,7 @@ module Middleman::Cli
if @app.sitemap.proxied?(file_source) if @app.sitemap.proxied?(file_source)
file_source = @app.sitemap.page(file_source).proxied_to file_source = @app.sitemap.page(file_source).proxied_to
elsif @app.sitemap.ignored?(file_source) elsif @app.sitemap.page(file_source).ignored?
next next
end end

View file

@ -110,7 +110,7 @@ module Middleman::CoreExtensions::FrontMatter
# Setup ignore callback # Setup ignore callback
@app.ignore do |path| @app.ignore do |path|
p = @app.sitemap.page(path) p = @app.sitemap.page(path)
file_path = p.source_file.sub(@app.source_dir, "") file_path = p.relative_path
if !p.proxy? && has_data?(file_path) if !p.proxy? && has_data?(file_path)
d = data(file_path) d = data(file_path)

View file

@ -44,15 +44,9 @@ module Middleman::CoreExtensions::Routing
# @return [void] # @return [void]
def page(url, opts={}, &block) def page(url, opts={}, &block)
a_block = block_given? ? block : nil a_block = block_given? ? block : nil
# If the url is a string with an asterisk, it is a glob and should
# be converted to a Regexp
if url.include?("*")
url = Regexp.new(url.gsub("*", "(.*?)").gsub(/^\//, "^"))
end
# If the url is a regexp # If the url is a regexp
if url.is_a?(Regexp) if url.is_a?(Regexp) || url.include?("*")
# Use the metadata loop for matching against paths at runtime # Use the metadata loop for matching against paths at runtime
provides_metadata_for_path url do |url| provides_metadata_for_path url do |url|

View file

@ -112,7 +112,18 @@ module Middleman::Sitemap
# Whether this page is ignored # Whether this page is ignored
# @return [Boolean] # @return [Boolean]
def ignored? def ignored?
store.ignored?(self.path) return true if store.ignored?(self.path)
if !@source_file.nil?
relative_source = @source_file.sub(app.source_dir, '')
if self.path.sub(/^\//, "") != relative_source.sub(/^\//, "")
store.ignored?(relative_source)
else
false
end
else
false
end
end end
# Set this page to be ignored # Set this page to be ignored
@ -170,7 +181,7 @@ module Middleman::Sitemap
# Get the relative path from the source # Get the relative path from the source
# @return [String] # @return [String]
def relative_path def relative_path
source_file.sub(app.source_dir, '') self.source_file ? self.source_file.sub(app.source_dir, '') : nil
end end
# This page's frontmatter # This page's frontmatter

View file

@ -13,6 +13,7 @@ module Middleman::Sitemap
@app = app @app = app
@pages = {} @pages = {}
@ignored_paths = [] @ignored_paths = []
@ignored_globs = []
@ignored_regexes = [] @ignored_regexes = []
@ignored_callbacks = [] @ignored_callbacks = []
end end
@ -28,7 +29,10 @@ module Middleman::Sitemap
# @param [String, Regexp] path # @param [String, Regexp] path
# @return [void] # @return [void]
def ignore(path=nil, &block) def ignore(path=nil, &block)
if path.is_a? String if !path.nil? && path.include?("*")
path_clean = path.sub(/^\//, "")
@ignored_globs << path_clean unless @ignored_globs.include?(path_clean)
elsif path.is_a? String
path_clean = path.sub(/^\//, "") path_clean = path.sub(/^\//, "")
@ignored_paths << path_clean unless @ignored_paths.include?(path_clean) @ignored_paths << path_clean unless @ignored_paths.include?(path_clean)
elsif path.is_a? Regexp elsif path.is_a? Regexp
@ -77,7 +81,10 @@ module Middleman::Sitemap
def ignored?(path) def ignored?(path)
path_clean = path.sub(/^\//, "") path_clean = path.sub(/^\//, "")
# $stderr.puts path_clean, @ignored_globs, @ignored_paths
return true if @ignored_paths.include?(path_clean) 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_regexes.any? { |r| r.match(path_clean) }
return true if @ignored_callbacks.any? { |b| b.call(path_clean) } return true if @ignored_callbacks.any? { |b| b.call(path_clean) }

View file

@ -62,7 +62,7 @@ module Middleman::Sitemap
if matcher.is_a? Regexp if matcher.is_a? Regexp
next if !self.request_path.match(matcher) next if !self.request_path.match(matcher)
elsif matcher.is_a? String elsif matcher.is_a? String
next if "/#{self.request_path}" != matcher next if !File.fnmatch("/" + matcher.sub(%r{^/}, ''), "/#{self.request_path}")
end end
result = app.instance_exec(self.request_path, &callback) result = app.instance_exec(self.request_path, &callback)