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:
parent
e586105b46
commit
5b0e2a294d
|
@ -74,6 +74,33 @@ module Jekyll
|
||||||
end
|
end
|
||||||
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)
|
def sanitize_filename(name)
|
||||||
name.gsub!(/[^\w\s_-]+/, '')
|
name.gsub!(/[^\w\s_-]+/, '')
|
||||||
name.gsub!(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
|
name.gsub!(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
|
||||||
|
|
|
@ -211,34 +211,7 @@ module Jekyll
|
||||||
# Returns nothing
|
# Returns nothing
|
||||||
def read_data(dir)
|
def read_data(dir)
|
||||||
base = reader.in_source_dir(dir)
|
base = reader.in_source_dir(dir)
|
||||||
read_data_to(base, self.data)
|
reader.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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Read in all collections specified in the configuration
|
# Read in all collections specified in the configuration
|
||||||
|
|
Loading…
Reference in New Issue