Add Windows support to Utils.safe_glob
This commit is contained in:
parent
20735e12f9
commit
e9f8b4df74
|
@ -40,7 +40,7 @@ module Jekyll
|
|||
regex = keep_file_regex
|
||||
dirs = keep_dirs
|
||||
|
||||
Utils.safe_glob(site.in_dest_dir, "**/*", File::FNM_DOTMATCH).each do |file|
|
||||
Utils.safe_glob(site.in_dest_dir, ["**", "*"], File::FNM_DOTMATCH).each do |file|
|
||||
next if file =~ HIDDEN_FILE_REGEX || file =~ regex || dirs.include?(file)
|
||||
files << file
|
||||
end
|
||||
|
|
|
@ -74,7 +74,7 @@ module Jekyll
|
|||
def entries
|
||||
return Array.new unless exists?
|
||||
@entries ||=
|
||||
Utils.safe_glob(collection_dir, "**/*.*").map do |entry|
|
||||
Utils.safe_glob(collection_dir, ["**", "*.*"]).map do |entry|
|
||||
entry["#{collection_dir}/"] = ''; entry
|
||||
end
|
||||
end
|
||||
|
|
|
@ -222,15 +222,19 @@ module Jekyll
|
|||
# safe_glob("path", "*", File::FNM_DOTMATCH)
|
||||
# # => ["path/.", "path/..", "path/file1"]
|
||||
#
|
||||
# dir - the dir where glob will be executed under
|
||||
# safe_glob("path", ["**", "*"])
|
||||
# # => ["path[/file1", "path[/folder/file2"]
|
||||
#
|
||||
# dir - the dir where glob will be executed under
|
||||
# (the dir will be included to each result)
|
||||
# pattern - the pattern which will be applied under the dir
|
||||
# flags - the flags which will be applied to the pattern
|
||||
# patterns - the patterns (or the pattern) which will be applied under the dir
|
||||
# flags - the flags which will be applied to the pattern
|
||||
#
|
||||
# Returns matched pathes
|
||||
def safe_glob(dir, pattern, flags = 0)
|
||||
def safe_glob(dir, patterns, flags = 0)
|
||||
return [] unless Dir.exist?(dir)
|
||||
return [dir] if pattern.nil? || pattern.empty?
|
||||
pattern = File.join(Array patterns)
|
||||
return [dir] if pattern.empty?
|
||||
Dir.chdir(dir) do
|
||||
Dir.glob(pattern, flags).map { |f| File.join(dir, f) }
|
||||
end
|
||||
|
|
|
@ -212,6 +212,11 @@ class TestUtils < JekyllUnitTest
|
|||
assert_equal Dir.glob(dir + "/*", File::FNM_DOTMATCH),
|
||||
Utils.safe_glob(dir, "*", File::FNM_DOTMATCH)
|
||||
end
|
||||
|
||||
should "support pattern as an array to support windows" do
|
||||
dir = "test"
|
||||
assert_equal Dir.glob(dir + "/**/*"), Utils.safe_glob(dir, ["**", "*"])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue