roda 2.10.0 → 2.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +8 -0
- data/README.rdoc +5 -0
- data/doc/release_notes/2.11.0.txt +70 -0
- data/lib/roda/plugins/all_verbs.rb +1 -0
- data/lib/roda/plugins/assets.rb +2 -1
- data/lib/roda/plugins/backtracking_array.rb +1 -0
- data/lib/roda/plugins/caching.rb +1 -0
- data/lib/roda/plugins/chunked.rb +1 -0
- data/lib/roda/plugins/class_level_routing.rb +1 -0
- data/lib/roda/plugins/content_for.rb +1 -0
- data/lib/roda/plugins/cookies.rb +1 -0
- data/lib/roda/plugins/default_headers.rb +1 -0
- data/lib/roda/plugins/default_status.rb +1 -0
- data/lib/roda/plugins/delay_build.rb +1 -0
- data/lib/roda/plugins/delegate.rb +1 -0
- data/lib/roda/plugins/delete_empty_headers.rb +1 -0
- data/lib/roda/plugins/drop_body.rb +1 -0
- data/lib/roda/plugins/empty_root.rb +1 -0
- data/lib/roda/plugins/environments.rb +1 -0
- data/lib/roda/plugins/error_handler.rb +1 -0
- data/lib/roda/plugins/h.rb +1 -0
- data/lib/roda/plugins/halt.rb +1 -0
- data/lib/roda/plugins/hash_matcher.rb +1 -0
- data/lib/roda/plugins/head.rb +1 -0
- data/lib/roda/plugins/header_matchers.rb +1 -0
- data/lib/roda/plugins/heartbeat.rb +1 -0
- data/lib/roda/plugins/hooks.rb +1 -0
- data/lib/roda/plugins/indifferent_params.rb +1 -0
- data/lib/roda/plugins/match_affix.rb +1 -0
- data/lib/roda/plugins/middleware.rb +1 -0
- data/lib/roda/plugins/module_include.rb +1 -0
- data/lib/roda/plugins/multi_route.rb +1 -0
- data/lib/roda/plugins/multi_run.rb +1 -0
- data/lib/roda/plugins/multi_view.rb +1 -0
- data/lib/roda/plugins/named_templates.rb +1 -0
- data/lib/roda/plugins/not_allowed.rb +1 -0
- data/lib/roda/plugins/not_found.rb +1 -0
- data/lib/roda/plugins/padrino_render.rb +1 -0
- data/lib/roda/plugins/param_matchers.rb +1 -0
- data/lib/roda/plugins/params_capturing.rb +132 -0
- data/lib/roda/plugins/partials.rb +1 -0
- data/lib/roda/plugins/pass.rb +1 -0
- data/lib/roda/plugins/path.rb +1 -0
- data/lib/roda/plugins/path_matchers.rb +1 -0
- data/lib/roda/plugins/path_rewriter.rb +1 -0
- data/lib/roda/plugins/per_thread_caching.rb +1 -0
- data/lib/roda/plugins/precompile_templates.rb +1 -0
- data/lib/roda/plugins/render.rb +3 -1
- data/lib/roda/plugins/render_each.rb +1 -0
- data/lib/roda/plugins/response_request.rb +1 -0
- data/lib/roda/plugins/run_handler.rb +1 -0
- data/lib/roda/plugins/shared_vars.rb +1 -0
- data/lib/roda/plugins/sinatra_helpers.rb +1 -0
- data/lib/roda/plugins/slash_path_empty.rb +1 -0
- data/lib/roda/plugins/static.rb +1 -0
- data/lib/roda/plugins/status_handler.rb +1 -0
- data/lib/roda/plugins/streaming.rb +1 -0
- data/lib/roda/plugins/symbol_matchers.rb +1 -0
- data/lib/roda/plugins/symbol_views.rb +1 -0
- data/lib/roda/plugins/view_options.rb +1 -0
- data/lib/roda/version.rb +1 -1
- data/spec/plugin/params_capturing_spec.rb +38 -0
- data/spec/plugin/render_spec.rb +12 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8838cf12ea385cc60fd7a700596ea8e5b7d6f048
|
4
|
+
data.tar.gz: 17e8862408a8cfec0f55a4ff6bc845bef02df74b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dc1d418979beb8c3410d4eb15c4e5c8355c501dc39ec091c80409f6c30e1a4e3d5dfbf41263965a11174915753ed66c9385a55549d6a97603e96f1eb46ae41a
|
7
|
+
data.tar.gz: fdf05f0931a18f622c0c75e0bc596cb7421a584b0e67ac9d381bdb5932f78658ee3caf38d5ca7eba827893e21dcc2efd935b12b4c1ce9504082bf6927c1f0979
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
= 2.11.0 (2016-02-16)
|
2
|
+
|
3
|
+
* Support :scope option in render plugin, for specifying object in which to evaluate the template (jeremyevans)
|
4
|
+
|
5
|
+
* Make minjs compressor support in assets plugin support latest version of Minjs (jeremyevans)
|
6
|
+
|
7
|
+
* Add params_capturing plugin, for storing matcher captures in the request params (jeremyevans)
|
8
|
+
|
1
9
|
= 2.10.0 (2016-01-15)
|
2
10
|
|
3
11
|
* Do not override existing Content-Type header in json plugin (jeremyevans)
|
data/README.rdoc
CHANGED
@@ -744,6 +744,11 @@ to escape by default, so that in your templates:
|
|
744
744
|
<%= '<>' %> # outputs <>
|
745
745
|
<%== '<>' %> # outputs <>
|
746
746
|
|
747
|
+
When using the +:escape_option, you will need to ensure that your layouts
|
748
|
+
are not escaping the output of the content template:
|
749
|
+
|
750
|
+
<%== yield %> # not <%= yield %>
|
751
|
+
|
747
752
|
You can also provide a +:escape_safe_classes+ option, which will
|
748
753
|
make <tt><%= %></tt> not escape certain string subclasses, useful
|
749
754
|
if you have helpers that already return escaped output using a
|
@@ -0,0 +1,70 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* A params_capturing plugin has been added, which makes string and
|
4
|
+
symbol matchers update the request params with the value of the
|
5
|
+
captured segments, using the matcher as the key:
|
6
|
+
|
7
|
+
plugin :params_capturing
|
8
|
+
|
9
|
+
route do |r|
|
10
|
+
# GET /foo/123/abc/67
|
11
|
+
r.on("foo/:bar/:baz", :quux) do
|
12
|
+
r[:bar] #=> '123'
|
13
|
+
r[:baz] #=> 'abc'
|
14
|
+
r[:quux] #=> '67'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Note that this updating of the request params using the matcher as
|
19
|
+
the key is only done if all arguments to the matcher are symbols
|
20
|
+
or strings.
|
21
|
+
|
22
|
+
All matchers will update the request params by adding all
|
23
|
+
captured segments to the captures key, including
|
24
|
+
symbol and string matchers:
|
25
|
+
|
26
|
+
r.on(:x, /(\d+)\/(\w+)/, ':y') do
|
27
|
+
r[:x] #=> nil
|
28
|
+
r[:y] #=> nil
|
29
|
+
r[:captures] #=> ["foo", "123", "abc", "67"]
|
30
|
+
end
|
31
|
+
|
32
|
+
Note that the request params captures entry will be appended to with
|
33
|
+
each nested match:
|
34
|
+
|
35
|
+
r.on(:w) do
|
36
|
+
r.on(:x) do
|
37
|
+
r.on(:y) do
|
38
|
+
r.on(:z) do
|
39
|
+
r[:captures] # => ["foo", "123", "abc", "67"]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Note that any existing params captures entry will be overwritten
|
46
|
+
by this plugin. You can use r.GET or r.POST to get the underlying
|
47
|
+
entry, depending on how it was submitted.
|
48
|
+
|
49
|
+
Also note that the param keys are actually stored in r.params as
|
50
|
+
strings and not symbols (r[] converts the argument to a string
|
51
|
+
before looking it up in r.params).
|
52
|
+
|
53
|
+
Also note that this plugin will not work correctly if you are using
|
54
|
+
the symbol_matchers plugin with custom symbol matching and are using
|
55
|
+
symbols that capture multiple values or no values.
|
56
|
+
|
57
|
+
* A :scope option is now supported by render/view in the render plugin,
|
58
|
+
which allows you to specify the object in which context to evaluate
|
59
|
+
the template.
|
60
|
+
|
61
|
+
= Other Improvements
|
62
|
+
|
63
|
+
* The assets plugin's support for the Minjs javascript minifier now
|
64
|
+
supports the latest version (0.4.1).
|
65
|
+
|
66
|
+
= Backwards Compatibility
|
67
|
+
|
68
|
+
* Support for Minjs <0.4.0 has been dropped from the assets plugin.
|
69
|
+
Please upgrade Minjs at the same time you upgrade Roda if you are
|
70
|
+
using both of them.
|
data/lib/roda/plugins/assets.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen-string-literal: true
|
2
2
|
|
3
|
+
#
|
3
4
|
class Roda
|
4
5
|
module RodaPlugins
|
5
6
|
# The assets plugin adds support for rendering your CSS and javascript
|
@@ -511,7 +512,7 @@ class Roda
|
|
511
512
|
# Compress the JS using MinJS, a pure ruby compressor
|
512
513
|
def compress_js_minjs(content)
|
513
514
|
require 'minjs'
|
514
|
-
|
515
|
+
Minjs::Compressor::Compressor.new(:debug => false).compress(content).to_js
|
515
516
|
end
|
516
517
|
|
517
518
|
# Compress the JS using Uglifier, requires javascript runtime
|
data/lib/roda/plugins/caching.rb
CHANGED
data/lib/roda/plugins/chunked.rb
CHANGED
data/lib/roda/plugins/cookies.rb
CHANGED
data/lib/roda/plugins/h.rb
CHANGED
data/lib/roda/plugins/halt.rb
CHANGED
data/lib/roda/plugins/head.rb
CHANGED
data/lib/roda/plugins/hooks.rb
CHANGED
@@ -0,0 +1,132 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
class Roda
|
5
|
+
module RodaPlugins
|
6
|
+
# The params_capturing plugin makes string and symbol matchers
|
7
|
+
# update the request params with the value of the captured segments,
|
8
|
+
# using the matcher as the key:
|
9
|
+
#
|
10
|
+
# plugin :params_capturing
|
11
|
+
#
|
12
|
+
# route do |r|
|
13
|
+
# # GET /foo/123/abc/67
|
14
|
+
# r.on("foo/:bar/:baz", :quux) do
|
15
|
+
# r[:bar] #=> '123'
|
16
|
+
# r[:baz] #=> 'abc'
|
17
|
+
# r[:quux] #=> '67'
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# Note that this updating of the request params using the matcher as
|
22
|
+
# the key is only done if all arguments to the matcher are symbols
|
23
|
+
# or strings.
|
24
|
+
#
|
25
|
+
# All matchers will update the request params by adding all
|
26
|
+
# captured segments to the +captures+ key, including
|
27
|
+
# symbol and string matchers:
|
28
|
+
#
|
29
|
+
# r.on(:x, /(\d+)\/(\w+)/, ':y') do
|
30
|
+
# r[:x] #=> nil
|
31
|
+
# r[:y] #=> nil
|
32
|
+
# r[:captures] #=> ["foo", "123", "abc", "67"]
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# Note that the request params +captures+ entry will be appended to with
|
36
|
+
# each nested match:
|
37
|
+
#
|
38
|
+
# r.on(:w) do
|
39
|
+
# r.on(:x) do
|
40
|
+
# r.on(:y) do
|
41
|
+
# r.on(:z) do
|
42
|
+
# r[:captures] # => ["foo", "123", "abc", "67"]
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# Note that any existing params captures entry will be overwritten
|
49
|
+
# by this plugin. You can use +r.GET+ or +r.POST+ to get the underlying
|
50
|
+
# entry, depending on how it was submitted.
|
51
|
+
#
|
52
|
+
# Also note that the param keys are actually stored in +r.params+ as
|
53
|
+
# strings and not symbols (<tt>r[]</tt> converts the argument
|
54
|
+
# to a string before looking it up in +r.params+).
|
55
|
+
#
|
56
|
+
# Also note that this plugin will not work correctly if you are using
|
57
|
+
# the symbol_matchers plugin with custom symbol matching and are using
|
58
|
+
# symbols that capture multiple values or no values.
|
59
|
+
module ParamsCapturing
|
60
|
+
module RequestMethods
|
61
|
+
def initialize(*)
|
62
|
+
super
|
63
|
+
params['captures'] = []
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
if RUBY_VERSION >= '1.9'
|
69
|
+
# Regexp to scan for capture names. Uses positive lookbehind
|
70
|
+
# so it is only valid on ruby 1.9+, hence the use of eval.
|
71
|
+
STRING_PARAM_CAPTURE_REGEXP = eval("/(?<=:)\\w+/")
|
72
|
+
|
73
|
+
# Add the capture names from this string to list of param
|
74
|
+
# capture names if param capturing.
|
75
|
+
def _match_string(str)
|
76
|
+
if pc = @_params_captures
|
77
|
+
pc.concat(str.scan(STRING_PARAM_CAPTURE_REGEXP))
|
78
|
+
end
|
79
|
+
super
|
80
|
+
end
|
81
|
+
else
|
82
|
+
# :nocov:
|
83
|
+
|
84
|
+
# Ruby 1.8 doesn't support positive lookbehind, so include the
|
85
|
+
# colon in the scan, and strip it out later.
|
86
|
+
STRING_PARAM_CAPTURE_RANGE = 1..-1
|
87
|
+
|
88
|
+
def _match_string(str)
|
89
|
+
if pc = @_params_captures
|
90
|
+
pc.concat(str.scan(/:\w+/).map{|s| s[STRING_PARAM_CAPTURE_RANGE]})
|
91
|
+
end
|
92
|
+
super
|
93
|
+
end
|
94
|
+
# :nocov:
|
95
|
+
end
|
96
|
+
|
97
|
+
# Add the symbol to the list of param capture names if param capturing.
|
98
|
+
def _match_symbol(sym)
|
99
|
+
if pc = @_params_captures
|
100
|
+
pc << sym.to_s
|
101
|
+
end
|
102
|
+
super
|
103
|
+
end
|
104
|
+
|
105
|
+
# If all arguments are strings or symbols, turn on param capturing during
|
106
|
+
# the matching, but turn it back off before yielding to the block. Add
|
107
|
+
# any captures to the params based on the param capture names added by
|
108
|
+
# the matchers.
|
109
|
+
def if_match(args)
|
110
|
+
params = self.params
|
111
|
+
|
112
|
+
if args.all?{|x| x.is_a?(String) || x.is_a?(Symbol)}
|
113
|
+
pc = @_params_captures = []
|
114
|
+
end
|
115
|
+
|
116
|
+
super do |*a|
|
117
|
+
if pc
|
118
|
+
@_params_captures = nil
|
119
|
+
pc.zip(a).each do |k,v|
|
120
|
+
params[k] = v
|
121
|
+
end
|
122
|
+
end
|
123
|
+
params['captures'].concat(a)
|
124
|
+
yield(*a)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
register_plugin(:params_capturing, ParamsCapturing)
|
131
|
+
end
|
132
|
+
end
|
data/lib/roda/plugins/pass.rb
CHANGED
data/lib/roda/plugins/path.rb
CHANGED
data/lib/roda/plugins/render.rb
CHANGED
@@ -77,6 +77,8 @@ class Roda
|
|
77
77
|
# :path :: Use the value given as the full pathname for the file, instead
|
78
78
|
# of using the :views and :engine option in combination with the
|
79
79
|
# template name.
|
80
|
+
# :scope :: The object in which context to evaluate the template. By
|
81
|
+
# default, this is the Roda instance.
|
80
82
|
# :template :: Provides the name of the template to use. This allows you
|
81
83
|
# pass a single options hash to the render/view method, while
|
82
84
|
# still allowing you to specify the template name.
|
@@ -215,7 +217,7 @@ class Roda
|
|
215
217
|
def render(template, opts = OPTS, &block)
|
216
218
|
opts = parse_template_opts(template, opts)
|
217
219
|
merge_render_locals(opts)
|
218
|
-
retrieve_template(opts).render(self, (opts[:locals]||OPTS), &block)
|
220
|
+
retrieve_template(opts).render((opts[:scope]||self), (opts[:locals]||OPTS), &block)
|
219
221
|
end
|
220
222
|
|
221
223
|
# Return the render options for the instance's class. While this
|
data/lib/roda/plugins/static.rb
CHANGED
data/lib/roda/version.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
|
2
|
+
|
3
|
+
describe "params_capturing plugin" do
|
4
|
+
it "should add captures to r.params" do
|
5
|
+
app(:params_capturing) do |r|
|
6
|
+
r.on('foo/:y/:z', :w) do |y, z, w|
|
7
|
+
(r.params.values_at('y', 'z', 'w') + [y, z, w, r[:captures].length]).join('-')
|
8
|
+
end
|
9
|
+
|
10
|
+
r.on("bar/:foo") do |foo|
|
11
|
+
"b-#{foo}-#{r[:foo]}-#{r[:captures].length}"
|
12
|
+
end
|
13
|
+
|
14
|
+
r.on(/(quux)/, /(foo)(bar)/) do |q, foo, bar|
|
15
|
+
"y-#{r[:captures].join}-#{q}-#{foo}-#{bar}"
|
16
|
+
end
|
17
|
+
|
18
|
+
r.on(/(quux)/, :y) do |q, y|
|
19
|
+
r.on(:x) do |x|
|
20
|
+
"y-#{r[:y]}-#{r[:x]}-#{q}-#{y}-#{x}-#{r[:captures].length}"
|
21
|
+
end
|
22
|
+
|
23
|
+
"y-#{r[:y]}-#{q}-#{y}-#{r[:captures].length}"
|
24
|
+
end
|
25
|
+
|
26
|
+
r.on(:x) do |x|
|
27
|
+
"x-#{x}-#{r[:x]}-#{r[:captures].length}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
body('/blarg', 'rack.input'=>StringIO.new).must_equal 'x-blarg-blarg-1'
|
32
|
+
body('/foo/1/2/3', 'rack.input'=>StringIO.new).must_equal '1-2-3-1-2-3-3'
|
33
|
+
body('/bar/banana', 'rack.input'=>StringIO.new).must_equal 'b-banana-banana-1'
|
34
|
+
body('/quux/foobar', 'rack.input'=>StringIO.new).must_equal 'y-quuxfoobar-quux-foo-bar'
|
35
|
+
body('/quux/asdf', 'rack.input'=>StringIO.new).must_equal 'y--quux-asdf-2'
|
36
|
+
body('/quux/asdf/890', 'rack.input'=>StringIO.new).must_equal 'y--890-quux-asdf-890-3'
|
37
|
+
end
|
38
|
+
end
|
data/spec/plugin/render_spec.rb
CHANGED
@@ -396,6 +396,18 @@ describe "render plugin" do
|
|
396
396
|
body('/about').strip.must_equal "<h1>a</h1>"
|
397
397
|
end
|
398
398
|
|
399
|
+
it "Support :scope option to override object in which to evaluate the template" do
|
400
|
+
app(:bare) do
|
401
|
+
plugin :render, :views=>"./spec/views"
|
402
|
+
|
403
|
+
route do |r|
|
404
|
+
render(:inline=>'<%= first %>-<%= last %>', :scope=>[1,2])
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
body.must_equal "1-2"
|
409
|
+
end
|
410
|
+
|
399
411
|
it "render_opts inheritance" do
|
400
412
|
c = Class.new(Roda)
|
401
413
|
c.plugin :render
|
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: 2.
|
4
|
+
version: 2.11.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: 2016-
|
11
|
+
date: 2016-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -176,6 +176,7 @@ extra_rdoc_files:
|
|
176
176
|
- doc/release_notes/2.8.0.txt
|
177
177
|
- doc/release_notes/2.9.0.txt
|
178
178
|
- doc/release_notes/2.10.0.txt
|
179
|
+
- doc/release_notes/2.11.0.txt
|
179
180
|
files:
|
180
181
|
- CHANGELOG
|
181
182
|
- MIT-LICENSE
|
@@ -189,6 +190,7 @@ files:
|
|
189
190
|
- doc/release_notes/2.0.0.txt
|
190
191
|
- doc/release_notes/2.1.0.txt
|
191
192
|
- doc/release_notes/2.10.0.txt
|
193
|
+
- doc/release_notes/2.11.0.txt
|
192
194
|
- doc/release_notes/2.2.0.txt
|
193
195
|
- doc/release_notes/2.3.0.txt
|
194
196
|
- doc/release_notes/2.4.0.txt
|
@@ -242,6 +244,7 @@ files:
|
|
242
244
|
- lib/roda/plugins/not_found.rb
|
243
245
|
- lib/roda/plugins/padrino_render.rb
|
244
246
|
- lib/roda/plugins/param_matchers.rb
|
247
|
+
- lib/roda/plugins/params_capturing.rb
|
245
248
|
- lib/roda/plugins/partials.rb
|
246
249
|
- lib/roda/plugins/pass.rb
|
247
250
|
- lib/roda/plugins/path.rb
|
@@ -319,6 +322,7 @@ files:
|
|
319
322
|
- spec/plugin/not_found_spec.rb
|
320
323
|
- spec/plugin/padrino_render_spec.rb
|
321
324
|
- spec/plugin/param_matchers_spec.rb
|
325
|
+
- spec/plugin/params_capturing_spec.rb
|
322
326
|
- spec/plugin/partials_spec.rb
|
323
327
|
- spec/plugin/pass_spec.rb
|
324
328
|
- spec/plugin/path_matchers_spec.rb
|