From e1e60499b1ba7117ea9cee828db380dac13397ab Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Thu, 29 Jan 2015 12:41:19 -0800 Subject: [PATCH 1/3] Factor out a `read_data_file` call to keep things clean --- lib/jekyll/site.rb | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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. From 3bac8a20340d1124fb4a3d4b567c92b7921251f7 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Fri, 30 Jan 2015 15:21:45 -0800 Subject: [PATCH 2/3] Add test for new extracted method --- test/test_site.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/test_site.rb b/test/test_site.rb index 1fe86b76..1ea582f7 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(File.join(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 From 32a2e8b4ef5096f118dc88ba3bf839ff794e3f5c Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 31 Jan 2015 00:12:24 -0800 Subject: [PATCH 3/3] Use the source_dir() helper --- test/test_site.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_site.rb b/test/test_site.rb index 1ea582f7..409392fd 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -373,7 +373,7 @@ class TestSite < Test::Unit::TestCase site = Site.new(site_configuration) site.process - file_content = site.read_data_file(File.join(source_dir, '_data', 'members.yaml')) + 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