diff --git a/features/data.feature b/features/data.feature index 9bfac1ee..45f5554e 100644 --- a/features/data.feature +++ b/features/data.feature @@ -33,6 +33,18 @@ Feature: Data And I should see "Jack" in "_site/index.html" And I should see "Leon" in "_site/index.html" + Scenario: autoload *.json files in _data directory + Given I have a _data directory + And I have a "_data/members.json" file with content: + """ + [{"name": "Jack", "age": 28},{"name": "Leon", "age": 34}] + """ + And I have an "index.html" page that contains "{% for member in site.data.members %}{{member.name}}{% endfor %}" + When I run jekyll build + Then the "_site/index.html" file should exist + And I should see "Jack" in "_site/index.html" + And I should see "Leon" in "_site/index.html" + Scenario: autoload *.yml files in _data directory with space in file name Given I have a _data directory And I have a "_data/team members.yml" file with content: @@ -62,4 +74,3 @@ Feature: Data Then the "_site/index.html" file should exist And I should see "Jack" in "_site/index.html" And I should see "Leon" in "_site/index.html" - diff --git a/test/source/_data/members.json b/test/source/_data/members.json new file mode 100644 index 00000000..5ca4821f --- /dev/null +++ b/test/source/_data/members.json @@ -0,0 +1,12 @@ +[ + { + "name": "Jack", + "age": 27, + "blog": "http://example.com/jack" + }, + { + "name": "John", + "age": 32, + "blog": "http://example.com/john" + } +] diff --git a/test/test_site.rb b/test/test_site.rb index c5d78594..94263491 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -378,6 +378,16 @@ class TestSite < Test::Unit::TestCase assert_equal site.site_payload['site']['data']['languages'], file_content end + should 'auto load json files' do + site = Site.new(Jekyll.configuration) + site.process + + file_content = SafeYAML.load_file(File.join(source_dir, '_data', 'members.json')) + + assert_equal site.data['members'], file_content + assert_equal site.site_payload['site']['data']['members'], file_content + end + should "load symlink files in unsafe mode" do site = Site.new(Jekyll.configuration.merge({'safe' => false})) site.process