Ensuring that layout is only set to the default value if layout is not specified
This commit is contained in:
parent
11ca1dfa78
commit
5a3e05dbff
|
@ -32,7 +32,7 @@ module Jekyll
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def read_yaml(base, name)
|
def read_yaml(base, name)
|
||||||
super(base, name)
|
super(base, name)
|
||||||
self.data['layout'] ||= 'page'
|
self.data['layout'] = 'page' unless self.data.has_key?('layout')
|
||||||
self.data
|
self.data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ module Jekyll
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def read_yaml(base, name)
|
def read_yaml(base, name)
|
||||||
super(base, name)
|
super(base, name)
|
||||||
self.data['layout'] ||= 'post'
|
self.data['layout'] = 'post' unless self.data.has_key?('layout')
|
||||||
self.data
|
self.data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
layout: nil
|
||||||
|
title: No layout
|
||||||
|
---
|
||||||
|
|
||||||
|
This post has no layout.
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: I have no layout
|
||||||
|
---
|
||||||
|
|
||||||
|
This post will be rendered with the "post" layout.
|
|
@ -14,7 +14,7 @@ class TestGeneratedSite < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "ensure post count is as expected" do
|
should "ensure post count is as expected" do
|
||||||
assert_equal 28, @site.posts.size
|
assert_equal 30, @site.posts.size
|
||||||
end
|
end
|
||||||
|
|
||||||
should "insert site.posts into the index" do
|
should "insert site.posts into the index" do
|
||||||
|
|
|
@ -66,6 +66,26 @@ class TestPage < Test::Unit::TestCase
|
||||||
assert_equal "/about/", @page.dir
|
assert_equal "/about/", @page.dir
|
||||||
end
|
end
|
||||||
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
|
context "rendering" do
|
||||||
setup do
|
setup do
|
||||||
|
|
|
@ -95,7 +95,7 @@ class TestPost < Test::Unit::TestCase
|
||||||
should "consume the embedded dashes" do
|
should "consume the embedded dashes" do
|
||||||
@post.read_yaml(@source, @real_file)
|
@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
|
assert_equal "Triple the fun!", @post.content
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -128,6 +128,30 @@ class TestPost < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
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
|
context "with unspecified (date) style and categories" do
|
||||||
setup do
|
setup do
|
||||||
@post.categories << "food"
|
@post.categories << "food"
|
||||||
|
|
Loading…
Reference in New Issue