Skip to content

Commit

Permalink
Merge commit 'bahuvrihi/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed Jun 24, 2009
2 parents ec637a1 + ca98cd0 commit 8b678a8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
12 changes: 7 additions & 5 deletions lib/jekyll/convertible.rb
Expand Up @@ -17,12 +17,14 @@ def to_s
# 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.
Expand Down
2 changes: 0 additions & 2 deletions lib/jekyll/page.rb
Expand Up @@ -20,8 +20,6 @@ def initialize(site, base, dir, name)
@dir = dir
@name = name

self.data = {}

self.process(name)
self.read_yaml(File.join(base, dir), name)
end
Expand Down
3 changes: 3 additions & 0 deletions test/source/_posts/2009-06-22-empty-yaml.textile
@@ -0,0 +1,3 @@
---
---
Empty YAML.
1 change: 1 addition & 0 deletions test/source/_posts/2009-06-22-no-yaml.textile
@@ -0,0 +1 @@
No YAML.
12 changes: 11 additions & 1 deletion test/test_post.rb
Expand Up @@ -77,7 +77,7 @@ def do_render(post)
@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

Expand Down Expand Up @@ -235,6 +235,16 @@ def do_render(post)
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
Expand Down

0 comments on commit 8b678a8

Please sign in to comment.