Ensuring that layout is only set to the default value if layout is not specified

This commit is contained in:
Parker Moore 2013-01-12 15:31:14 -08:00
parent 11ca1dfa78
commit 5a3e05dbff
7 changed files with 59 additions and 4 deletions

View File

@ -32,7 +32,7 @@ module Jekyll
# Returns nothing.
def read_yaml(base, name)
super(base, name)
self.data['layout'] ||= 'page'
self.data['layout'] = 'page' unless self.data.has_key?('layout')
self.data
end

View File

@ -74,7 +74,7 @@ module Jekyll
# Returns nothing.
def read_yaml(base, name)
super(base, name)
self.data['layout'] ||= 'post'
self.data['layout'] = 'post' unless self.data.has_key?('layout')
self.data
end

View File

@ -0,0 +1,6 @@
---
layout: nil
title: No layout
---
This post has no layout.

View File

@ -0,0 +1,5 @@
---
title: I have no layout
---
This post will be rendered with the "post" layout.

View File

@ -14,7 +14,7 @@ class TestGeneratedSite < Test::Unit::TestCase
end
should "ensure post count is as expected" do
assert_equal 28, @site.posts.size
assert_equal 30, @site.posts.size
end
should "insert site.posts into the index" do

View File

@ -66,6 +66,26 @@ class TestPage < Test::Unit::TestCase
assert_equal "/about/", @page.dir
end
end
context "with unspecified layout" do
setup do
@page = setup_page('contacts.html')
end
should "default to 'post' layout" do
assert_equal "page", @page.data["layout"]
end
end
context "with specified layout of nil" do
setup do
@page = setup_page('sitemap.xml')
end
should "layout of nil is respected" do
assert_equal "nil", @page.data["layout"]
end
end
context "rendering" do
setup do

View File

@ -95,7 +95,7 @@ class TestPost < Test::Unit::TestCase
should "consume the embedded dashes" do
@post.read_yaml(@source, @real_file)
assert_equal({"title" => "Foo --- Bar"}, @post.data)
assert_equal({"title" => "Foo --- Bar", "layout" => "post"}, @post.data)
assert_equal "Triple the fun!", @post.content
end
end
@ -128,6 +128,30 @@ class TestPost < Test::Unit::TestCase
end
end
context "with unspecified layout" do
setup do
file = '2013-01-12-no-layout.textile'
@post = setup_post(file)
@post.process(file)
end
should "default to 'post' layout" do
assert_equal "post", @post.data["layout"]
end
end
context "with specified layout of nil" do
setup do
file = '2013-01-12-nil-layout.textile'
@post = setup_post(file)
@post.process(file)
end
should "layout of nil is respected" do
assert_equal "nil", @post.data["layout"]
end
end
context "with unspecified (date) style and categories" do
setup do
@post.categories << "food"