Skip to content

Commit 1ebaa86

Browse files
liquid related compat tests added
1 parent 20d75ec commit 1ebaa86

File tree

6 files changed

+142
-1
lines changed

6 files changed

+142
-1
lines changed

compat/liquid_test.rb

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
require File.dirname(__FILE__) + '/helper'
2+
3+
context "Liquid" do
4+
5+
setup do
6+
Sinatra.application = nil
7+
end
8+
9+
context "without layouts" do
10+
11+
setup do
12+
Sinatra.application = nil
13+
end
14+
15+
specify "should render" do
16+
17+
get '/no_layout' do
18+
liquid '{{ 1|plus:1 }}'
19+
end
20+
21+
get_it '/no_layout'
22+
should.be.ok
23+
body.should == '2'
24+
25+
end
26+
27+
specify "should take an options hash with :locals set with a string" do
28+
get '/locals' do
29+
liquid '{{ foo }}', :locals => {'foo' => "Bar"}
30+
end
31+
32+
get_it '/locals'
33+
should.be.ok
34+
body.should == 'Bar'
35+
end
36+
37+
specify "should take an options hash with :locals set with a complex object" do
38+
get '/locals-complex' do
39+
liquid '{{ foo[0] }}', :locals => {'foo' => ["foo", "bar", "baz"]}
40+
end
41+
42+
get_it '/locals-complex'
43+
should.be.ok
44+
body.should == 'foo'
45+
end
46+
end
47+
48+
context "with layouts" do
49+
50+
setup do
51+
Sinatra.application = nil
52+
end
53+
54+
specify "can be inline" do
55+
56+
layout do
57+
"This is {{ content }}!"
58+
end
59+
60+
get '/lay' do
61+
liquid 'Blake'
62+
end
63+
64+
get_it '/lay'
65+
should.be.ok
66+
body.should.equal 'This is Blake!'
67+
68+
end
69+
70+
specify "can use named layouts" do
71+
72+
layout :pretty do
73+
"<h1>{{ content }}</h1>"
74+
end
75+
76+
get '/pretty' do
77+
liquid 'Foo', :layout => :pretty
78+
end
79+
80+
get '/not_pretty' do
81+
liquid 'Bar'
82+
end
83+
84+
get_it '/pretty'
85+
body.should.equal '<h1>Foo</h1>'
86+
87+
get_it '/not_pretty'
88+
body.should.equal 'Bar'
89+
90+
end
91+
92+
specify "can be read from a file if they're not inlined" do
93+
94+
get '/foo' do
95+
locals = {'title' => 'Welcome to the Hello Program'}
96+
liquid 'Blake', :locals => locals, :layout => :foo_layout,
97+
:views_directory => File.dirname(__FILE__) + "/views"
98+
end
99+
100+
get_it '/foo'
101+
body.should.equal "Welcome to the Hello Program\nHi Blake\n"
102+
103+
end
104+
105+
end
106+
107+
context "Templates (in general)" do
108+
109+
specify "are read from files if Symbols" do
110+
111+
get '/from_file' do
112+
locals = {'name' => 'Alena'}
113+
liquid :foo, :views_directory => File.dirname(__FILE__) + "/views", :locals => locals
114+
end
115+
116+
get_it '/from_file'
117+
118+
body.should.equal "You rock Alena!\n"
119+
120+
end
121+
122+
specify "use layout.ext by default if available" do
123+
124+
get '/layout_from_file' do
125+
liquid :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
126+
end
127+
128+
get_it '/layout_from_file'
129+
should.be.ok
130+
body.should.equal "x This is foo! x \n"
131+
132+
end
133+
134+
end
135+
136+
end

compat/views/foo.liquid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
You rock {{ name }}!

compat/views/foo_layout.liquid

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{ title }}
2+
Hi {{ content }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is foo!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x {{ content }} x

lib/sinatra/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def render(engine, template, options={}, locals={})
267267

268268
# render layout
269269
if layout && data = lookup_layout(engine, layout, views)
270-
__send__("render_#{engine}", layout, data, options, {}) { output }
270+
__send__("render_#{engine}", layout, data, options, locals) { output }
271271
else
272272
output
273273
end

0 commit comments

Comments
 (0)