mirror of
https://github.com/jekyll/jekyll.git
synced 2026-01-29 16:58:01 -05:00
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:
@@ -57,5 +57,21 @@ module Jekyll
|
||||
entries = Dir.chdir(base) { filter_entries(Dir['**/*'], base) }
|
||||
entries.delete_if { |e| File.directory?(in_source_dir(base, e)) }
|
||||
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
|
||||
@@ -236,26 +236,11 @@ module Jekyll
|
||||
if File.directory?(path)
|
||||
read_data_to(path, data[key] = {})
|
||||
else
|
||||
data[key] = read_data_file(path)
|
||||
data[key] = reader.read_data_file(path)
|
||||
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
|
||||
#
|
||||
# Returns nothing.
|
||||
|
||||
@@ -369,7 +369,7 @@ class TestSite < JekyllUnitTest
|
||||
site = Site.new(site_configuration)
|
||||
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.site_payload['site']['data']['members'], file_content
|
||||
|
||||
Reference in New Issue
Block a user