diff --git a/lib/jekyll/core_ext.rb b/lib/jekyll/core_ext.rb index dd9af277..43edcb13 100644 --- a/lib/jekyll/core_ext.rb +++ b/lib/jekyll/core_ext.rb @@ -53,21 +53,3 @@ class Hash dup.symbolize_keys! end end - -module Enumerable - def ensure_leading_slash(path) - path[0..0] == "/" ? path : "/#{path}" - end - - # Returns true if path matches against any glob pattern. - # Look for more detail about glob pattern in method File::fnmatch. - def glob_include?(e) - entry = ensure_leading_slash(e) - any? do |exp| - item = ensure_leading_slash(exp) - Jekyll.logger.debug "glob_include?(#{entry})" - Jekyll.logger.debug " ==> File.fnmatch?(#{item}, #{entry}) == #{File.fnmatch?(item, entry)}" - File.fnmatch?(item, entry) - end - end -end diff --git a/lib/jekyll/entry_filter.rb b/lib/jekyll/entry_filter.rb index 6ecca92d..11db9e11 100644 --- a/lib/jekyll/entry_filter.rb +++ b/lib/jekyll/entry_filter.rb @@ -31,7 +31,7 @@ module Jekyll end def included?(entry) - site.include.glob_include?(entry) + glob_include?(site.include, entry) end def special?(entry) @@ -43,7 +43,7 @@ module Jekyll end def excluded?(entry) - excluded = site.exclude.glob_include?(relative_to_source(entry)) + excluded = glob_include?(site.exclude, relative_to_source(entry)) Jekyll.logger.debug "excluded?(#{relative_to_source(entry)}) ==> #{excluded}" excluded end @@ -51,5 +51,21 @@ module Jekyll def symlink?(entry) File.symlink?(entry) && site.safe end + + def ensure_leading_slash(path) + path[0..0] == "/" ? path : "/#{path}" + end + + # Returns true if path matches against any glob pattern. + # Look for more detail about glob pattern in method File::fnmatch. + def glob_include?(enum, e) + entry = ensure_leading_slash(e) + enum.any? do |exp| + item = ensure_leading_slash(exp) + Jekyll.logger.debug "glob_include?(#{entry})" + Jekyll.logger.debug " ==> File.fnmatch?(#{item}, #{entry}) == #{File.fnmatch?(item, entry)}" + File.fnmatch?(item, entry) + end + end end end diff --git a/test/test_core_ext.rb b/test/test_core_ext.rb index 5eb77e34..c3e62cb5 100644 --- a/test/test_core_ext.rb +++ b/test/test_core_ext.rb @@ -63,32 +63,4 @@ 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 - - should "match even if there is no leading slash" do - data = ['vendor/bundle'] - assert data.glob_include?('/vendor/bundle') - assert data.glob_include?('vendor/bundle') - end - end - end end diff --git a/test/test_entry_filter.rb b/test/test_entry_filter.rb index f5e02174..ce50b6a8 100644 --- a/test/test_entry_filter.rb +++ b/test/test_entry_filter.rb @@ -71,4 +71,38 @@ class TestEntryFilter < Test::Unit::TestCase assert_not_equal [], site.static_files end end + + context "glob_include?" do + setup do + stub(Jekyll).configuration do + Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir}) + end + @site = Site.new(Jekyll.configuration) + @filter = EntryFilter.new(@site) + end + + should "return false with no glob patterns" do + assert !@filter.glob_include?([], "a.txt") + end + + should "return false with all not match path" do + data = ["a*", "b?"] + assert !@filter.glob_include?(data, "ca.txt") + assert !@filter.glob_include?(data, "ba.txt") + end + + should "return true with match path" do + data = ["a*", "b?", "**/a*"] + assert @filter.glob_include?(data, "a.txt") + assert @filter.glob_include?(data, "ba") + assert @filter.glob_include?(data, "c/a/a.txt") + assert @filter.glob_include?(data, "c/a/b/a.txt") + end + + should "match even if there is no leading slash" do + data = ['vendor/bundle'] + assert @filter.glob_include?(data, '/vendor/bundle') + assert @filter.glob_include?(data, 'vendor/bundle') + end + end end