From ca98cd01520e4cf225912b5788590ad97c5d4b3a Mon Sep 17 00:00:00 2001 From: Simon Chiang Date: Tue, 23 Jun 2009 20:55:13 -0600 Subject: [PATCH] updated convertible to allow for posts with no, or empty YAML --- lib/jekyll/convertible.rb | 2 ++ lib/jekyll/page.rb | 2 -- test/source/_posts/2009-06-22-empty-yaml.textile | 3 +++ test/source/_posts/2009-06-22-no-yaml.textile | 1 + test/test_post.rb | 10 ++++++++++ 5 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/source/_posts/2009-06-22-empty-yaml.textile create mode 100644 test/source/_posts/2009-06-22-no-yaml.textile diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index 8f42865c..f0348ab5 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -23,6 +23,8 @@ module Jekyll self.data = YAML.load($1) end + + self.data ||= {} end # Transform the contents based on the file extension. diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index b3a624f3..537df3d4 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -20,8 +20,6 @@ module Jekyll @dir = dir @name = name - self.data = {} - self.process(name) self.read_yaml(File.join(base, dir), name) end diff --git a/test/source/_posts/2009-06-22-empty-yaml.textile b/test/source/_posts/2009-06-22-empty-yaml.textile new file mode 100644 index 00000000..5b0e74b1 --- /dev/null +++ b/test/source/_posts/2009-06-22-empty-yaml.textile @@ -0,0 +1,3 @@ +--- +--- +Empty YAML. \ No newline at end of file diff --git a/test/source/_posts/2009-06-22-no-yaml.textile b/test/source/_posts/2009-06-22-no-yaml.textile new file mode 100644 index 00000000..b0ce4d35 --- /dev/null +++ b/test/source/_posts/2009-06-22-no-yaml.textile @@ -0,0 +1 @@ +No YAML. \ No newline at end of file diff --git a/test/test_post.rb b/test/test_post.rb index 0176ac18..649e2f46 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -235,6 +235,16 @@ class TestPost < Test::Unit::TestCase assert post.tags.include?('cooking') assert post.tags.include?('pizza') end + + should "allow no yaml" do + post = setup_post("2009-06-22-no-yaml.textile") + assert_equal "No YAML.", post.content + end + + should "allow empty yaml" do + post = setup_post("2009-06-22-empty-yaml.textile") + assert_equal "Empty YAML.", post.content + end context "rendering" do setup do