padrino-helpers 0.16.0.pre4 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +29 -29
- data/Rakefile +1 -1
- data/lib/padrino/rendering/erb_template.rb +7 -7
- data/lib/padrino/rendering/erubi_template.rb +4 -4
- data/lib/padrino/rendering/erubis_template.rb +4 -4
- data/lib/padrino/rendering/haml_template.rb +1 -1
- data/lib/padrino/rendering/hamlit_template.rb +4 -4
- data/lib/padrino/rendering/slim_template.rb +5 -5
- data/lib/padrino/rendering.rb +54 -45
- data/lib/padrino/safe_buffer.rb +31 -36
- data/lib/padrino-helpers/asset_tag_helpers.rb +48 -48
- data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +74 -70
- data/lib/padrino-helpers/form_builder/standard_form_builder.rb +20 -20
- data/lib/padrino-helpers/form_helpers/errors.rb +14 -14
- data/lib/padrino-helpers/form_helpers/options.rb +25 -24
- data/lib/padrino-helpers/form_helpers/security.rb +5 -5
- data/lib/padrino-helpers/form_helpers.rb +133 -133
- data/lib/padrino-helpers/format_helpers.rb +61 -63
- data/lib/padrino-helpers/number_helpers.rb +82 -78
- data/lib/padrino-helpers/output_helpers/abstract_handler.rb +5 -3
- data/lib/padrino-helpers/output_helpers/erb_handler.rb +2 -2
- data/lib/padrino-helpers/output_helpers/haml_handler.rb +1 -1
- data/lib/padrino-helpers/output_helpers.rb +16 -17
- data/lib/padrino-helpers/render_helpers.rb +28 -27
- data/lib/padrino-helpers/tag_helpers.rb +62 -58
- data/lib/padrino-helpers/translation_helpers.rb +2 -2
- data/lib/padrino-helpers.rb +1 -2
- data/padrino-helpers.gemspec +17 -17
- data/test/fixtures/apps/render.rb +2 -2
- data/test/fixtures/markup_app/app.rb +9 -8
- data/test/fixtures/markup_app/views/button_to.erb +3 -3
- data/test/fixtures/markup_app/views/button_to.haml +2 -2
- data/test/fixtures/markup_app/views/button_to.slim +3 -3
- data/test/fixtures/markup_app/views/content_for.erb +4 -4
- data/test/fixtures/markup_app/views/content_for.haml +4 -4
- data/test/fixtures/markup_app/views/content_for.slim +2 -2
- data/test/fixtures/markup_app/views/content_tag.erb +3 -3
- data/test/fixtures/markup_app/views/content_tag.haml +3 -3
- data/test/fixtures/markup_app/views/content_tag.slim +3 -3
- data/test/fixtures/markup_app/views/fields_for.erb +2 -2
- data/test/fixtures/markup_app/views/fields_for.haml +2 -2
- data/test/fixtures/markup_app/views/fields_for.slim +2 -2
- data/test/fixtures/markup_app/views/form_for.erb +41 -41
- data/test/fixtures/markup_app/views/form_for.haml +41 -41
- data/test/fixtures/markup_app/views/form_for.slim +41 -42
- data/test/fixtures/markup_app/views/form_tag.erb +47 -47
- data/test/fixtures/markup_app/views/form_tag.haml +48 -48
- data/test/fixtures/markup_app/views/form_tag.slim +49 -49
- data/test/fixtures/markup_app/views/link_to.erb +2 -2
- data/test/fixtures/markup_app/views/link_to.haml +2 -2
- data/test/fixtures/markup_app/views/link_to.slim +2 -2
- data/test/fixtures/markup_app/views/meta_tag.erb +2 -2
- data/test/fixtures/markup_app/views/meta_tag.haml +2 -2
- data/test/fixtures/markup_app/views/meta_tag.slim +2 -2
- data/test/fixtures/markup_app/views/simple_partial.erb +1 -1
- data/test/fixtures/markup_app/views/simple_partial.haml +1 -1
- data/test/fixtures/markup_app/views/simple_partial.slim +1 -1
- data/test/fixtures/render_app/app.rb +13 -12
- data/test/fixtures/render_app/views/_unsafe.html.builder +1 -1
- data/test/fixtures/render_app/views/_unsafe_object.html.builder +1 -1
- data/test/fixtures/render_app/views/explicit_engine.haml +3 -3
- data/test/helper.rb +19 -19
- data/test/test_asset_tag_helpers.rb +133 -133
- data/test/test_form_builder.rb +629 -628
- data/test/test_form_helpers.rb +610 -610
- data/test/test_format_helpers.rb +66 -63
- data/test/test_helpers.rb +2 -2
- data/test/test_locale.rb +13 -11
- data/test/test_number_helpers.rb +65 -65
- data/test/test_output_helpers.rb +76 -76
- data/test/test_render_helpers.rb +101 -101
- data/test/test_rendering.rb +329 -326
- data/test/test_rendering_extensions.rb +4 -4
- data/test/test_tag_helpers.rb +55 -55
- metadata +6 -6
data/test/test_rendering.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'helper'
|
|
2
2
|
require 'slim'
|
|
3
3
|
require 'liquid'
|
|
4
4
|
|
|
5
|
-
describe
|
|
5
|
+
describe 'Rendering' do
|
|
6
6
|
def setup
|
|
7
7
|
Padrino::Rendering::DEFAULT_RENDERING_OPTIONS[:strict_format] = false
|
|
8
8
|
I18n.enforce_available_locales = true
|
|
@@ -14,84 +14,83 @@ describe "Rendering" do
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
describe 'for application layout functionality' do
|
|
17
|
-
|
|
18
17
|
it 'should get no layout' do
|
|
19
18
|
mock_app do
|
|
20
|
-
get(
|
|
19
|
+
get('/') { 'no layout' }
|
|
21
20
|
end
|
|
22
21
|
|
|
23
|
-
get
|
|
24
|
-
assert_equal
|
|
22
|
+
get '/'
|
|
23
|
+
assert_equal 'no layout', body
|
|
25
24
|
end
|
|
26
25
|
|
|
27
26
|
it 'should be compatible with sinatra layout' do
|
|
28
27
|
mock_app do
|
|
29
28
|
layout do
|
|
30
|
-
|
|
29
|
+
'this is a <%= yield %>'
|
|
31
30
|
end
|
|
32
31
|
|
|
33
|
-
get(
|
|
32
|
+
get('/') { render :erb, 'sinatra layout', layout: true }
|
|
34
33
|
end
|
|
35
34
|
|
|
36
|
-
get
|
|
37
|
-
assert_equal
|
|
35
|
+
get '/'
|
|
36
|
+
assert_equal 'this is a sinatra layout', body
|
|
38
37
|
end
|
|
39
38
|
|
|
40
39
|
it 'should use rails way layout' do
|
|
41
|
-
with_layout :application,
|
|
40
|
+
with_layout :application, 'this is a <%= yield %>' do
|
|
42
41
|
mock_app do
|
|
43
|
-
get(
|
|
42
|
+
get('/') { render :erb, 'rails way layout' }
|
|
44
43
|
end
|
|
45
44
|
|
|
46
|
-
get
|
|
47
|
-
assert_equal
|
|
45
|
+
get '/'
|
|
46
|
+
assert_equal 'this is a rails way layout', body
|
|
48
47
|
end
|
|
49
48
|
end
|
|
50
49
|
|
|
51
50
|
it 'should use rails way for a custom layout' do
|
|
52
|
-
with_layout
|
|
51
|
+
with_layout 'layouts/custom', 'this is a <%= yield %>' do
|
|
53
52
|
mock_app do
|
|
54
53
|
layout :custom
|
|
55
|
-
get(
|
|
54
|
+
get('/') { render :erb, 'rails way custom layout' }
|
|
56
55
|
end
|
|
57
56
|
|
|
58
|
-
get
|
|
59
|
-
assert_equal
|
|
57
|
+
get '/'
|
|
58
|
+
assert_equal 'this is a rails way custom layout', body
|
|
60
59
|
end
|
|
61
60
|
end
|
|
62
61
|
|
|
63
62
|
it 'should not use layout' do
|
|
64
|
-
with_layout :application,
|
|
65
|
-
with_view :index,
|
|
63
|
+
with_layout :application, 'this is an <%= yield %>' do
|
|
64
|
+
with_view :index, 'index' do
|
|
66
65
|
mock_app do
|
|
67
|
-
get(
|
|
68
|
-
get(
|
|
66
|
+
get('/with/layout') { render :index }
|
|
67
|
+
get('/without/layout') { render :index, layout: false }
|
|
69
68
|
end
|
|
70
|
-
get
|
|
71
|
-
assert_equal
|
|
72
|
-
get
|
|
73
|
-
assert_equal
|
|
69
|
+
get '/with/layout'
|
|
70
|
+
assert_equal 'this is an index', body
|
|
71
|
+
get '/without/layout'
|
|
72
|
+
assert_equal 'index', body
|
|
74
73
|
end
|
|
75
74
|
end
|
|
76
75
|
end
|
|
77
76
|
|
|
78
77
|
it 'should not use layout with js format' do
|
|
79
|
-
create_layout :application,
|
|
80
|
-
create_view :foo,
|
|
81
|
-
create_view :foo,
|
|
78
|
+
create_layout :application, 'this is an <%= yield %>'
|
|
79
|
+
create_view :foo, 'erb file'
|
|
80
|
+
create_view :foo, 'js file', format: :js
|
|
82
81
|
mock_app do
|
|
83
|
-
get('/layout_test', :
|
|
82
|
+
get('/layout_test', provides: %i[html js]) { render :foo }
|
|
84
83
|
end
|
|
85
|
-
get
|
|
86
|
-
assert_equal
|
|
87
|
-
get
|
|
88
|
-
assert_equal
|
|
84
|
+
get '/layout_test'
|
|
85
|
+
assert_equal 'this is an erb file', body
|
|
86
|
+
get '/layout_test.js'
|
|
87
|
+
assert_equal 'js file', body
|
|
89
88
|
end
|
|
90
89
|
|
|
91
90
|
it 'should set and restore layout in controllers' do
|
|
92
|
-
create_layout :boo,
|
|
93
|
-
create_layout :moo,
|
|
94
|
-
create_view :foo,
|
|
91
|
+
create_layout :boo, 'boo is a <%= yield %>'
|
|
92
|
+
create_layout :moo, 'moo is a <%= yield %>'
|
|
93
|
+
create_view :foo, 'liquid file', format: :liquid
|
|
95
94
|
mock_app do
|
|
96
95
|
layout :boo
|
|
97
96
|
controller :moo do
|
|
@@ -102,49 +101,49 @@ describe "Rendering" do
|
|
|
102
101
|
get('/liquid') { render :foo }
|
|
103
102
|
end
|
|
104
103
|
end
|
|
105
|
-
get
|
|
106
|
-
assert_equal
|
|
107
|
-
get
|
|
108
|
-
assert_equal
|
|
104
|
+
get '/moo/liquid'
|
|
105
|
+
assert_equal 'moo is a liquid file', body
|
|
106
|
+
get '/boo/liquid'
|
|
107
|
+
assert_equal 'boo is a liquid file', body
|
|
109
108
|
end
|
|
110
109
|
|
|
111
110
|
it 'should use correct layout for each format' do
|
|
112
|
-
create_layout :application,
|
|
113
|
-
create_layout :application,
|
|
114
|
-
create_view :foo,
|
|
115
|
-
create_view :foo,
|
|
111
|
+
create_layout :application, 'this is an <%= yield %>'
|
|
112
|
+
create_layout :application, 'document start <%= yield %> end', format: :xml
|
|
113
|
+
create_view :foo, 'erb file'
|
|
114
|
+
create_view :foo, 'xml file', format: :xml
|
|
116
115
|
mock_app do
|
|
117
|
-
get('/layout_test', :
|
|
116
|
+
get('/layout_test', provides: %i[html xml]) { render :foo }
|
|
118
117
|
end
|
|
119
|
-
get
|
|
120
|
-
assert_equal
|
|
121
|
-
get
|
|
122
|
-
assert_equal
|
|
118
|
+
get '/layout_test'
|
|
119
|
+
assert_equal 'this is an erb file', body
|
|
120
|
+
get '/layout_test.xml'
|
|
121
|
+
assert_equal 'document start xml file end', body
|
|
123
122
|
end
|
|
124
123
|
|
|
125
124
|
it 'should by default use html file when no other is given' do
|
|
126
|
-
create_layout :baz,
|
|
125
|
+
create_layout :baz, 'html file', format: :html
|
|
127
126
|
|
|
128
127
|
mock_app do
|
|
129
|
-
get('/content_type_test', :
|
|
128
|
+
get('/content_type_test', provides: %i[html xml]) { render :baz }
|
|
130
129
|
end
|
|
131
130
|
|
|
132
|
-
get
|
|
133
|
-
assert_equal
|
|
134
|
-
get
|
|
135
|
-
assert_equal
|
|
136
|
-
get
|
|
137
|
-
assert_equal
|
|
131
|
+
get '/content_type_test'
|
|
132
|
+
assert_equal 'html file', body
|
|
133
|
+
get '/content_type_test.html'
|
|
134
|
+
assert_equal 'html file', body
|
|
135
|
+
get '/content_type_test.xml'
|
|
136
|
+
assert_equal 'html file', body
|
|
138
137
|
end
|
|
139
138
|
|
|
140
139
|
it 'should find proper templates when content_type is set by string' do
|
|
141
|
-
create_layout :error,
|
|
142
|
-
create_view :e404,
|
|
140
|
+
create_layout :error, 'layout<%= yield %>'
|
|
141
|
+
create_view :e404, '404 file'
|
|
143
142
|
|
|
144
143
|
mock_app do
|
|
145
144
|
not_found do
|
|
146
145
|
content_type 'text/html'
|
|
147
|
-
render 'e404', :
|
|
146
|
+
render 'e404', layout: :error
|
|
148
147
|
end
|
|
149
148
|
end
|
|
150
149
|
get '/missing'
|
|
@@ -152,301 +151,300 @@ describe "Rendering" do
|
|
|
152
151
|
end
|
|
153
152
|
|
|
154
153
|
it 'should work with set content type not contained in rack-types' do
|
|
155
|
-
create_view
|
|
154
|
+
create_view 'index.md.erb', 'Hello'
|
|
156
155
|
mock_app do
|
|
157
|
-
get(
|
|
158
|
-
content_type
|
|
159
|
-
render
|
|
160
|
-
|
|
156
|
+
get('/') do
|
|
157
|
+
content_type 'text/x-markdown; charset=UTF-8'
|
|
158
|
+
render 'index.erb', { layout: nil }
|
|
159
|
+
end
|
|
161
160
|
end
|
|
162
|
-
get
|
|
163
|
-
assert_equal
|
|
161
|
+
get '/'
|
|
162
|
+
assert_equal 'Hello', body
|
|
164
163
|
end
|
|
165
164
|
|
|
166
165
|
it 'should not use html file when DEFAULT_RENDERING_OPTIONS[:strict_format] == true' do
|
|
167
|
-
create_layout :foo,
|
|
166
|
+
create_layout :foo, 'html file', format: :html
|
|
168
167
|
|
|
169
168
|
mock_app do
|
|
170
|
-
get('/default_rendering_test', :
|
|
169
|
+
get('/default_rendering_test', provides: %i[html xml]) { render :foo }
|
|
171
170
|
end
|
|
172
171
|
|
|
173
172
|
@save = Padrino::Rendering::DEFAULT_RENDERING_OPTIONS
|
|
174
173
|
Padrino::Rendering::DEFAULT_RENDERING_OPTIONS[:strict_format] = true
|
|
175
174
|
|
|
176
|
-
get
|
|
177
|
-
assert_equal
|
|
175
|
+
get '/default_rendering_test'
|
|
176
|
+
assert_equal 'html file', body
|
|
178
177
|
assert_raises Padrino::Rendering::TemplateNotFound do
|
|
179
|
-
get
|
|
178
|
+
get '/default_rendering_test.xml'
|
|
180
179
|
end
|
|
181
180
|
|
|
182
181
|
Padrino::Rendering::DEFAULT_RENDERING_OPTIONS.merge!(@save)
|
|
183
182
|
end
|
|
184
183
|
|
|
185
184
|
it 'should use correct layout with each controller' do
|
|
186
|
-
create_layout :foo,
|
|
187
|
-
create_layout :bar,
|
|
188
|
-
create_layout :baz,
|
|
189
|
-
create_layout :application,
|
|
185
|
+
create_layout :foo, 'foo layout at <%= yield %>'
|
|
186
|
+
create_layout :bar, 'bar layout at <%= yield %>'
|
|
187
|
+
create_layout :baz, 'baz layout at <%= yield %>'
|
|
188
|
+
create_layout :application, 'default layout at <%= yield %>'
|
|
190
189
|
mock_app do
|
|
191
|
-
get(
|
|
190
|
+
get('/') { render :erb, 'application' }
|
|
192
191
|
controller :foo do
|
|
193
192
|
layout :foo
|
|
194
|
-
get(
|
|
193
|
+
get('/') { render :erb, 'foo' }
|
|
195
194
|
end
|
|
196
195
|
controller :bar do
|
|
197
196
|
layout :bar
|
|
198
|
-
get(
|
|
197
|
+
get('/') { render :erb, 'bar' }
|
|
199
198
|
end
|
|
200
199
|
controller :baz do
|
|
201
200
|
layout :baz
|
|
202
|
-
get(
|
|
201
|
+
get('/') { render :erb, 'baz', layout: true }
|
|
203
202
|
end
|
|
204
203
|
controller :none do
|
|
205
|
-
get(
|
|
206
|
-
get(
|
|
207
|
-
end
|
|
208
|
-
end
|
|
209
|
-
get
|
|
210
|
-
assert_equal
|
|
211
|
-
get
|
|
212
|
-
assert_equal
|
|
213
|
-
get
|
|
214
|
-
assert_equal
|
|
215
|
-
get
|
|
216
|
-
assert_equal
|
|
217
|
-
get
|
|
218
|
-
assert_equal
|
|
219
|
-
get
|
|
220
|
-
assert_equal
|
|
204
|
+
get('/') { render :erb, 'none' }
|
|
205
|
+
get('/with_foo_layout') { render :erb, 'none with layout', layout: :foo }
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
get '/foo'
|
|
209
|
+
assert_equal 'foo layout at foo', body
|
|
210
|
+
get '/bar'
|
|
211
|
+
assert_equal 'bar layout at bar', body
|
|
212
|
+
get '/baz'
|
|
213
|
+
assert_equal 'baz layout at baz', body
|
|
214
|
+
get '/none'
|
|
215
|
+
assert_equal 'default layout at none', body
|
|
216
|
+
get '/none/with_foo_layout'
|
|
217
|
+
assert_equal 'foo layout at none with layout', body
|
|
218
|
+
get '/'
|
|
219
|
+
assert_equal 'default layout at application', body
|
|
221
220
|
end
|
|
222
221
|
end
|
|
223
222
|
|
|
224
223
|
it 'should solve layout in layouts paths' do
|
|
225
|
-
create_layout :foo,
|
|
226
|
-
create_layout :"layouts/bar",
|
|
224
|
+
create_layout :foo, 'foo layout <%= yield %>'
|
|
225
|
+
create_layout :"layouts/bar", 'bar layout <%= yield %>'
|
|
227
226
|
mock_app do
|
|
228
|
-
get(
|
|
229
|
-
get(
|
|
230
|
-
get(
|
|
231
|
-
end
|
|
232
|
-
get
|
|
233
|
-
assert_equal
|
|
234
|
-
get
|
|
235
|
-
assert_equal
|
|
236
|
-
get
|
|
237
|
-
assert_equal
|
|
227
|
+
get('/') { render :erb, 'none' }
|
|
228
|
+
get('/foo') { render :erb, 'foo', layout: :foo }
|
|
229
|
+
get('/bar') { render :erb, 'bar', layout: :bar }
|
|
230
|
+
end
|
|
231
|
+
get '/'
|
|
232
|
+
assert_equal 'none', body
|
|
233
|
+
get '/foo'
|
|
234
|
+
assert_equal 'foo layout foo', body
|
|
235
|
+
get '/bar'
|
|
236
|
+
assert_equal 'bar layout bar', body
|
|
238
237
|
end
|
|
239
238
|
|
|
240
239
|
it 'should allow to render template with layout option that using other template engine.' do
|
|
241
|
-
create_layout :"layouts/foo",
|
|
242
|
-
create_view :slim,
|
|
243
|
-
create_view :haml,
|
|
244
|
-
create_view :erb,
|
|
240
|
+
create_layout :"layouts/foo", 'application layout for <%= yield %>', format: :erb
|
|
241
|
+
create_view :slim, '| slim', format: :slim
|
|
242
|
+
create_view :haml, 'haml', format: :haml
|
|
243
|
+
create_view :erb, 'erb', format: :erb
|
|
245
244
|
mock_app do
|
|
246
|
-
get(
|
|
247
|
-
get(
|
|
248
|
-
get(
|
|
249
|
-
end
|
|
250
|
-
get
|
|
251
|
-
assert_equal
|
|
252
|
-
get
|
|
253
|
-
assert_equal
|
|
254
|
-
get
|
|
255
|
-
assert_equal
|
|
245
|
+
get('/slim') { render('slim.slim', layout: 'foo.erb') }
|
|
246
|
+
get('/haml') { render('haml.haml', layout: 'foo.erb') }
|
|
247
|
+
get('/erb') { render('erb.erb', layout: 'foo.erb') }
|
|
248
|
+
end
|
|
249
|
+
get '/slim'
|
|
250
|
+
assert_equal 'application layout for slim', body.chomp
|
|
251
|
+
get '/haml'
|
|
252
|
+
assert_equal 'application layout for haml', body.chomp
|
|
253
|
+
get '/erb'
|
|
254
|
+
assert_equal 'application layout for erb', body.chomp
|
|
256
255
|
end
|
|
257
256
|
|
|
258
257
|
it 'should allow to use extension with layout method.' do
|
|
259
|
-
create_layout :"layouts/bar",
|
|
260
|
-
create_view :slim,
|
|
261
|
-
create_view :haml,
|
|
262
|
-
create_view :erb,
|
|
258
|
+
create_layout :"layouts/bar", 'application layout for <%= yield %>', format: :erb
|
|
259
|
+
create_view :slim, '| slim', format: :slim
|
|
260
|
+
create_view :haml, 'haml', format: :haml
|
|
261
|
+
create_view :erb, 'erb', format: :erb
|
|
263
262
|
mock_app do
|
|
264
|
-
layout
|
|
265
|
-
get(
|
|
266
|
-
get(
|
|
267
|
-
get(
|
|
268
|
-
end
|
|
269
|
-
get
|
|
270
|
-
assert_equal
|
|
271
|
-
get
|
|
272
|
-
assert_equal
|
|
273
|
-
get
|
|
274
|
-
assert_equal
|
|
263
|
+
layout 'bar.erb'
|
|
264
|
+
get('/slim') { render('slim.slim') }
|
|
265
|
+
get('/haml') { render('haml.haml') }
|
|
266
|
+
get('/erb') { render('erb.erb') }
|
|
267
|
+
end
|
|
268
|
+
get '/slim'
|
|
269
|
+
assert_equal 'application layout for slim', body.chomp
|
|
270
|
+
get '/haml'
|
|
271
|
+
assert_equal 'application layout for haml', body.chomp
|
|
272
|
+
get '/erb'
|
|
273
|
+
assert_equal 'application layout for erb', body.chomp
|
|
275
274
|
end
|
|
276
275
|
|
|
277
276
|
it 'should find a layout by symbol' do
|
|
278
|
-
create_layout :"layouts/bar",
|
|
279
|
-
create_view :slim,
|
|
280
|
-
create_view :haml,
|
|
281
|
-
create_view :erb,
|
|
277
|
+
create_layout :"layouts/bar", 'application layout for <%= yield %>', format: :erb
|
|
278
|
+
create_view :slim, '| slim', format: :slim
|
|
279
|
+
create_view :haml, 'haml', format: :haml
|
|
280
|
+
create_view :erb, 'erb', format: :erb
|
|
282
281
|
mock_app do
|
|
283
282
|
layout :bar
|
|
284
|
-
get(
|
|
285
|
-
get(
|
|
286
|
-
get(
|
|
287
|
-
end
|
|
288
|
-
get
|
|
289
|
-
assert_equal
|
|
290
|
-
get
|
|
291
|
-
assert_equal
|
|
292
|
-
get
|
|
293
|
-
assert_equal
|
|
283
|
+
get('/slim') { render('slim.slim') }
|
|
284
|
+
get('/haml') { render('haml.haml') }
|
|
285
|
+
get('/erb') { render('erb.erb') }
|
|
286
|
+
end
|
|
287
|
+
get '/slim'
|
|
288
|
+
assert_equal 'application layout for slim', body.chomp
|
|
289
|
+
get '/haml'
|
|
290
|
+
assert_equal 'application layout for haml', body.chomp
|
|
291
|
+
get '/erb'
|
|
292
|
+
assert_equal 'application layout for erb', body.chomp
|
|
294
293
|
end
|
|
295
294
|
|
|
296
295
|
it 'should not apply default layout to unsupported layout engines' do
|
|
297
|
-
create_layout :application,
|
|
298
|
-
create_view 'foo',
|
|
296
|
+
create_layout :application, 'erb template <%= yield %>', format: :erb
|
|
297
|
+
create_view 'foo', 'xml.instruct!', format: :builder
|
|
299
298
|
mock_app do
|
|
300
|
-
get('/layout_test.xml'
|
|
299
|
+
get('/layout_test.xml') { render :foo }
|
|
301
300
|
end
|
|
302
|
-
get
|
|
303
|
-
refute_match
|
|
301
|
+
get '/layout_test.xml'
|
|
302
|
+
refute_match(/erb template/, body)
|
|
304
303
|
assert_match '<?xml', body
|
|
305
304
|
end
|
|
306
305
|
|
|
307
306
|
describe 'for application render functionality' do
|
|
308
|
-
|
|
309
307
|
it 'should work properly with logging and missing layout' do
|
|
310
|
-
create_view :index,
|
|
308
|
+
create_view :index, '<%= foo %>'
|
|
311
309
|
mock_app do
|
|
312
310
|
enable :logging
|
|
313
|
-
get(
|
|
311
|
+
get('/') { render 'index', { layout: nil }, { foo: 'bar' } }
|
|
314
312
|
end
|
|
315
|
-
get
|
|
316
|
-
assert_equal
|
|
313
|
+
get '/'
|
|
314
|
+
assert_equal 'bar', body
|
|
317
315
|
end
|
|
318
316
|
|
|
319
317
|
it 'should work properly with logging and layout' do
|
|
320
|
-
create_layout :application,
|
|
321
|
-
create_view :index,
|
|
318
|
+
create_layout :application, 'layout <%= yield %>'
|
|
319
|
+
create_view :index, '<%= foo %>'
|
|
322
320
|
mock_app do
|
|
323
321
|
enable :logging
|
|
324
|
-
get(
|
|
322
|
+
get('/') { render 'index', { layout: true }, { foo: 'bar' } }
|
|
325
323
|
end
|
|
326
|
-
get
|
|
327
|
-
assert_equal
|
|
324
|
+
get '/'
|
|
325
|
+
assert_equal 'layout bar', body
|
|
328
326
|
end
|
|
329
327
|
|
|
330
328
|
it 'should be compatible with sinatra render' do
|
|
331
329
|
mock_app do
|
|
332
|
-
get(
|
|
330
|
+
get('/') { render :erb, '<%= 1+2 %>' }
|
|
333
331
|
end
|
|
334
|
-
get
|
|
335
|
-
assert_equal
|
|
332
|
+
get '/'
|
|
333
|
+
assert_equal '3', body
|
|
336
334
|
end
|
|
337
335
|
|
|
338
336
|
it 'should support passing locals into render' do
|
|
339
|
-
create_layout :application,
|
|
340
|
-
create_view :index,
|
|
337
|
+
create_layout :application, 'layout <%= yield %>'
|
|
338
|
+
create_view :index, '<%= foo %>'
|
|
341
339
|
mock_app do
|
|
342
|
-
get(
|
|
340
|
+
get('/') { render 'index', { layout: true }, { foo: 'bar' } }
|
|
343
341
|
end
|
|
344
|
-
get
|
|
345
|
-
assert_equal
|
|
342
|
+
get '/'
|
|
343
|
+
assert_equal 'layout bar', body
|
|
346
344
|
end
|
|
347
345
|
|
|
348
346
|
it 'should support passing locals into sinatra render' do
|
|
349
|
-
create_layout :application,
|
|
350
|
-
create_view :index,
|
|
347
|
+
create_layout :application, 'layout <%= yield %>'
|
|
348
|
+
create_view :index, '<%= foo %>'
|
|
351
349
|
mock_app do
|
|
352
|
-
get(
|
|
350
|
+
get('/') { render :erb, :index, { layout: true }, { foo: 'bar' } }
|
|
353
351
|
end
|
|
354
|
-
get
|
|
355
|
-
assert_equal
|
|
352
|
+
get '/'
|
|
353
|
+
assert_equal 'layout bar', body
|
|
356
354
|
end
|
|
357
355
|
|
|
358
356
|
it 'should support passing locals into special nil engine render' do
|
|
359
|
-
create_layout :application,
|
|
360
|
-
create_view :index,
|
|
357
|
+
create_layout :application, 'layout <%= yield %>'
|
|
358
|
+
create_view :index, '<%= foo %>'
|
|
361
359
|
mock_app do
|
|
362
|
-
get(
|
|
360
|
+
get('/') { render nil, :index, { layout: true }, { foo: 'bar' } }
|
|
363
361
|
end
|
|
364
|
-
get
|
|
365
|
-
assert_equal
|
|
362
|
+
get '/'
|
|
363
|
+
assert_equal 'layout bar', body
|
|
366
364
|
end
|
|
367
365
|
|
|
368
366
|
it 'should be compatible with sinatra views' do
|
|
369
|
-
with_view :index,
|
|
367
|
+
with_view :index, '<%= 1+2 %>' do
|
|
370
368
|
mock_app do
|
|
371
|
-
get(
|
|
372
|
-
get(
|
|
373
|
-
get(
|
|
374
|
-
get(
|
|
375
|
-
get(
|
|
369
|
+
get('/foo') { render :erb, :index }
|
|
370
|
+
get('/bar') { erb :index }
|
|
371
|
+
get('/dir') { '3' }
|
|
372
|
+
get('/inj') { erb '<%= 2+1 %>' }
|
|
373
|
+
get('/rnj') { render :erb, '<%= 2+1 %>' }
|
|
376
374
|
end
|
|
377
|
-
get
|
|
378
|
-
assert_equal
|
|
379
|
-
get
|
|
380
|
-
assert_equal
|
|
381
|
-
get
|
|
382
|
-
assert_equal
|
|
383
|
-
get
|
|
384
|
-
assert_equal
|
|
385
|
-
get
|
|
386
|
-
assert_equal
|
|
375
|
+
get '/foo'
|
|
376
|
+
assert_equal '3', body
|
|
377
|
+
get '/bar'
|
|
378
|
+
assert_equal '3', body
|
|
379
|
+
get '/dir'
|
|
380
|
+
assert_equal '3', body
|
|
381
|
+
get '/inj'
|
|
382
|
+
assert_equal '3', body
|
|
383
|
+
get '/rnj'
|
|
384
|
+
assert_equal '3', body
|
|
387
385
|
end
|
|
388
386
|
end
|
|
389
387
|
|
|
390
388
|
it 'should resolve template engine' do
|
|
391
|
-
with_view :index,
|
|
389
|
+
with_view :index, '<%= 1+2 %>' do
|
|
392
390
|
mock_app do
|
|
393
|
-
get(
|
|
394
|
-
get(
|
|
391
|
+
get('/foo') { render :index }
|
|
392
|
+
get('/bar') { render '/index' }
|
|
395
393
|
end
|
|
396
|
-
get
|
|
397
|
-
assert_equal
|
|
398
|
-
get
|
|
399
|
-
assert_equal
|
|
394
|
+
get '/foo'
|
|
395
|
+
assert_equal '3', body
|
|
396
|
+
get '/bar'
|
|
397
|
+
assert_equal '3', body
|
|
400
398
|
end
|
|
401
399
|
end
|
|
402
400
|
|
|
403
401
|
it 'should resolve template content type' do
|
|
404
|
-
create_view :foo,
|
|
405
|
-
create_view :foo,
|
|
402
|
+
create_view :foo, 'Im Js', format: :js
|
|
403
|
+
create_view :foo, 'Im Erb'
|
|
406
404
|
mock_app do
|
|
407
|
-
get(
|
|
408
|
-
get(
|
|
405
|
+
get('/foo', provides: :js) { render :foo }
|
|
406
|
+
get('/bar.js') { render :foo }
|
|
409
407
|
end
|
|
410
|
-
get
|
|
411
|
-
assert_equal
|
|
408
|
+
get '/foo.js'
|
|
409
|
+
assert_equal 'Im Js', body
|
|
412
410
|
# TODO: implement this!
|
|
413
411
|
# get "/bar.js"
|
|
414
412
|
# assert_equal "Im Js", body
|
|
415
413
|
end
|
|
416
414
|
|
|
417
415
|
it 'should resolve with explicit template format' do
|
|
418
|
-
create_view :foo,
|
|
419
|
-
create_view :foo,
|
|
420
|
-
create_view :foo,
|
|
416
|
+
create_view :foo, 'Im Js', format: :js
|
|
417
|
+
create_view :foo, 'Im Haml', format: :haml
|
|
418
|
+
create_view :foo, 'Im Xml', format: :xml
|
|
421
419
|
mock_app do
|
|
422
|
-
get(
|
|
423
|
-
get(
|
|
424
|
-
get(
|
|
420
|
+
get('/foo_normal', provides: :js) { render 'foo' }
|
|
421
|
+
get('/foo_haml', provides: :js) { render 'foo.haml' }
|
|
422
|
+
get('/foo_xml', provides: :js) { render 'foo.xml' }
|
|
425
423
|
end
|
|
426
|
-
get
|
|
427
|
-
assert_equal
|
|
428
|
-
get
|
|
424
|
+
get '/foo_normal.js'
|
|
425
|
+
assert_equal 'Im Js', body
|
|
426
|
+
get '/foo_haml.js'
|
|
429
427
|
assert_equal "Im Haml\n", body
|
|
430
|
-
get
|
|
431
|
-
assert_equal
|
|
428
|
+
get '/foo_xml.js'
|
|
429
|
+
assert_equal 'Im Xml', body
|
|
432
430
|
end
|
|
433
431
|
|
|
434
432
|
it 'should resolve without explict template format' do
|
|
435
|
-
create_view :foo,
|
|
436
|
-
create_view :foo,
|
|
433
|
+
create_view :foo, 'Im Html'
|
|
434
|
+
create_view :foo, 'xml.rss', format: :rss
|
|
437
435
|
mock_app do
|
|
438
|
-
get(:index, :
|
|
436
|
+
get(:index, map: '/', provides: %i[html rss]) { render 'foo' }
|
|
439
437
|
end
|
|
440
|
-
get
|
|
441
|
-
assert_equal
|
|
442
|
-
get
|
|
438
|
+
get '/', {}, { 'HTTP_ACCEPT' => 'text/html;q=0.9' }
|
|
439
|
+
assert_equal 'Im Html', body
|
|
440
|
+
get '.rss'
|
|
443
441
|
assert_equal "<rss/>\n", body
|
|
444
442
|
end
|
|
445
443
|
|
|
446
444
|
it 'should ignore files ending in tilde and not render them' do
|
|
447
|
-
create_view :foo,
|
|
448
|
-
create_view :foo,
|
|
449
|
-
create_view :bar,
|
|
445
|
+
create_view :foo, 'Im Wrong', format: 'haml~'
|
|
446
|
+
create_view :foo, 'Im Haml', format: :haml
|
|
447
|
+
create_view :bar, 'Im Haml backup', format: 'haml~'
|
|
450
448
|
mock_app do
|
|
451
449
|
get('/foo') { render 'foo' }
|
|
452
450
|
get('/bar') { render 'bar' }
|
|
@@ -457,57 +455,58 @@ describe "Rendering" do
|
|
|
457
455
|
end
|
|
458
456
|
|
|
459
457
|
it 'should resolve template locale' do
|
|
460
|
-
create_view :foo,
|
|
461
|
-
create_view :foo,
|
|
458
|
+
create_view :foo, 'Im English', locale: :en
|
|
459
|
+
create_view :foo, 'Im Italian', locale: :it
|
|
462
460
|
mock_app do
|
|
463
|
-
get(
|
|
461
|
+
get('/foo') { render :foo }
|
|
464
462
|
end
|
|
465
463
|
I18n.locale = :en
|
|
466
|
-
get
|
|
467
|
-
assert_equal
|
|
464
|
+
get '/foo'
|
|
465
|
+
assert_equal 'Im English', body
|
|
468
466
|
I18n.locale = :it
|
|
469
|
-
get
|
|
470
|
-
assert_equal
|
|
467
|
+
get '/foo'
|
|
468
|
+
assert_equal 'Im Italian', body
|
|
471
469
|
end
|
|
472
470
|
|
|
473
471
|
it 'should resolve template content_type and locale' do
|
|
474
|
-
create_view :foo,
|
|
475
|
-
create_view :foo,
|
|
476
|
-
create_view :foo,
|
|
477
|
-
create_view :foo,
|
|
478
|
-
create_view :foo,
|
|
479
|
-
create_view :foo,
|
|
472
|
+
create_view :foo, 'Im Erb'
|
|
473
|
+
create_view :foo, 'Im English Erb', locale: :en
|
|
474
|
+
create_view :foo, 'Im Italian Erb', locale: :it
|
|
475
|
+
create_view :foo, 'Im Js', format: :js
|
|
476
|
+
create_view :foo, 'Im English Js', format: :js, locale: :en
|
|
477
|
+
create_view :foo, 'Im Italian Js', format: :js, locale: :it
|
|
478
|
+
|
|
480
479
|
mock_app do
|
|
481
|
-
get(
|
|
480
|
+
get('/foo', provides: %i[html js]) { render :foo }
|
|
482
481
|
end
|
|
483
482
|
|
|
484
483
|
I18n.enforce_available_locales = false
|
|
485
484
|
I18n.locale = :none
|
|
486
|
-
get
|
|
487
|
-
assert_equal
|
|
488
|
-
get
|
|
489
|
-
assert_equal
|
|
485
|
+
get '/foo.js'
|
|
486
|
+
assert_equal 'Im Js', body
|
|
487
|
+
get '/foo'
|
|
488
|
+
assert_equal 'Im Erb', body
|
|
490
489
|
I18n.enforce_available_locales = true
|
|
491
490
|
|
|
492
491
|
I18n.locale = :en
|
|
493
|
-
get
|
|
494
|
-
assert_equal
|
|
492
|
+
get '/foo'
|
|
493
|
+
assert_equal 'Im English Erb', body
|
|
495
494
|
I18n.locale = :it
|
|
496
|
-
get
|
|
497
|
-
assert_equal
|
|
495
|
+
get '/foo'
|
|
496
|
+
assert_equal 'Im Italian Erb', body
|
|
498
497
|
I18n.locale = :en
|
|
499
|
-
get
|
|
500
|
-
assert_equal
|
|
498
|
+
get '/foo.js'
|
|
499
|
+
assert_equal 'Im English Js', body
|
|
501
500
|
I18n.locale = :it
|
|
502
|
-
get
|
|
503
|
-
assert_equal
|
|
501
|
+
get '/foo.js'
|
|
502
|
+
assert_equal 'Im Italian Js', body
|
|
504
503
|
I18n.locale = :en
|
|
505
|
-
get
|
|
504
|
+
get '/foo.pk'
|
|
506
505
|
assert_equal 404, status
|
|
507
506
|
end
|
|
508
507
|
|
|
509
508
|
it 'should resolve layouts from specific application' do
|
|
510
|
-
require File.expand_path(
|
|
509
|
+
require File.expand_path("#{__dir__}/fixtures/apps/render")
|
|
511
510
|
@app = RenderDemo2
|
|
512
511
|
get '/blog/override'
|
|
513
512
|
assert_equal 'otay', body
|
|
@@ -515,68 +514,69 @@ describe "Rendering" do
|
|
|
515
514
|
|
|
516
515
|
it 'should resolve templates and layouts located in absolute paths' do
|
|
517
516
|
mock_app do
|
|
518
|
-
get(
|
|
517
|
+
get('/foo') { render 'apps/views/blog/post', layout: 'layout', views: "#{__dir__}/fixtures" }
|
|
519
518
|
end
|
|
520
519
|
get '/foo'
|
|
521
|
-
assert_match
|
|
520
|
+
assert_match(/okay absolute layout/, body)
|
|
522
521
|
end
|
|
523
522
|
|
|
524
523
|
it 'should resolve template content_type and locale with layout' do
|
|
525
|
-
create_layout :foo,
|
|
526
|
-
create_layout :foo,
|
|
527
|
-
create_layout :foo,
|
|
528
|
-
create_layout :foo,
|
|
529
|
-
create_layout :foo,
|
|
530
|
-
create_layout :foo,
|
|
531
|
-
|
|
532
|
-
create_view :bar,
|
|
533
|
-
create_view :bar,
|
|
534
|
-
create_view :bar,
|
|
535
|
-
create_view :bar,
|
|
536
|
-
create_view :bar,
|
|
537
|
-
create_view :bar,
|
|
524
|
+
create_layout :foo, 'Hello <%= yield %> in a Js layout', format: :js
|
|
525
|
+
create_layout :foo, 'Hello <%= yield %> in a Js-En layout', format: :js, locale: :en
|
|
526
|
+
create_layout :foo, 'Hello <%= yield %> in a Js-It layout', format: :js, locale: :it
|
|
527
|
+
create_layout :foo, 'Hello <%= yield %> in a Erb-En layout', locale: :en
|
|
528
|
+
create_layout :foo, 'Hello <%= yield %> in a Erb-It layout', locale: :it
|
|
529
|
+
create_layout :foo, 'Hello <%= yield %> in a Erb layout'
|
|
530
|
+
|
|
531
|
+
create_view :bar, 'Im Erb'
|
|
532
|
+
create_view :bar, 'Im English Erb', locale: :en
|
|
533
|
+
create_view :bar, 'Im Italian Erb', locale: :it
|
|
534
|
+
create_view :bar, 'Im Js', format: :js
|
|
535
|
+
create_view :bar, 'Im English Js', format: :js, locale: :en
|
|
536
|
+
create_view :bar, 'Im Italian Js', format: :js, locale: :it
|
|
537
|
+
create_view :bar, 'Im a json', format: :json
|
|
538
|
+
|
|
538
539
|
mock_app do
|
|
539
540
|
layout :foo
|
|
540
|
-
get(
|
|
541
|
+
get('/bar', provides: %i[html js json]) { render :bar }
|
|
541
542
|
end
|
|
542
543
|
|
|
543
544
|
I18n.enforce_available_locales = false
|
|
544
545
|
I18n.locale = :none
|
|
545
|
-
get
|
|
546
|
-
assert_equal
|
|
547
|
-
get
|
|
548
|
-
assert_equal
|
|
546
|
+
get '/bar.js'
|
|
547
|
+
assert_equal 'Hello Im Js in a Js layout', body
|
|
548
|
+
get '/bar'
|
|
549
|
+
assert_equal 'Hello Im Erb in a Erb layout', body
|
|
549
550
|
I18n.enforce_available_locales = true
|
|
550
551
|
|
|
551
552
|
I18n.locale = :en
|
|
552
|
-
get
|
|
553
|
-
assert_equal
|
|
553
|
+
get '/bar'
|
|
554
|
+
assert_equal 'Hello Im English Erb in a Erb-En layout', body
|
|
554
555
|
I18n.locale = :it
|
|
555
|
-
get
|
|
556
|
-
assert_equal
|
|
556
|
+
get '/bar'
|
|
557
|
+
assert_equal 'Hello Im Italian Erb in a Erb-It layout', body
|
|
557
558
|
I18n.locale = :en
|
|
558
|
-
get
|
|
559
|
-
assert_equal
|
|
559
|
+
get '/bar.js'
|
|
560
|
+
assert_equal 'Hello Im English Js in a Js-En layout', body
|
|
560
561
|
I18n.locale = :it
|
|
561
|
-
get
|
|
562
|
-
assert_equal
|
|
562
|
+
get '/bar.js'
|
|
563
|
+
assert_equal 'Hello Im Italian Js in a Js-It layout', body
|
|
563
564
|
I18n.locale = :en
|
|
564
|
-
get
|
|
565
|
-
assert_equal
|
|
566
|
-
get
|
|
565
|
+
get '/bar.json'
|
|
566
|
+
assert_equal 'Im a json', body
|
|
567
|
+
get '/bar.pk'
|
|
567
568
|
assert_equal 404, status
|
|
568
|
-
|
|
569
569
|
end
|
|
570
570
|
|
|
571
571
|
it 'should resolve template location relative to controller name' do
|
|
572
|
-
require File.expand_path(
|
|
572
|
+
require File.expand_path("#{__dir__}/fixtures/apps/render")
|
|
573
573
|
@app = RenderDemo2
|
|
574
574
|
get '/blog'
|
|
575
575
|
assert_equal 'okay', body
|
|
576
576
|
end
|
|
577
577
|
|
|
578
578
|
it 'should resolve nested template location relative to controller name' do
|
|
579
|
-
require File.expand_path(
|
|
579
|
+
require File.expand_path("#{__dir__}/fixtures/apps/render")
|
|
580
580
|
@app = RenderDemo2
|
|
581
581
|
get '/article/comment'
|
|
582
582
|
assert_equal 'okay comment', body
|
|
@@ -586,16 +586,19 @@ describe "Rendering" do
|
|
|
586
586
|
mock_app do
|
|
587
587
|
helpers do
|
|
588
588
|
def container
|
|
589
|
-
@_out_buf <<
|
|
589
|
+
@_out_buf << 'THIS.'
|
|
590
590
|
yield
|
|
591
|
-
@_out_buf <<
|
|
591
|
+
@_out_buf << 'SPARTA!'
|
|
592
592
|
end
|
|
593
|
-
|
|
593
|
+
|
|
594
|
+
def is; 'IS.'; end
|
|
594
595
|
end
|
|
596
|
+
|
|
595
597
|
get '/' do
|
|
596
598
|
render :erb, '<% container do %> <%= is %> <% end %>'
|
|
597
599
|
end
|
|
598
600
|
end
|
|
601
|
+
|
|
599
602
|
get '/'
|
|
600
603
|
assert ok?
|
|
601
604
|
assert_equal 'THIS. IS. SPARTA!', body
|
|
@@ -604,13 +607,13 @@ describe "Rendering" do
|
|
|
604
607
|
it 'should render erb to a SafeBuffer' do
|
|
605
608
|
mock_app do
|
|
606
609
|
layout do
|
|
607
|
-
|
|
610
|
+
'this is a <%= yield %>'
|
|
608
611
|
end
|
|
609
612
|
get '/' do
|
|
610
|
-
render :erb, '<p><%= %q{<script lang="ronin">alert("https://github.com/ronin-ruby/ronin")</script>} %></p>', :
|
|
613
|
+
render :erb, '<p><%= %q{<script lang="ronin">alert("https://github.com/ronin-ruby/ronin")</script>} %></p>', layout: false
|
|
611
614
|
end
|
|
612
615
|
get '/with_layout' do
|
|
613
|
-
render :erb, '<span>span</span>', :
|
|
616
|
+
render :erb, '<span>span</span>', layout: true
|
|
614
617
|
end
|
|
615
618
|
end
|
|
616
619
|
get '/'
|
|
@@ -626,29 +629,29 @@ describe "Rendering" do
|
|
|
626
629
|
skip if ENV['ERB_ENGINE'] == 'stdlib'
|
|
627
630
|
mock_app do
|
|
628
631
|
layout do
|
|
629
|
-
|
|
632
|
+
'<%= yield %>'
|
|
630
633
|
end
|
|
631
634
|
|
|
632
|
-
get
|
|
633
|
-
render
|
|
635
|
+
get '/' do
|
|
636
|
+
render :erb, '<%== "<script></script>" %>'
|
|
634
637
|
end
|
|
635
638
|
end
|
|
636
639
|
|
|
637
|
-
get
|
|
640
|
+
get '/'
|
|
638
641
|
assert ok?
|
|
639
|
-
assert_equal
|
|
642
|
+
assert_equal '<script></script>', body
|
|
640
643
|
end
|
|
641
644
|
|
|
642
645
|
it 'should render haml to a SafeBuffer' do
|
|
643
646
|
mock_app do
|
|
644
647
|
layout do
|
|
645
|
-
|
|
648
|
+
'%p= yield'
|
|
646
649
|
end
|
|
647
650
|
get '/' do
|
|
648
|
-
render :haml, '%p= %s{<script lang="ronin">alert("https://github.com/ronin-ruby/ronin")</script>}', :
|
|
651
|
+
render :haml, '%p= %s{<script lang="ronin">alert("https://github.com/ronin-ruby/ronin")</script>}', layout: false
|
|
649
652
|
end
|
|
650
653
|
get '/with_layout' do
|
|
651
|
-
render :haml, "%div\n foo", :
|
|
654
|
+
render :haml, "%div\n foo", layout: true
|
|
652
655
|
end
|
|
653
656
|
end
|
|
654
657
|
get '/'
|
|
@@ -657,19 +660,19 @@ describe "Rendering" do
|
|
|
657
660
|
|
|
658
661
|
get 'with_layout'
|
|
659
662
|
assert ok?
|
|
660
|
-
assert_equal '<p><div>foo</div></p>', body.gsub(/\s+/,
|
|
663
|
+
assert_equal '<p><div>foo</div></p>', body.gsub(/\s+/, '')
|
|
661
664
|
end
|
|
662
665
|
|
|
663
666
|
it 'should render slim to a SafeBuffer' do
|
|
664
667
|
mock_app do
|
|
665
668
|
layout do
|
|
666
|
-
|
|
669
|
+
'p= yield'
|
|
667
670
|
end
|
|
668
671
|
get '/' do
|
|
669
|
-
render :slim, 'p = %q{<script lang="ronin">alert("https://github.com/ronin-ruby/ronin")</script>}', :
|
|
672
|
+
render :slim, 'p = %q{<script lang="ronin">alert("https://github.com/ronin-ruby/ronin")</script>}', layout: false
|
|
670
673
|
end
|
|
671
|
-
get
|
|
672
|
-
render :slim, 'div foo', :
|
|
674
|
+
get '/with_layout' do
|
|
675
|
+
render :slim, 'div foo', layout: true
|
|
673
676
|
end
|
|
674
677
|
end
|
|
675
678
|
get '/'
|
|
@@ -683,30 +686,30 @@ describe "Rendering" do
|
|
|
683
686
|
|
|
684
687
|
it 'should render correct erb when use sinatra as middleware' do
|
|
685
688
|
class Bar < Sinatra::Base
|
|
686
|
-
get
|
|
689
|
+
get '/' do
|
|
687
690
|
render :erb, "<&'>"
|
|
688
691
|
end
|
|
689
692
|
end
|
|
690
693
|
mock_app do
|
|
691
694
|
use Bar
|
|
692
695
|
end
|
|
693
|
-
get
|
|
696
|
+
get '/'
|
|
694
697
|
assert_equal "<&'>", body
|
|
695
698
|
end
|
|
696
699
|
end
|
|
697
700
|
|
|
698
701
|
describe 'standalone Sinatra usage of Rendering' do
|
|
699
702
|
before do
|
|
700
|
-
Sinatra::Request.class_eval{ alias_method :monkey_controller, :controller; undef :controller }
|
|
703
|
+
Sinatra::Request.class_eval { alias_method :monkey_controller, :controller; undef :controller }
|
|
701
704
|
end
|
|
702
705
|
after do
|
|
703
|
-
Sinatra::Request.class_eval{ alias_method :controller, :monkey_controller; undef :monkey_controller }
|
|
706
|
+
Sinatra::Request.class_eval { alias_method :controller, :monkey_controller; undef :monkey_controller }
|
|
704
707
|
end
|
|
705
708
|
it 'should work with Sinatra::Base' do
|
|
706
709
|
class Application < Sinatra::Base
|
|
707
710
|
register Padrino::Rendering
|
|
708
711
|
get '/' do
|
|
709
|
-
render :post, :
|
|
712
|
+
render :post, views: "#{__dir__}/fixtures/apps/views/blog"
|
|
710
713
|
end
|
|
711
714
|
end
|
|
712
715
|
@app = Application.new
|
|
@@ -719,7 +722,7 @@ describe "Rendering" do
|
|
|
719
722
|
it 'should locate controller templates' do
|
|
720
723
|
mock_app do
|
|
721
724
|
disable :reload_templates
|
|
722
|
-
set :views,
|
|
725
|
+
set :views, "#{__dir__}/fixtures/apps/views"
|
|
723
726
|
controller :test do
|
|
724
727
|
get :index do
|
|
725
728
|
render 'test/post'
|
|
@@ -732,7 +735,7 @@ describe "Rendering" do
|
|
|
732
735
|
it 'should properly cache template path' do
|
|
733
736
|
mock_app do
|
|
734
737
|
disable :reload_templates
|
|
735
|
-
set :views,
|
|
738
|
+
set :views, "#{__dir__}/fixtures/apps/views"
|
|
736
739
|
controller :blog do
|
|
737
740
|
get :index do
|
|
738
741
|
render :post
|
|
@@ -759,17 +762,17 @@ describe "Rendering" do
|
|
|
759
762
|
end
|
|
760
763
|
|
|
761
764
|
describe 'sinatra template helpers' do
|
|
762
|
-
it
|
|
765
|
+
it 'should respect default_content_type option defined by sinatra' do
|
|
763
766
|
mock_app do
|
|
764
|
-
get(:index){ builder
|
|
767
|
+
get(:index) { builder 'xml.foo' }
|
|
765
768
|
end
|
|
766
769
|
get '/'
|
|
767
|
-
assert_equal
|
|
770
|
+
assert_equal 'application/xml;charset=utf-8', response['Content-Type']
|
|
768
771
|
end
|
|
769
772
|
end
|
|
770
773
|
|
|
771
774
|
describe 'rendering with helpers that use render' do
|
|
772
|
-
%
|
|
775
|
+
%w[erb haml slim].each do |engine|
|
|
773
776
|
it "should work with #{engine}" do
|
|
774
777
|
@app = RenderDemo
|
|
775
778
|
get "/double_dive_#{engine}"
|