Merge branch 'jekyll-gjtorikian-patch-1'
* jekyll-gjtorikian-patch-1: Use the source_dir() helper Add test for new extracted method Factor out a `read_data_file` call to keep things clean
This commit is contained in:
commit
aceb5b5d53
|
@ -258,16 +258,23 @@ module Jekyll
|
|||
if File.directory?(path)
|
||||
read_data_to(path, data[key] = {})
|
||||
else
|
||||
case File.extname(path).downcase
|
||||
when '.csv'
|
||||
data[key] = CSV.read(path, :headers => true).map(&:to_hash)
|
||||
else
|
||||
data[key] = SafeYAML.load_file(path)
|
||||
end
|
||||
data[key] = 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).map(&:to_hash)
|
||||
else
|
||||
SafeYAML.load_file(path)
|
||||
end
|
||||
end
|
||||
|
||||
# Read in all collections specified in the configuration
|
||||
#
|
||||
# Returns nothing.
|
||||
|
|
|
@ -369,6 +369,16 @@ class TestSite < Test::Unit::TestCase
|
|||
assert_equal site.site_payload['site']['data']['members'], file_content
|
||||
end
|
||||
|
||||
should 'load yaml files from extracted method' do
|
||||
site = Site.new(site_configuration)
|
||||
site.process
|
||||
|
||||
file_content = site.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
|
||||
end
|
||||
|
||||
should 'auto load yml files' do
|
||||
site = Site.new(site_configuration)
|
||||
site.process
|
||||
|
|
Loading…
Reference in New Issue