This repository was archived by the owner on Mar 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlayout_spec.rb
118 lines (99 loc) · 3.19 KB
/
layout_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
describe "layouts" do
let!(:root) { node "/" }
let!(:outer_layout) do
node "_layout.html.erb", parent: root, source: <<-EOF
<h1><%= "Outer Layout <g>" %></h1>
<%= yield %>
EOF
end
let!(:folder) do
node "test", parent: root
end
let!(:page) do
node "page.html", parent: folder, source: <<-EOF
---
title: Page Title
---
<p>I'm the actual page!</p>
EOF
end
let!(:stylesheet) do
node "styles.css", parent: folder,
source: %[body { color: red }]
end
let!(:inner_layout) do
node "_layout.html.erb", parent: folder, source: <<-EOF
<h2><%= page.title %></h2>
<%= yield %>
EOF
end
let!(:alternative_layout) do
node "_alternative_layout.html.erb", parent: folder, source: <<-EOF
<h2>Alternative Inner Layout</h2>
<%= yield %>
EOF
end
context "with the normal layout behavior" do
it "walks up the tree, applying all _layout files" do
expect(page.render(layout: true))
.to eq(%{<h1>Outer Layout <g></h1>\n<h2>Page Title</h2>\n<p>I'm the actual page!</p>\n\n\n})
end
end
context "with all layout disabled" do
before do
page.data[:layout] = false
end
it "doesn't apply any layouts" do
expect(page.render(layout: true))
.to eq(%{<p>I'm the actual page!</p>\n})
end
end
context "with an alternative layout specified in the node data" do
before do
page.data[:layout] = "./_alternative_layout"
end
it "applies the specified layout, then walks up the tree" do
expect(page.render(layout: true))
.to eq(%{<h1>Outer Layout <g></h1>\n<h2>Alternative Inner Layout</h2>\n<p>I'm the actual page!</p>\n\n\n})
end
end
context "with multiple layouts specified (you crazy person, you)" do
before do
page.data[:layout] = ["/_layout", "./_alternative_layout", false]
end
it "applies the specified layout, then walks up the tree" do
expect(page.render(layout: true))
.to eq(%{<h2>Alternative Inner Layout</h2>\n<h1>Outer Layout <g></h1>\n<p>I'm the actual page!</p>\n\n\n})
end
end
context "with an alternative layout specified in the node data, and a false value" do
before do
page.data[:layout] = ["./_alternative_layout", false]
end
it "applies the specified layout, then stops" do
expect(page.render(layout: true))
.to eq(%{<h2>Alternative Inner Layout</h2>\n<p>I'm the actual page!</p>\n\n})
end
end
context "with an alternative layout explicitly specified" do
it "applies the specified layout, then stops" do
expect(page.render(layout: "./_alternative_layout"))
.to eq(%{<h2>Alternative Inner Layout</h2>\n<p>I'm the actual page!</p>\n\n})
end
end
context "when rendering something that is not a HTML page" do
specify "layouts are not applied automatically" do
expect(stylesheet.render(layout: true))
.to eq("body { color: red }")
end
end
context "with a missing layout specified" do
before do
page.data[:layout] = "./_missing_layout"
end
it "applies the specified layout, then walks up the tree" do
expect { page.render(layout: true) }
.to raise_error("No layout found for path expression './_missing_layout'")
end
end
end