roda 3.24.0 → 3.25.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/CHANGELOG +6 -0
- data/doc/release_notes/3.25.0.txt +12 -0
- data/lib/roda.rb +5 -1
- data/lib/roda/plugins/precompile_templates.rb +1 -1
- data/lib/roda/plugins/render.rb +71 -11
- data/lib/roda/plugins/render_each.rb +16 -86
- data/lib/roda/plugins/sessions.rb +3 -3
- data/lib/roda/version.rb +1 -1
- data/spec/define_roda_method_spec.rb +20 -6
- data/spec/plugin/precompile_templates_spec.rb +6 -3
- data/spec/plugin/render_spec.rb +4 -0
- data/spec/spec_helper.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4e98660fac24a8bb7b455591674e9427e4fb07521384ae925888b95d7b38509c
|
|
4
|
+
data.tar.gz: 5ca8cec4fbff75633280c63375f9b33b5eeb26f7862d05356b5c3e85f0f1a29a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1e1ac389fcaad6a03b0ea9a5b89bf895c49421f971ce3a21eacaa7a24f93e061a1318debfd5cc30f2a41c146fdfbe53bd18785e6e2cc53fed938bde8dc078efa
|
|
7
|
+
data.tar.gz: fc26dccc7384e5619754d5f2ca4fddaf691aa57b301f1e2ea9b8de9a27224a49961ee0b162117363a7805a80860f4f3bb012d6d11ac8ca81f3b25f1505d888ef
|
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
= 3.25.0 (2019-10-15)
|
|
2
|
+
|
|
3
|
+
* Support change in tilt 2.0.10 private API to continue to support compiled templates, with up to 33% performance improvement (jeremyevans)
|
|
4
|
+
|
|
5
|
+
* Improve render performance with :locals option up to 75% by calling compiled template methods directly (jeremyevans)
|
|
6
|
+
|
|
1
7
|
= 3.24.0 (2019-09-13)
|
|
2
8
|
|
|
3
9
|
* Fix Proc.new warning in module_include plugin on Ruby 2.7+ (jeremyevans)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
= Improvements
|
|
2
|
+
|
|
3
|
+
* The new tilt 2.0.10 private API is now supported when using
|
|
4
|
+
compiled template methods, with up to a 33% performance increase.
|
|
5
|
+
The older tilt private API (back to tilt 1.2) is still supported.
|
|
6
|
+
|
|
7
|
+
* The performance of the render and view methods in the render plugin
|
|
8
|
+
when called with only the :locals option are now about 75% faster
|
|
9
|
+
by calling compiled template methods directly.
|
|
10
|
+
|
|
11
|
+
* Keyword argument separation issues are now handled on Ruby 2.7+
|
|
12
|
+
when defining methods with blocks that accept keyword arguments.
|
data/lib/roda.rb
CHANGED
|
@@ -213,7 +213,11 @@ class Roda
|
|
|
213
213
|
# Complexity of handling keyword arguments using define_method is too high,
|
|
214
214
|
# Fallback to instance_exec in this case.
|
|
215
215
|
b = block
|
|
216
|
-
|
|
216
|
+
if RUBY_VERSION >= '2.7'
|
|
217
|
+
block = eval('lambda{|*a, **kw| instance_exec(*a, **kw, &b)}', nil, __FILE__, __LINE__) # Keyword arguments fallback
|
|
218
|
+
else
|
|
219
|
+
block = lambda{|*a| instance_exec(*a, &b)} # Keyword arguments fallback
|
|
220
|
+
end
|
|
217
221
|
else
|
|
218
222
|
arity_meth = meth
|
|
219
223
|
meth = :"#{meth}_arity"
|
data/lib/roda/plugins/render.rb
CHANGED
|
@@ -122,7 +122,9 @@ class Roda
|
|
|
122
122
|
#
|
|
123
123
|
# The render/view method calls are optimized for usage with a single symbol/string
|
|
124
124
|
# argument specifying the template name. So for fastest rendering, pass only a
|
|
125
|
-
# symbol/string to render/view.
|
|
125
|
+
# symbol/string to render/view. Next best optimized are template calls with a
|
|
126
|
+
# single :locals option. Use of other options disables the compiled template
|
|
127
|
+
# method optimizations and can be significantly slower.
|
|
126
128
|
#
|
|
127
129
|
# If you must pass a hash to render/view, either as a second argument or as the
|
|
128
130
|
# only argument, you can speed things up by specifying a +:cache_key+ option in
|
|
@@ -131,10 +133,20 @@ class Roda
|
|
|
131
133
|
module Render
|
|
132
134
|
# Support for using compiled methods directly requires Ruby 2.3 for the
|
|
133
135
|
# method binding to work, and Tilt 1.2 for Tilt::Template#compiled_method.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
tilt_compiled_method_support = defined?(Tilt::VERSION) && Tilt::VERSION >= '1.2' &&
|
|
137
|
+
([1, -2].include?(((compiled_method_arity = Tilt::Template.instance_method(:compiled_method).arity) rescue false)))
|
|
138
|
+
NO_CACHE = {:cache=>false}.freeze
|
|
139
|
+
COMPILED_METHOD_SUPPORT = RUBY_VERSION >= '2.3' && tilt_compiled_method_support
|
|
140
|
+
|
|
141
|
+
if compiled_method_arity == -2
|
|
142
|
+
def self.tilt_template_compiled_method(template, locals_keys, scope_class)
|
|
143
|
+
template.send(:compiled_method, locals_keys, scope_class)
|
|
144
|
+
end
|
|
145
|
+
else
|
|
146
|
+
def self.tilt_template_compiled_method(template, locals_keys, scope_class)
|
|
147
|
+
template.send(:compiled_method, locals_keys)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
138
150
|
|
|
139
151
|
# Setup default rendering options. See Render for details.
|
|
140
152
|
def self.configure(app, opts=OPTS)
|
|
@@ -268,7 +280,7 @@ class Roda
|
|
|
268
280
|
mod = roda_class::RodaCompiledTemplates
|
|
269
281
|
internal_method_name = :"_#{method_name}"
|
|
270
282
|
begin
|
|
271
|
-
mod.send(:define_method, internal_method_name, send(:compiled_method, locals_keys))
|
|
283
|
+
mod.send(:define_method, internal_method_name, send(:compiled_method, locals_keys, roda_class))
|
|
272
284
|
rescue ::NotImplementedError
|
|
273
285
|
return false
|
|
274
286
|
end
|
|
@@ -283,8 +295,8 @@ class Roda
|
|
|
283
295
|
private
|
|
284
296
|
|
|
285
297
|
# Return the compiled method for the current template object.
|
|
286
|
-
def compiled_method(locals_keys=EMPTY_ARRAY)
|
|
287
|
-
@template
|
|
298
|
+
def compiled_method(locals_keys=EMPTY_ARRAY, roda_class=nil)
|
|
299
|
+
Render.tilt_template_compiled_method(@template, locals_keys, roda_class)
|
|
288
300
|
end
|
|
289
301
|
|
|
290
302
|
# Return the lambda used to define the compiled template method. This
|
|
@@ -294,7 +306,7 @@ class Roda
|
|
|
294
306
|
mod = roda_class::RodaCompiledTemplates
|
|
295
307
|
lambda do |locals, &block|
|
|
296
308
|
if template.modified?
|
|
297
|
-
mod.send(:define_method, method_name,
|
|
309
|
+
mod.send(:define_method, method_name, Render.tilt_template_compiled_method(template, locals_keys, roda_class))
|
|
298
310
|
mod.send(:private, method_name)
|
|
299
311
|
end
|
|
300
312
|
|
|
@@ -326,9 +338,11 @@ class Roda
|
|
|
326
338
|
|
|
327
339
|
module InstanceMethods
|
|
328
340
|
# Render the given template. See Render for details.
|
|
329
|
-
def render(template, opts = (optimized_template = _cached_template_method(template); OPTS), &block)
|
|
341
|
+
def render(template, opts = (no_opts = true; optimized_template = _cached_template_method(template); OPTS), &block)
|
|
330
342
|
if optimized_template
|
|
331
343
|
send(optimized_template, OPTS, &block)
|
|
344
|
+
elsif !no_opts && opts.length == 1 && (locals = opts[:locals]) && (optimized_template = _optimized_render_method_for_locals(template, locals))
|
|
345
|
+
send(optimized_template, locals, &block)
|
|
332
346
|
else
|
|
333
347
|
opts = render_template_opts(template, opts)
|
|
334
348
|
retrieve_template(opts).render((opts[:scope]||self), (opts[:locals]||OPTS), &block)
|
|
@@ -395,6 +409,48 @@ class Roda
|
|
|
395
409
|
def _cached_template_method_lookup(method_cache, template)
|
|
396
410
|
method_cache[template]
|
|
397
411
|
end
|
|
412
|
+
|
|
413
|
+
# Use an optimized render path for templates with a hash of locals. Returns the result
|
|
414
|
+
# of the template render if the optimized path is used, or nil if the optimized
|
|
415
|
+
# path is not used and the long method needs to be used.
|
|
416
|
+
def _optimized_render_method_for_locals(template, locals)
|
|
417
|
+
return unless method_cache = render_opts[:template_method_cache]
|
|
418
|
+
|
|
419
|
+
locals_keys = locals.keys.sort
|
|
420
|
+
key = [:_render_locals, template, locals_keys]
|
|
421
|
+
|
|
422
|
+
optimized_template = case template
|
|
423
|
+
when String, Symbol
|
|
424
|
+
_cached_template_method_lookup(method_cache, key)
|
|
425
|
+
else
|
|
426
|
+
return
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
case optimized_template
|
|
430
|
+
when Symbol
|
|
431
|
+
optimized_template
|
|
432
|
+
else
|
|
433
|
+
if method_cache_key = _cached_template_method_key(key)
|
|
434
|
+
template_obj = retrieve_template(render_template_opts(template, NO_CACHE))
|
|
435
|
+
method_name = :"_roda_template_locals_#{self.class.object_id}_#{method_cache_key}"
|
|
436
|
+
|
|
437
|
+
method_cache[method_cache_key] = case template_obj
|
|
438
|
+
when Render::TemplateMtimeWrapper
|
|
439
|
+
template_obj.define_compiled_method(self.class, method_name, locals_keys)
|
|
440
|
+
else
|
|
441
|
+
begin
|
|
442
|
+
unbound_method = Render.tilt_template_compiled_method(template_obj, locals_keys, self.class)
|
|
443
|
+
rescue ::NotImplementedError
|
|
444
|
+
false
|
|
445
|
+
else
|
|
446
|
+
self.class::RodaCompiledTemplates.send(:define_method, method_name, unbound_method)
|
|
447
|
+
self.class::RodaCompiledTemplates.send(:private, method_name)
|
|
448
|
+
method_name
|
|
449
|
+
end
|
|
450
|
+
end
|
|
451
|
+
end
|
|
452
|
+
end
|
|
453
|
+
end
|
|
398
454
|
else
|
|
399
455
|
# :nocov:
|
|
400
456
|
def _cached_template_method(template)
|
|
@@ -404,6 +460,10 @@ class Roda
|
|
|
404
460
|
def _cached_template_method_key(template)
|
|
405
461
|
nil
|
|
406
462
|
end
|
|
463
|
+
|
|
464
|
+
def _optimized_render_method_for_locals(_, _)
|
|
465
|
+
nil
|
|
466
|
+
end
|
|
407
467
|
# :nocov:
|
|
408
468
|
end
|
|
409
469
|
|
|
@@ -525,7 +585,7 @@ class Roda
|
|
|
525
585
|
|
|
526
586
|
if define_compiled_method && cache != false
|
|
527
587
|
begin
|
|
528
|
-
unbound_method =
|
|
588
|
+
unbound_method = Render.tilt_template_compiled_method(template, EMPTY_ARRAY, self.class)
|
|
529
589
|
rescue ::NotImplementedError
|
|
530
590
|
method_cache[method_cache_key] = false
|
|
531
591
|
else
|
|
@@ -34,8 +34,6 @@ class Roda
|
|
|
34
34
|
app.plugin :render
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
COMPILED_METHOD_SUPPORT = Render::COMPILED_METHOD_SUPPORT
|
|
38
|
-
NO_CACHE = {:cache=>false}.freeze
|
|
39
37
|
ALLOWED_KEYS = [:locals, :local].freeze
|
|
40
38
|
|
|
41
39
|
module InstanceMethods
|
|
@@ -47,40 +45,13 @@ class Roda
|
|
|
47
45
|
# set a local variable. If not set, uses the template name.
|
|
48
46
|
def render_each(enum, template, opts=(no_opts = true; optimized_template = _cached_render_each_template_method(template); OPTS))
|
|
49
47
|
if optimized_template
|
|
50
|
-
|
|
51
|
-
return enum.map{|v| send(optimized_template, as=>v)}.join
|
|
48
|
+
return _optimized_render_each(enum, optimized_template, template.to_s.to_sym, {})
|
|
52
49
|
elsif opts.has_key?(:local)
|
|
53
50
|
as = opts[:local]
|
|
54
51
|
else
|
|
55
52
|
as = template.to_s.to_sym
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
no_opts &&
|
|
59
|
-
optimized_template.nil? &&
|
|
60
|
-
(method_cache = render_opts[:template_method_cache]) &&
|
|
61
|
-
(method_cache_key = _cached_template_method_key([:_render_each, template]))
|
|
62
|
-
|
|
63
|
-
template_obj = retrieve_template(render_template_opts(template, NO_CACHE))
|
|
64
|
-
method_name = :"_roda_render_each_#{self.class.object_id}_#{method_cache_key}"
|
|
65
|
-
|
|
66
|
-
case template_obj
|
|
67
|
-
when Render::TemplateMtimeWrapper
|
|
68
|
-
optimized_template = method_cache[method_cache_key] = template_obj.define_compiled_method(self.class, method_name, [as])
|
|
69
|
-
else
|
|
70
|
-
begin
|
|
71
|
-
unbound_method = template_obj.send(:compiled_method, [as])
|
|
72
|
-
rescue ::NotImplementedError
|
|
73
|
-
method_cache[method_cache_key] = false
|
|
74
|
-
else
|
|
75
|
-
self.class::RodaCompiledTemplates.send(:define_method, method_name, unbound_method)
|
|
76
|
-
self.class::RodaCompiledTemplates.send(:private, method_name)
|
|
77
|
-
optimized_template = method_cache[method_cache_key] = method_name
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
if optimized_template
|
|
82
|
-
return enum.map{|v| send(optimized_template, as=>v)}.join
|
|
83
|
-
end
|
|
53
|
+
if no_opts && optimized_template.nil? && (optimized_template = _optimized_render_method_for_locals(template, (locals = {as=>nil})))
|
|
54
|
+
return _optimized_render_each(enum, optimized_template, as, locals)
|
|
84
55
|
end
|
|
85
56
|
end
|
|
86
57
|
|
|
@@ -91,59 +62,10 @@ class Roda
|
|
|
91
62
|
else
|
|
92
63
|
locals = opts[:locals] = {}
|
|
93
64
|
end
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if COMPILED_METHOD_SUPPORT &&
|
|
97
|
-
!no_opts &&
|
|
98
|
-
as &&
|
|
99
|
-
(opts.keys - ALLOWED_KEYS).empty? &&
|
|
100
|
-
(method_cache = render_opts[:template_method_cache])
|
|
65
|
+
locals[as] = nil
|
|
101
66
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
optimized_template = case template
|
|
106
|
-
when String, Symbol
|
|
107
|
-
_cached_template_method_lookup(method_cache, key)
|
|
108
|
-
else
|
|
109
|
-
false
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
case optimized_template
|
|
113
|
-
when Symbol
|
|
114
|
-
return enum.map do |v|
|
|
115
|
-
locals[as] = v
|
|
116
|
-
send(optimized_template, locals)
|
|
117
|
-
end.join
|
|
118
|
-
when false
|
|
119
|
-
# nothing
|
|
120
|
-
else
|
|
121
|
-
if method_cache_key = _cached_template_method_key(key)
|
|
122
|
-
template_obj = retrieve_template(render_template_opts(template, NO_CACHE))
|
|
123
|
-
method_name = :"_roda_render_each_#{self.class.object_id}_#{method_cache_key}"
|
|
124
|
-
|
|
125
|
-
case template_obj
|
|
126
|
-
when Render::TemplateMtimeWrapper
|
|
127
|
-
optimized_template = method_cache[method_cache_key] = template_obj.define_compiled_method(self.class, method_name, locals_keys)
|
|
128
|
-
else
|
|
129
|
-
begin
|
|
130
|
-
unbound_method = template_obj.send(:compiled_method, locals_keys)
|
|
131
|
-
rescue ::NotImplementedError
|
|
132
|
-
method_cache[method_cache_key] = false
|
|
133
|
-
else
|
|
134
|
-
self.class::RodaCompiledTemplates.send(:define_method, method_name, unbound_method)
|
|
135
|
-
self.class::RodaCompiledTemplates.send(:private, method_name)
|
|
136
|
-
optimized_template = method_cache[method_cache_key] = method_name
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
if optimized_template
|
|
141
|
-
return enum.map do |v|
|
|
142
|
-
locals[as] = v
|
|
143
|
-
send(optimized_template, locals)
|
|
144
|
-
end.join
|
|
145
|
-
end
|
|
146
|
-
end
|
|
67
|
+
if (opts.keys - ALLOWED_KEYS).empty? && (optimized_template = _optimized_render_method_for_locals(template, locals))
|
|
68
|
+
return _optimized_render_each(enum, optimized_template, as, locals)
|
|
147
69
|
end
|
|
148
70
|
end
|
|
149
71
|
|
|
@@ -155,7 +77,7 @@ class Roda
|
|
|
155
77
|
|
|
156
78
|
private
|
|
157
79
|
|
|
158
|
-
if COMPILED_METHOD_SUPPORT
|
|
80
|
+
if Render::COMPILED_METHOD_SUPPORT
|
|
159
81
|
# If compiled method support is enabled in the render plugin, return the
|
|
160
82
|
# method name to call to render the template. Return false if not given
|
|
161
83
|
# a string or symbol, or if compiled method support for this template has
|
|
@@ -164,12 +86,20 @@ class Roda
|
|
|
164
86
|
case template
|
|
165
87
|
when String, Symbol
|
|
166
88
|
if (method_cache = render_opts[:template_method_cache])
|
|
167
|
-
_cached_template_method_lookup(method_cache, [:
|
|
89
|
+
_cached_template_method_lookup(method_cache, [:_render_locals, template, [template.to_sym]])
|
|
168
90
|
end
|
|
169
91
|
else
|
|
170
92
|
false
|
|
171
93
|
end
|
|
172
94
|
end
|
|
95
|
+
|
|
96
|
+
# Use an optimized render for each value in the enum.
|
|
97
|
+
def _optimized_render_each(enum, optimized_template, as, locals)
|
|
98
|
+
enum.map do |v|
|
|
99
|
+
locals[as] = v
|
|
100
|
+
send(optimized_template, locals)
|
|
101
|
+
end.join
|
|
102
|
+
end
|
|
173
103
|
else
|
|
174
104
|
# :nocov:
|
|
175
105
|
def _cached_render_each_template_method(template)
|
|
@@ -71,9 +71,9 @@ class Roda
|
|
|
71
71
|
# :max_seconds :: The maximum number of seconds to allow for total session lifetime, starting with when
|
|
72
72
|
# the session was originally created. Default is <tt>86400*30</tt> (30 days). Can be set to
|
|
73
73
|
# +nil+ to disable session lifetime checks.
|
|
74
|
-
# :
|
|
75
|
-
#
|
|
76
|
-
#
|
|
74
|
+
# :max_idle_seconds :: The maximum number of seconds to allow since the session was last updated.
|
|
75
|
+
# Default is <tt>86400*7</tt> (7 days). Can be set to nil to disable session idleness
|
|
76
|
+
# checks.
|
|
77
77
|
# :old_secret :: The previous secret to use, allowing for secret rotation. Must be a string of at least 64
|
|
78
78
|
# bytes if given.
|
|
79
79
|
# :pad_size :: Pad session data (after possible compression, before encryption), to a multiple of this
|
data/lib/roda/version.rb
CHANGED
|
@@ -206,6 +206,20 @@ describe "Roda.define_roda_method" do
|
|
|
206
206
|
end
|
|
207
207
|
|
|
208
208
|
it "should handle expected_arity :any with keyword arguments" do
|
|
209
|
+
if RUBY_VERSION >= '2.7' && RUBY_VERSION < '3'
|
|
210
|
+
suppress = proc do |&b|
|
|
211
|
+
begin
|
|
212
|
+
stderr = $stderr
|
|
213
|
+
$stderr = StringIO.new
|
|
214
|
+
b.call
|
|
215
|
+
ensure
|
|
216
|
+
$stderr = stderr
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
else
|
|
220
|
+
suppress = proc{|&b| b.call}
|
|
221
|
+
end
|
|
222
|
+
|
|
209
223
|
m = eval('app.define_roda_method("x", :any){|b:2| b}', binding)
|
|
210
224
|
@scope.send(m).must_equal 2
|
|
211
225
|
@scope.send(m, 4).must_equal 2
|
|
@@ -225,26 +239,26 @@ describe "Roda.define_roda_method" do
|
|
|
225
239
|
@scope.send(m, 4, b: 3).must_equal(b: 3)
|
|
226
240
|
|
|
227
241
|
m = eval('app.define_roda_method("x", :any){|x, b:9| [x, b, 1]}', binding)
|
|
228
|
-
@scope.send(m).must_equal [
|
|
242
|
+
suppress.call{@scope.send(m)[1..-1]}.must_equal [9, 1]
|
|
229
243
|
@scope.send(m, 2).must_equal [2, 9, 1]
|
|
230
244
|
@scope.send(m, 2, 3).must_equal [2, 9, 1]
|
|
231
|
-
@scope.send(m, b: 4).must_equal [{b: 4}, 9, 1]
|
|
245
|
+
eval("@scope.send(m, {b: 4}#{', **{}' if RUBY_VERSION > '2'})").must_equal [{b: 4}, 9, 1]
|
|
232
246
|
@scope.send(m, 2, b: 4).must_equal [2, 4, 1]
|
|
233
247
|
@scope.send(m, 2, 3, b: 4).must_equal [2, 4, 1]
|
|
234
248
|
|
|
235
249
|
m = eval('app.define_roda_method("x", :any){|x, b:| [x, b, 1]}', binding)
|
|
236
|
-
proc{@scope.send(m)}.must_raise ArgumentError
|
|
250
|
+
proc{suppress.call{@scope.send(m)}}.must_raise ArgumentError
|
|
237
251
|
proc{@scope.send(m, 2)}.must_raise ArgumentError
|
|
238
252
|
proc{@scope.send(m, 2, 3)}.must_raise ArgumentError
|
|
239
|
-
proc{@scope.send(m, b: 4)}.must_raise ArgumentError
|
|
253
|
+
proc{eval("@scope.send(m, {b: 4}#{', **{}' if RUBY_VERSION > '2'})")}.must_raise ArgumentError
|
|
240
254
|
@scope.send(m, 2, b: 4).must_equal [2, 4, 1]
|
|
241
255
|
@scope.send(m, 2, 3, b: 4).must_equal [2, 4, 1]
|
|
242
256
|
|
|
243
257
|
m = eval('app.define_roda_method("x", :any){|x, **b| [x, b, 1]}', binding)
|
|
244
|
-
@scope.send(m).must_equal [
|
|
258
|
+
suppress.call{@scope.send(m)[1..-1]}.must_equal [{}, 1]
|
|
245
259
|
@scope.send(m, 2).must_equal [2, {}, 1]
|
|
246
260
|
@scope.send(m, 2, 3).must_equal [2, {}, 1]
|
|
247
|
-
@scope.send(m, b: 4).must_equal [{b: 4}, {}, 1]
|
|
261
|
+
eval("@scope.send(m, {b: 4}#{', **{}' if RUBY_VERSION > '2'})").must_equal [{b: 4}, {}, 1]
|
|
248
262
|
@scope.send(m, 2, b: 4).must_equal [2, {b: 4}, 1]
|
|
249
263
|
@scope.send(m, 2, 3, b: 4).must_equal [2, {b: 4}, 1]
|
|
250
264
|
|
|
@@ -19,8 +19,9 @@ describe "precompile_templates plugin" do
|
|
|
19
19
|
app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].must_be_nil
|
|
20
20
|
app.precompile_templates 'spec/views/iv.erb'
|
|
21
21
|
app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].wont_equal nil
|
|
22
|
-
app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].instance_variable_get(:@compiled_method)
|
|
22
|
+
app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].instance_variable_get(:@compiled_method).length.must_equal 1
|
|
23
23
|
body.strip.must_equal '1'
|
|
24
|
+
app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].instance_variable_get(:@compiled_method).length.must_equal 1
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
it "adds support for template precompilation with :locals" do
|
|
@@ -35,8 +36,9 @@ describe "precompile_templates plugin" do
|
|
|
35
36
|
app.render_opts[:cache][File.expand_path('spec/views/about.erb')].must_be_nil
|
|
36
37
|
app.precompile_templates 'spec/views/about.erb', :locals=>[:title]
|
|
37
38
|
app.render_opts[:cache][File.expand_path('spec/views/about.erb')].wont_equal nil
|
|
38
|
-
app.render_opts[:cache][File.expand_path('spec/views/about.erb')].instance_variable_get(:@compiled_method)
|
|
39
|
+
app.render_opts[:cache][File.expand_path('spec/views/about.erb')].instance_variable_get(:@compiled_method).length.must_equal 1
|
|
39
40
|
body.strip.must_equal '<h1>1</h1>'
|
|
41
|
+
app.render_opts[:cache][File.expand_path('spec/views/about.erb')].instance_variable_get(:@compiled_method).length.must_equal 1
|
|
40
42
|
end
|
|
41
43
|
|
|
42
44
|
it "adds support for template precompilation with :inline" do
|
|
@@ -51,8 +53,9 @@ describe "precompile_templates plugin" do
|
|
|
51
53
|
app.render_opts[:cache]['a'].must_be_nil
|
|
52
54
|
app.precompile_templates :inline=>'a', :cache_key=>'a'
|
|
53
55
|
app.render_opts[:cache]['a'].wont_equal nil
|
|
54
|
-
app.render_opts[:cache]['a'].instance_variable_get(:@compiled_method)
|
|
56
|
+
app.render_opts[:cache]['a'].instance_variable_get(:@compiled_method).length.must_equal 1
|
|
55
57
|
body.strip.must_equal "a"
|
|
58
|
+
app.render_opts[:cache]['a'].instance_variable_get(:@compiled_method).length.must_equal 1
|
|
56
59
|
end
|
|
57
60
|
end
|
|
58
61
|
end
|
data/spec/plugin/render_spec.rb
CHANGED
|
@@ -763,22 +763,26 @@ describe "render plugin" do
|
|
|
763
763
|
req("/a")
|
|
764
764
|
req("/c")
|
|
765
765
|
|
|
766
|
+
@app = Class.new(app)
|
|
766
767
|
app.plugin :render, :allowed_paths=>[]
|
|
767
768
|
proc{req}.must_raise Roda::RodaError
|
|
768
769
|
proc{req("/a")}.must_raise Roda::RodaError
|
|
769
770
|
proc{req("/c")}.must_raise Roda::RodaError
|
|
770
771
|
|
|
772
|
+
@app = Class.new(app)
|
|
771
773
|
app.plugin :render, :allowed_paths=>['spec/views/about']
|
|
772
774
|
proc{req}.must_raise Roda::RodaError
|
|
773
775
|
proc{req("/a")}.must_raise Roda::RodaError
|
|
774
776
|
req("/c")
|
|
775
777
|
|
|
778
|
+
@app = Class.new(app)
|
|
776
779
|
app.plugin :render, :allowed_paths=>%w'spec/views/about spec/views/b'
|
|
777
780
|
body.strip.must_equal "b"
|
|
778
781
|
proc{req("/a")}.must_raise Roda::RodaError
|
|
779
782
|
req("/c")
|
|
780
783
|
|
|
781
784
|
render_opts[:check_paths] = true
|
|
785
|
+
@app = Class.new(app)
|
|
782
786
|
app.plugin :render, :check_paths=>false
|
|
783
787
|
body.strip.must_equal "b"
|
|
784
788
|
proc{req("/a")}.must_raise Roda::RodaError
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: roda
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.25.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeremy Evans
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-10-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rack
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: 5.7.0
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: minitest-global_expectations
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
55
69
|
- !ruby/object:Gem::Dependency
|
|
56
70
|
name: tilt
|
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -221,6 +235,7 @@ extra_rdoc_files:
|
|
|
221
235
|
- doc/release_notes/3.22.0.txt
|
|
222
236
|
- doc/release_notes/3.23.0.txt
|
|
223
237
|
- doc/release_notes/3.24.0.txt
|
|
238
|
+
- doc/release_notes/3.25.0.txt
|
|
224
239
|
files:
|
|
225
240
|
- CHANGELOG
|
|
226
241
|
- MIT-LICENSE
|
|
@@ -281,6 +296,7 @@ files:
|
|
|
281
296
|
- doc/release_notes/3.22.0.txt
|
|
282
297
|
- doc/release_notes/3.23.0.txt
|
|
283
298
|
- doc/release_notes/3.24.0.txt
|
|
299
|
+
- doc/release_notes/3.25.0.txt
|
|
284
300
|
- doc/release_notes/3.3.0.txt
|
|
285
301
|
- doc/release_notes/3.4.0.txt
|
|
286
302
|
- doc/release_notes/3.5.0.txt
|