diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index fd457177..f0348ab5 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -17,12 +17,14 @@ module Jekyll # Returns nothing def read_yaml(base, name) self.content = File.read(File.join(base, name)) - - if self.content =~ /^(---\s*\n.*?)\r?\n---\s*\n/m - self.content = self.content[($1.size + 5)..-1] - - self.data = YAML.load($1.dup) + + if self.content =~ /^(---\s*\n.*?\n?)(---.*?\n)/m + self.content = self.content[($1.size + $2.size)..-1] + + 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 ed8a4d2d..649e2f46 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -77,7 +77,7 @@ class TestPost < Test::Unit::TestCase @post.read_yaml(@source, @real_file) assert_equal({"title" => "Test title", "layout" => "post", "tag" => "Ruby"}, @post.data) - assert_equal "\r\n\r\nThis is the content", @post.content + assert_equal "\r\nThis is the content", @post.content end end @@ -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