Extracted `read_data_file` 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
6e06fd8734
commit
ddfecb0f53
|
@ -57,5 +57,21 @@ module Jekyll
|
||||||
entries = Dir.chdir(base) { filter_entries(Dir['**/*'], base) }
|
entries = Dir.chdir(base) { filter_entries(Dir['**/*'], base) }
|
||||||
entries.delete_if { |e| File.directory?(in_source_dir(base, e)) }
|
entries.delete_if { |e| File.directory?(in_source_dir(base, e)) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# Determines how to read a data file.
|
||||||
|
#
|
||||||
|
# Returns the contents of the data file.
|
||||||
|
def read_data_file(path)
|
||||||
|
case File.extname(path).downcase
|
||||||
|
when '.csv'
|
||||||
|
CSV.read(path, {
|
||||||
|
:headers => true,
|
||||||
|
:encoding => config['encoding']
|
||||||
|
}).map(&:to_hash)
|
||||||
|
else
|
||||||
|
SafeYAML.load_file(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -236,26 +236,11 @@ module Jekyll
|
||||||
if File.directory?(path)
|
if File.directory?(path)
|
||||||
read_data_to(path, data[key] = {})
|
read_data_to(path, data[key] = {})
|
||||||
else
|
else
|
||||||
data[key] = read_data_file(path)
|
data[key] = reader.read_data_file(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Determines how to read a data file.
|
|
||||||
#
|
|
||||||
# Returns the contents of the data file.
|
|
||||||
def read_data_file(path)
|
|
||||||
case File.extname(path).downcase
|
|
||||||
when '.csv'
|
|
||||||
CSV.read(path, {
|
|
||||||
:headers => true,
|
|
||||||
:encoding => config['encoding']
|
|
||||||
}).map(&:to_hash)
|
|
||||||
else
|
|
||||||
SafeYAML.load_file(path)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Read in all collections specified in the configuration
|
# Read in all collections specified in the configuration
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
|
|
|
@ -369,7 +369,7 @@ class TestSite < JekyllUnitTest
|
||||||
site = Site.new(site_configuration)
|
site = Site.new(site_configuration)
|
||||||
site.process
|
site.process
|
||||||
|
|
||||||
file_content = site.read_data_file(source_dir('_data', 'members.yaml'))
|
file_content = site.reader.read_data_file(source_dir('_data', 'members.yaml'))
|
||||||
|
|
||||||
assert_equal site.data['members'], file_content
|
assert_equal site.data['members'], file_content
|
||||||
assert_equal site.site_payload['site']['data']['members'], file_content
|
assert_equal site.site_payload['site']['data']['members'], file_content
|
||||||
|
|
Loading…
Reference in New Issue