From ddfecb0f538adde02028c668caada8ae8bf9b14c Mon Sep 17 00:00:00 2001 From: Martin Jorn Rogalla Date: Wed, 4 Mar 2015 19:55:54 +0100 Subject: [PATCH] Extracted `read_data_file` from site.rb into reader.rb - Extracted - Updated References - Ran Tests Signed-off-by: Martin Jorn Rogalla --- lib/jekyll/reader.rb | 16 ++++++++++++++++ lib/jekyll/site.rb | 17 +---------------- test/test_site.rb | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/jekyll/reader.rb b/lib/jekyll/reader.rb index 9d9b2260..d8f6eac4 100644 --- a/lib/jekyll/reader.rb +++ b/lib/jekyll/reader.rb @@ -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 \ No newline at end of file diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 40659d22..ff964d7e 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -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. diff --git a/test/test_site.rb b/test/test_site.rb index c460d873..2e0adbbf 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -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