sinatra-acd 1.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +5 -0
- data/AUTHORS +61 -0
- data/CHANGES +1293 -0
- data/Gemfile +76 -0
- data/LICENSE +23 -0
- data/README.de.md +2864 -0
- data/README.es.md +2786 -0
- data/README.fr.md +2924 -0
- data/README.hu.md +694 -0
- data/README.ja.md +2726 -0
- data/README.ko.md +2832 -0
- data/README.md +2980 -0
- data/README.pt-br.md +965 -0
- data/README.pt-pt.md +791 -0
- data/README.ru.md +2799 -0
- data/README.zh.md +2158 -0
- data/Rakefile +199 -0
- data/examples/chat.rb +61 -0
- data/examples/simple.rb +3 -0
- data/examples/stream.ru +26 -0
- data/lib/sinatra.rb +4 -0
- data/lib/sinatra/base.rb +2044 -0
- data/lib/sinatra/images/404.png +0 -0
- data/lib/sinatra/images/500.png +0 -0
- data/lib/sinatra/main.rb +34 -0
- data/lib/sinatra/show_exceptions.rb +345 -0
- data/lib/sinatra/version.rb +3 -0
- data/sinatra.gemspec +19 -0
- data/test/asciidoctor_test.rb +72 -0
- data/test/base_test.rb +171 -0
- data/test/builder_test.rb +91 -0
- data/test/coffee_test.rb +90 -0
- data/test/compile_test.rb +183 -0
- data/test/contest.rb +100 -0
- data/test/creole_test.rb +65 -0
- data/test/delegator_test.rb +160 -0
- data/test/encoding_test.rb +20 -0
- data/test/erb_test.rb +116 -0
- data/test/extensions_test.rb +98 -0
- data/test/filter_test.rb +487 -0
- data/test/haml_test.rb +109 -0
- data/test/helper.rb +131 -0
- data/test/helpers_test.rb +1917 -0
- data/test/integration/app.rb +79 -0
- data/test/integration_helper.rb +236 -0
- data/test/integration_test.rb +104 -0
- data/test/less_test.rb +69 -0
- data/test/liquid_test.rb +77 -0
- data/test/mapped_error_test.rb +285 -0
- data/test/markaby_test.rb +80 -0
- data/test/markdown_test.rb +82 -0
- data/test/mediawiki_test.rb +68 -0
- data/test/middleware_test.rb +68 -0
- data/test/nokogiri_test.rb +67 -0
- data/test/public/favicon.ico +0 -0
- data/test/rabl_test.rb +89 -0
- data/test/rack_test.rb +45 -0
- data/test/radius_test.rb +59 -0
- data/test/rdoc_test.rb +66 -0
- data/test/readme_test.rb +130 -0
- data/test/request_test.rb +97 -0
- data/test/response_test.rb +63 -0
- data/test/result_test.rb +76 -0
- data/test/route_added_hook_test.rb +59 -0
- data/test/routing_test.rb +1412 -0
- data/test/sass_test.rb +115 -0
- data/test/scss_test.rb +88 -0
- data/test/server_test.rb +48 -0
- data/test/settings_test.rb +582 -0
- data/test/sinatra_test.rb +12 -0
- data/test/slim_test.rb +102 -0
- data/test/static_test.rb +236 -0
- data/test/streaming_test.rb +149 -0
- data/test/stylus_test.rb +90 -0
- data/test/templates_test.rb +382 -0
- data/test/textile_test.rb +65 -0
- data/test/views/a/in_a.str +1 -0
- data/test/views/ascii.erb +2 -0
- data/test/views/b/in_b.str +1 -0
- data/test/views/calc.html.erb +1 -0
- data/test/views/error.builder +3 -0
- data/test/views/error.erb +3 -0
- data/test/views/error.haml +3 -0
- data/test/views/error.sass +2 -0
- data/test/views/explicitly_nested.str +1 -0
- data/test/views/foo/hello.test +1 -0
- data/test/views/hello.asciidoc +1 -0
- data/test/views/hello.builder +1 -0
- data/test/views/hello.coffee +1 -0
- data/test/views/hello.creole +1 -0
- data/test/views/hello.erb +1 -0
- data/test/views/hello.haml +1 -0
- data/test/views/hello.less +5 -0
- data/test/views/hello.liquid +1 -0
- data/test/views/hello.mab +1 -0
- data/test/views/hello.md +1 -0
- data/test/views/hello.mediawiki +1 -0
- data/test/views/hello.nokogiri +1 -0
- data/test/views/hello.rabl +2 -0
- data/test/views/hello.radius +1 -0
- data/test/views/hello.rdoc +1 -0
- data/test/views/hello.sass +2 -0
- data/test/views/hello.scss +3 -0
- data/test/views/hello.slim +1 -0
- data/test/views/hello.str +1 -0
- data/test/views/hello.styl +2 -0
- data/test/views/hello.test +1 -0
- data/test/views/hello.textile +1 -0
- data/test/views/hello.wlang +1 -0
- data/test/views/hello.yajl +1 -0
- data/test/views/layout2.builder +3 -0
- data/test/views/layout2.erb +2 -0
- data/test/views/layout2.haml +2 -0
- data/test/views/layout2.liquid +2 -0
- data/test/views/layout2.mab +2 -0
- data/test/views/layout2.nokogiri +3 -0
- data/test/views/layout2.rabl +3 -0
- data/test/views/layout2.radius +2 -0
- data/test/views/layout2.slim +3 -0
- data/test/views/layout2.str +2 -0
- data/test/views/layout2.test +1 -0
- data/test/views/layout2.wlang +2 -0
- data/test/views/nested.str +1 -0
- data/test/views/utf8.erb +2 -0
- data/test/wlang_test.rb +87 -0
- data/test/yajl_test.rb +86 -0
- metadata +280 -0
data/test/stylus_test.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'stylus'
|
5
|
+
require 'stylus/tilt'
|
6
|
+
|
7
|
+
begin
|
8
|
+
Stylus.compile '1'
|
9
|
+
rescue RuntimeError
|
10
|
+
raise LoadError, 'unable to find Stylus compiler'
|
11
|
+
end
|
12
|
+
|
13
|
+
class StylusTest < Test::Unit::TestCase
|
14
|
+
def stylus_app(options = {}, &block)
|
15
|
+
mock_app do
|
16
|
+
set :views, File.dirname(__FILE__) + '/views'
|
17
|
+
set(options)
|
18
|
+
get('/', &block)
|
19
|
+
end
|
20
|
+
get '/'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'renders inline Stylus strings' do
|
24
|
+
stylus_app { stylus "a\n margin auto\n" }
|
25
|
+
assert ok?
|
26
|
+
assert body.include?("a {\n margin: auto;\n}\n")
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'defaults content type to css' do
|
30
|
+
stylus_app { stylus :hello }
|
31
|
+
assert ok?
|
32
|
+
assert_equal "text/css;charset=utf-8", response['Content-Type']
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'defaults allows setting content type per route' do
|
36
|
+
stylus_app do
|
37
|
+
content_type :html
|
38
|
+
stylus :hello
|
39
|
+
end
|
40
|
+
assert ok?
|
41
|
+
assert_equal "text/html;charset=utf-8", response['Content-Type']
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'defaults allows setting content type globally' do
|
45
|
+
stylus_app(:styl => { :content_type => 'html' }) do
|
46
|
+
stylus :hello
|
47
|
+
end
|
48
|
+
assert ok?
|
49
|
+
assert_equal "text/html;charset=utf-8", response['Content-Type']
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'renders .styl files in views path' do
|
53
|
+
stylus_app { stylus :hello }
|
54
|
+
assert ok?
|
55
|
+
assert_include body, "a {\n margin: auto;\n}\n"
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'ignores the layout option' do
|
59
|
+
stylus_app { stylus :hello, :layout => :layout2 }
|
60
|
+
assert ok?
|
61
|
+
assert_include body, "a {\n margin: auto;\n}\n"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "raises error if template not found" do
|
65
|
+
mock_app {
|
66
|
+
get('/') { stylus :no_such_template }
|
67
|
+
}
|
68
|
+
assert_raise(Errno::ENOENT) { get('/') }
|
69
|
+
end
|
70
|
+
|
71
|
+
it "passes stylus options to the stylus engine" do
|
72
|
+
stylus_app { stylus :hello, :no_wrap => true }
|
73
|
+
assert ok?
|
74
|
+
assert_body "a {\n margin: auto;\n}\n"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "passes default stylus options to the stylus engine" do
|
78
|
+
mock_app do
|
79
|
+
set :stylus, :no_wrap => true # default stylus style is :nested
|
80
|
+
get('/') { stylus :hello }
|
81
|
+
end
|
82
|
+
get '/'
|
83
|
+
assert ok?
|
84
|
+
assert_body "a {\n margin: auto;\n}\n"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
rescue LoadError
|
89
|
+
warn "#{$!.to_s}: skipping stylus tests"
|
90
|
+
end
|
@@ -0,0 +1,382 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path('../helper', __FILE__)
|
3
|
+
File.delete(File.dirname(__FILE__) + '/views/layout.test') rescue nil
|
4
|
+
|
5
|
+
class TestTemplate < Tilt::Template
|
6
|
+
def prepare
|
7
|
+
end
|
8
|
+
|
9
|
+
def evaluate(scope, locals={}, &block)
|
10
|
+
inner = block ? block.call : ''
|
11
|
+
data + inner
|
12
|
+
end
|
13
|
+
|
14
|
+
Tilt.register 'test', self
|
15
|
+
end
|
16
|
+
|
17
|
+
class TemplatesTest < Test::Unit::TestCase
|
18
|
+
def render_app(base=Sinatra::Base, options = {}, &block)
|
19
|
+
base, options = Sinatra::Base, base if base.is_a? Hash
|
20
|
+
mock_app(base) do
|
21
|
+
set :views, File.dirname(__FILE__) + '/views'
|
22
|
+
set options
|
23
|
+
get('/', &block)
|
24
|
+
template(:layout3) { "Layout 3!\n" }
|
25
|
+
end
|
26
|
+
get '/'
|
27
|
+
end
|
28
|
+
|
29
|
+
def with_default_layout
|
30
|
+
layout = File.dirname(__FILE__) + '/views/layout.test'
|
31
|
+
File.open(layout, 'wb') { |io| io.write "Layout!\n" }
|
32
|
+
yield
|
33
|
+
ensure
|
34
|
+
File.unlink(layout) rescue nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'falls back to engine layout' do
|
38
|
+
mock_app do
|
39
|
+
template(:layout3) { 'Layout 3!<%= yield %>' }
|
40
|
+
set :erb, :layout => :layout3
|
41
|
+
|
42
|
+
get('/') do
|
43
|
+
erb('Hello World!', { :layout => true })
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
get '/'
|
48
|
+
assert ok?
|
49
|
+
assert_equal "Layout 3!Hello World!", body
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'falls back to default layout if engine layout is true' do
|
53
|
+
mock_app do
|
54
|
+
template(:layout) { 'Layout!!! <%= yield %>' }
|
55
|
+
set :erb, :layout => true
|
56
|
+
|
57
|
+
get('/') do
|
58
|
+
erb('Hello World!', { :layout => true })
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
get '/'
|
63
|
+
assert ok?
|
64
|
+
assert_equal "Layout!!! Hello World!", body
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'renders no layout if layout if falsy' do
|
68
|
+
mock_app do
|
69
|
+
template(:layout) { 'Layout!!! <%= yield %>' }
|
70
|
+
set :erb, :layout => true
|
71
|
+
|
72
|
+
get('/') do
|
73
|
+
erb('Hello World!', { :layout => nil })
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
get '/'
|
78
|
+
assert ok?
|
79
|
+
assert_equal "Hello World!", body
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'allows overriding false default layout with explicit true' do
|
83
|
+
mock_app do
|
84
|
+
template(:layout) { 'Layout!!! <%= yield %>' }
|
85
|
+
set :erb, :layout => false
|
86
|
+
|
87
|
+
get('/') do
|
88
|
+
erb('Hello World!', { :layout => true })
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
get '/'
|
93
|
+
assert ok?
|
94
|
+
assert_equal "Layout!!! Hello World!", body
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'renders String templates directly' do
|
98
|
+
render_app { render(:test, 'Hello World') }
|
99
|
+
assert ok?
|
100
|
+
assert_equal 'Hello World', body
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'renders Proc templates using the call result' do
|
104
|
+
render_app { render(:test, Proc.new {'Hello World'}) }
|
105
|
+
assert ok?
|
106
|
+
assert_equal 'Hello World', body
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'looks up Symbol templates in views directory' do
|
110
|
+
render_app { render(:test, :hello) }
|
111
|
+
assert ok?
|
112
|
+
assert_equal "Hello World!\n", body
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'uses the default layout template if not explicitly overridden' do
|
116
|
+
with_default_layout do
|
117
|
+
render_app { render(:test, :hello) }
|
118
|
+
assert ok?
|
119
|
+
assert_equal "Layout!\nHello World!\n", body
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'uses the default layout template if not really overriden' do
|
124
|
+
with_default_layout do
|
125
|
+
render_app { render(:test, :hello, :layout => true) }
|
126
|
+
assert ok?
|
127
|
+
assert_equal "Layout!\nHello World!\n", body
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'uses the layout template specified' do
|
132
|
+
render_app { render(:test, :hello, :layout => :layout2) }
|
133
|
+
assert ok?
|
134
|
+
assert_equal "Layout 2!\nHello World!\n", body
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'uses layout templates defined with the #template method' do
|
138
|
+
render_app { render(:test, :hello, :layout => :layout3) }
|
139
|
+
assert ok?
|
140
|
+
assert_equal "Layout 3!\nHello World!\n", body
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'avoids wrapping layouts around nested templates' do
|
144
|
+
render_app { render(:str, :nested, :layout => :layout2) }
|
145
|
+
assert ok?
|
146
|
+
assert_equal(
|
147
|
+
"<h1>String Layout!</h1>\n<content><h1>Hello From String</h1></content>",
|
148
|
+
body
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'allows explicitly wrapping layouts around nested templates' do
|
153
|
+
render_app { render(:str, :explicitly_nested, :layout => :layout2) }
|
154
|
+
assert ok?
|
155
|
+
assert_equal(
|
156
|
+
"<h1>String Layout!</h1>\n<content><h1>String Layout!</h1>\n<h1>Hello From String</h1></content>",
|
157
|
+
body
|
158
|
+
)
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'two independent render calls do not disable layouts' do
|
162
|
+
render_app do
|
163
|
+
render :str, :explicitly_nested, :layout => :layout2
|
164
|
+
render :str, :nested, :layout => :layout2
|
165
|
+
end
|
166
|
+
assert ok?
|
167
|
+
assert_equal(
|
168
|
+
"<h1>String Layout!</h1>\n<content><h1>Hello From String</h1></content>",
|
169
|
+
body
|
170
|
+
)
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'is possible to use partials in layouts' do
|
174
|
+
render_app do
|
175
|
+
settings.layout { "<%= erb 'foo' %><%= yield %>" }
|
176
|
+
erb 'bar'
|
177
|
+
end
|
178
|
+
assert ok?
|
179
|
+
assert_equal "foobar", body
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'loads templates from source file' do
|
183
|
+
mock_app { enable(:inline_templates) }
|
184
|
+
assert_equal "this is foo\n\n", @app.templates[:foo][0]
|
185
|
+
assert_equal "X\n= yield\nX\n", @app.templates[:layout][0]
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'ignores spaces after names of inline templates' do
|
189
|
+
mock_app { enable(:inline_templates) }
|
190
|
+
assert_equal "There's a space after 'bar'!\n\n", @app.templates[:bar][0]
|
191
|
+
assert_equal "this is not foo\n\n", @app.templates[:"foo bar"][0]
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'loads templates from given source file' do
|
195
|
+
mock_app { set(:inline_templates, __FILE__) }
|
196
|
+
assert_equal "this is foo\n\n", @app.templates[:foo][0]
|
197
|
+
end
|
198
|
+
|
199
|
+
test 'inline_templates ignores IO errors' do
|
200
|
+
assert_nothing_raised { mock_app { set(:inline_templates, '/foo/bar') } }
|
201
|
+
|
202
|
+
assert @app.templates.empty?
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'allows unicode in inline templates' do
|
206
|
+
mock_app { set(:inline_templates, __FILE__) }
|
207
|
+
assert_equal(
|
208
|
+
"Den som tror at hemma det är där man bor har aldrig vart hos mig.\n\n",
|
209
|
+
@app.templates[:umlaut][0]
|
210
|
+
)
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'loads templates from specified views directory' do
|
214
|
+
render_app { render(:test, :hello, :views => settings.views + '/foo') }
|
215
|
+
|
216
|
+
assert_equal "from another views directory\n", body
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'takes views directory into consideration for caching' do
|
220
|
+
render_app do
|
221
|
+
render(:test, :hello) + render(:test, :hello, :views => settings.views + '/foo')
|
222
|
+
end
|
223
|
+
assert_equal "Hello World!\nfrom another views directory\n", body
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'passes locals to the layout' do
|
227
|
+
mock_app do
|
228
|
+
template(:my_layout) { 'Hello <%= name %>!<%= yield %>' }
|
229
|
+
|
230
|
+
get('/') do
|
231
|
+
erb('<p>content</p>', { :layout => :my_layout }, { :name => 'Mike'})
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
get '/'
|
236
|
+
assert ok?
|
237
|
+
assert_equal 'Hello Mike!<p>content</p>', body
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'sets layout-only options via layout_options' do
|
241
|
+
render_app do
|
242
|
+
render(:str, :in_a,
|
243
|
+
:views => settings.views + '/a',
|
244
|
+
:layout_options => { :views => settings.views },
|
245
|
+
:layout => :layout2)
|
246
|
+
end
|
247
|
+
|
248
|
+
assert ok?
|
249
|
+
assert_equal "<h1>String Layout!</h1>\nGimme an A!\n", body
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'loads templates defined in subclasses' do
|
253
|
+
base = Class.new(Sinatra::Base)
|
254
|
+
base.template(:foo) { 'bar' }
|
255
|
+
render_app(base) { render(:test, :foo) }
|
256
|
+
assert ok?
|
257
|
+
assert_equal 'bar', body
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'allows setting default content type per template engine' do
|
261
|
+
render_app(:str => { :content_type => :txt }) {
|
262
|
+
render :str, 'foo'
|
263
|
+
}
|
264
|
+
assert_equal 'text/plain;charset=utf-8', response['Content-Type']
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'setting default content type does not affect other template engines' do
|
268
|
+
render_app(:str => { :content_type => :txt }) {
|
269
|
+
render :test, 'foo'
|
270
|
+
}
|
271
|
+
assert_equal 'text/html;charset=utf-8', response['Content-Type']
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'setting default content type per template engine does not override content_type' do
|
275
|
+
render_app :str => { :content_type => :txt } do
|
276
|
+
content_type :html
|
277
|
+
render :str, 'foo'
|
278
|
+
end
|
279
|
+
assert_equal 'text/html;charset=utf-8', response['Content-Type']
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'uses templates in superclasses before subclasses' do
|
283
|
+
base = Class.new(Sinatra::Base)
|
284
|
+
base.template(:foo) { 'template in superclass' }
|
285
|
+
assert_equal 'template in superclass', base.templates[:foo].first.call
|
286
|
+
|
287
|
+
mock_app(base) do
|
288
|
+
set :views, File.dirname(__FILE__) + '/views'
|
289
|
+
template(:foo) { 'template in subclass' }
|
290
|
+
get('/') { render :test, :foo }
|
291
|
+
end
|
292
|
+
assert_equal 'template in subclass', @app.templates[:foo].first.call
|
293
|
+
|
294
|
+
get '/'
|
295
|
+
assert ok?
|
296
|
+
assert_equal 'template in subclass', body
|
297
|
+
end
|
298
|
+
|
299
|
+
it "is possible to use a different engine for the layout than for the template itself explicitly" do
|
300
|
+
render_app do
|
301
|
+
settings.template(:layout) { 'Hello <%= yield %>!' }
|
302
|
+
render :str, "<%= 'World' %>", :layout_engine => :erb
|
303
|
+
end
|
304
|
+
assert_equal "Hello <%= 'World' %>!", body
|
305
|
+
end
|
306
|
+
|
307
|
+
it "is possible to use a different engine for the layout than for the template itself globally" do
|
308
|
+
render_app :str => { :layout_engine => :erb } do
|
309
|
+
settings.template(:layout) { 'Hello <%= yield %>!' }
|
310
|
+
render :str, "<%= 'World' %>"
|
311
|
+
end
|
312
|
+
assert_equal "Hello <%= 'World' %>!", body
|
313
|
+
end
|
314
|
+
|
315
|
+
it "does not leak the content type to the template" do
|
316
|
+
render_app :str => { :layout_engine => :erb } do
|
317
|
+
settings.template(:layout) { 'Hello <%= yield %>!' }
|
318
|
+
render :str, "<%= 'World' %>", :content_type => :txt
|
319
|
+
end
|
320
|
+
assert_equal "text/html;charset=utf-8", headers['Content-Type']
|
321
|
+
end
|
322
|
+
|
323
|
+
it "is possible to register another template" do
|
324
|
+
Tilt.register "html.erb", Tilt[:erb]
|
325
|
+
render_app { render :erb, :calc }
|
326
|
+
assert_equal '2', body
|
327
|
+
end
|
328
|
+
|
329
|
+
it "passes scope to the template" do
|
330
|
+
mock_app do
|
331
|
+
template(:scoped) { 'Hello <%= foo %>' }
|
332
|
+
|
333
|
+
get('/') do
|
334
|
+
some_scope = Object.new
|
335
|
+
def some_scope.foo() 'World!' end
|
336
|
+
erb :scoped, :scope => some_scope
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
get '/'
|
341
|
+
assert ok?
|
342
|
+
assert_equal 'Hello World!', body
|
343
|
+
end
|
344
|
+
|
345
|
+
it "is possible to use custom logic for finding template files" do
|
346
|
+
mock_app do
|
347
|
+
set :views, ["a", "b"].map { |d| File.dirname(__FILE__) + '/views/' + d }
|
348
|
+
def find_template(views, name, engine, &block)
|
349
|
+
Array(views).each { |v| super(v, name, engine, &block) }
|
350
|
+
end
|
351
|
+
|
352
|
+
get('/:name') { render(:str, params[:name].to_sym) }
|
353
|
+
end
|
354
|
+
|
355
|
+
get '/in_a'
|
356
|
+
assert_body 'Gimme an A!'
|
357
|
+
|
358
|
+
get '/in_b'
|
359
|
+
assert_body 'Gimme a B!'
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
# __END__ : this is not the real end of the script.
|
364
|
+
|
365
|
+
__END__
|
366
|
+
|
367
|
+
@@ foo
|
368
|
+
this is foo
|
369
|
+
|
370
|
+
@@ bar
|
371
|
+
There's a space after 'bar'!
|
372
|
+
|
373
|
+
@@ foo bar
|
374
|
+
this is not foo
|
375
|
+
|
376
|
+
@@ umlaut
|
377
|
+
Den som tror at hemma det är där man bor har aldrig vart hos mig.
|
378
|
+
|
379
|
+
@@ layout
|
380
|
+
X
|
381
|
+
= yield
|
382
|
+
X
|