Merge branch 'master' of github.com:mojombo/jekyll
* 'master' of github.com:mojombo/jekyll: add Enumerable#glob_include? fixed a syntax error use any? instead update test for include,exclude glob support Update test/test_site.rb Update lib/jekyll/site.rb add regexp support for option 'include','exclude'
This commit is contained in:
commit
963721fb46
|
@ -50,3 +50,11 @@ class Date
|
|||
strftime("%Y-%m-%dT%H:%M:%S%Z")
|
||||
end if RUBY_VERSION < '1.9'
|
||||
end
|
||||
|
||||
module Enumerable
|
||||
# Returns true if path matches against any glob pattern.
|
||||
# Look for more detail about glob pattern in method File::fnmatch.
|
||||
def glob_include?(e)
|
||||
any? { |exp| File.fnmatch?(exp, e) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -335,10 +335,10 @@ module Jekyll
|
|||
# Returns the Array of filtered entries.
|
||||
def filter_entries(entries)
|
||||
entries.reject do |e|
|
||||
unless self.include.include?(e)
|
||||
unless self.include.glob_include?(e)
|
||||
['.', '_', '#'].include?(e[0..0]) ||
|
||||
e[-1..-1] == '~' ||
|
||||
self.exclude.include?(e) ||
|
||||
self.exclude.glob_include?(e) ||
|
||||
File.symlink?(e)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -63,4 +63,26 @@ class TestCoreExt < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
context "enumerable" do
|
||||
context "glob_include?" do
|
||||
should "return false with no glob patterns" do
|
||||
assert ![].glob_include?("a.txt")
|
||||
end
|
||||
|
||||
should "return false with all not match path" do
|
||||
data = ["a*", "b?"]
|
||||
assert !data.glob_include?("ca.txt")
|
||||
assert !data.glob_include?("ba.txt")
|
||||
end
|
||||
|
||||
should "return true with match path" do
|
||||
data = ["a*", "b?", "**/a*"]
|
||||
assert data.glob_include?("a.txt")
|
||||
assert data.glob_include?("ba")
|
||||
assert data.glob_include?("c/a/a.txt")
|
||||
assert data.glob_include?("c/a/b/a.txt")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -154,13 +154,13 @@ class TestSite < Test::Unit::TestCase
|
|||
excludes = %w[README TODO]
|
||||
files = %w[index.html site.css .htaccess]
|
||||
|
||||
@site.exclude = excludes
|
||||
assert_equal files, @site.filter_entries(excludes + files)
|
||||
@site.exclude = excludes + ["exclude*"]
|
||||
assert_equal files, @site.filter_entries(excludes + files + ["excludeA"])
|
||||
end
|
||||
|
||||
should "not filter entries within include" do
|
||||
includes = %w[_index.html .htaccess]
|
||||
files = %w[index.html _index.html .htaccess]
|
||||
includes = %w[_index.html .htaccess include*]
|
||||
files = %w[index.html _index.html .htaccess includeA]
|
||||
|
||||
@site.include = includes
|
||||
assert_equal files, @site.filter_entries(files)
|
||||
|
|
Loading…
Reference in New Issue