diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 85cdac18..3af47672 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -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. diff --git a/test/test_site.rb b/test/test_site.rb index 1fe86b76..409392fd 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -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