Merge commit 'bahuvrihi/master'

This commit is contained in:
Nick Quaranto 2009-06-24 17:33:57 -04:00
commit 8b678a8f01
5 changed files with 22 additions and 8 deletions

View File

@ -18,11 +18,13 @@ module Jekyll
def read_yaml(base, name) def read_yaml(base, name)
self.content = File.read(File.join(base, name)) self.content = File.read(File.join(base, name))
if self.content =~ /^(---\s*\n.*?)\r?\n---\s*\n/m if self.content =~ /^(---\s*\n.*?\n?)(---.*?\n)/m
self.content = self.content[($1.size + 5)..-1] self.content = self.content[($1.size + $2.size)..-1]
self.data = YAML.load($1.dup) self.data = YAML.load($1)
end end
self.data ||= {}
end end
# Transform the contents based on the file extension. # Transform the contents based on the file extension.

View File

@ -20,8 +20,6 @@ module Jekyll
@dir = dir @dir = dir
@name = name @name = name
self.data = {}
self.process(name) self.process(name)
self.read_yaml(File.join(base, dir), name) self.read_yaml(File.join(base, dir), name)
end end

View File

@ -0,0 +1,3 @@
---
---
Empty YAML.

View File

@ -0,0 +1 @@
No YAML.

View File

@ -77,7 +77,7 @@ class TestPost < Test::Unit::TestCase
@post.read_yaml(@source, @real_file) @post.read_yaml(@source, @real_file)
assert_equal({"title" => "Test title", "layout" => "post", "tag" => "Ruby"}, @post.data) 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
end end
@ -236,6 +236,16 @@ class TestPost < Test::Unit::TestCase
assert post.tags.include?('pizza') assert post.tags.include?('pizza')
end 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 context "rendering" do
setup do setup do
clear_dest clear_dest