mirror of
https://github.com/jekyll/jekyll.git
synced 2026-02-05 12:15:26 -05:00
Extracted read_data_to from site.rb into reader.rb
- Extracted - Updated References - Ran Tests Signed-off-by: Martin Jorn Rogalla <martin@martinrogalla.com>
This commit is contained in:
@@ -74,6 +74,33 @@ module Jekyll
|
||||
end
|
||||
end
|
||||
|
||||
# Read and parse all yaml files under <dir> and add them to the
|
||||
# <data> variable.
|
||||
#
|
||||
# dir - The string absolute path of the directory to read.
|
||||
# data - The variable to which data will be added.
|
||||
#
|
||||
# Returns nothing
|
||||
def read_data_to(dir, data)
|
||||
return unless File.directory?(dir) && (!site.safe || !File.symlink?(dir))
|
||||
|
||||
entries = Dir.chdir(dir) do
|
||||
Dir['*.{yaml,yml,json,csv}'] + Dir['*'].select { |fn| File.directory?(fn) }
|
||||
end
|
||||
|
||||
entries.each do |entry|
|
||||
path = in_source_dir(dir, entry)
|
||||
next if File.symlink?(path) && site.safe
|
||||
|
||||
key = sanitize_filename(File.basename(entry, '.*'))
|
||||
if File.directory?(path)
|
||||
read_data_to(path, data[key] = {})
|
||||
else
|
||||
data[key] = read_data_file(path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def sanitize_filename(name)
|
||||
name.gsub!(/[^\w\s_-]+/, '')
|
||||
name.gsub!(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
|
||||
|
||||
@@ -211,34 +211,7 @@ module Jekyll
|
||||
# Returns nothing
|
||||
def read_data(dir)
|
||||
base = reader.in_source_dir(dir)
|
||||
read_data_to(base, self.data)
|
||||
end
|
||||
|
||||
# Read and parse all yaml files under <dir> and add them to the
|
||||
# <data> variable.
|
||||
#
|
||||
# dir - The string absolute path of the directory to read.
|
||||
# data - The variable to which data will be added.
|
||||
#
|
||||
# Returns nothing
|
||||
def read_data_to(dir, data)
|
||||
return unless File.directory?(dir) && (!safe || !File.symlink?(dir))
|
||||
|
||||
entries = Dir.chdir(dir) do
|
||||
Dir['*.{yaml,yml,json,csv}'] + Dir['*'].select { |fn| File.directory?(fn) }
|
||||
end
|
||||
|
||||
entries.each do |entry|
|
||||
path = reader.in_source_dir(dir, entry)
|
||||
next if File.symlink?(path) && safe
|
||||
|
||||
key = reader.sanitize_filename(File.basename(entry, '.*'))
|
||||
if File.directory?(path)
|
||||
read_data_to(path, data[key] = {})
|
||||
else
|
||||
data[key] = reader.read_data_file(path)
|
||||
end
|
||||
end
|
||||
reader.read_data_to(base, self.data)
|
||||
end
|
||||
|
||||
# Read in all collections specified in the configuration
|
||||
|
||||
Reference in New Issue
Block a user