roda 2.10.0 → 2.11.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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +8 -0
  3. data/README.rdoc +5 -0
  4. data/doc/release_notes/2.11.0.txt +70 -0
  5. data/lib/roda/plugins/all_verbs.rb +1 -0
  6. data/lib/roda/plugins/assets.rb +2 -1
  7. data/lib/roda/plugins/backtracking_array.rb +1 -0
  8. data/lib/roda/plugins/caching.rb +1 -0
  9. data/lib/roda/plugins/chunked.rb +1 -0
  10. data/lib/roda/plugins/class_level_routing.rb +1 -0
  11. data/lib/roda/plugins/content_for.rb +1 -0
  12. data/lib/roda/plugins/cookies.rb +1 -0
  13. data/lib/roda/plugins/default_headers.rb +1 -0
  14. data/lib/roda/plugins/default_status.rb +1 -0
  15. data/lib/roda/plugins/delay_build.rb +1 -0
  16. data/lib/roda/plugins/delegate.rb +1 -0
  17. data/lib/roda/plugins/delete_empty_headers.rb +1 -0
  18. data/lib/roda/plugins/drop_body.rb +1 -0
  19. data/lib/roda/plugins/empty_root.rb +1 -0
  20. data/lib/roda/plugins/environments.rb +1 -0
  21. data/lib/roda/plugins/error_handler.rb +1 -0
  22. data/lib/roda/plugins/h.rb +1 -0
  23. data/lib/roda/plugins/halt.rb +1 -0
  24. data/lib/roda/plugins/hash_matcher.rb +1 -0
  25. data/lib/roda/plugins/head.rb +1 -0
  26. data/lib/roda/plugins/header_matchers.rb +1 -0
  27. data/lib/roda/plugins/heartbeat.rb +1 -0
  28. data/lib/roda/plugins/hooks.rb +1 -0
  29. data/lib/roda/plugins/indifferent_params.rb +1 -0
  30. data/lib/roda/plugins/match_affix.rb +1 -0
  31. data/lib/roda/plugins/middleware.rb +1 -0
  32. data/lib/roda/plugins/module_include.rb +1 -0
  33. data/lib/roda/plugins/multi_route.rb +1 -0
  34. data/lib/roda/plugins/multi_run.rb +1 -0
  35. data/lib/roda/plugins/multi_view.rb +1 -0
  36. data/lib/roda/plugins/named_templates.rb +1 -0
  37. data/lib/roda/plugins/not_allowed.rb +1 -0
  38. data/lib/roda/plugins/not_found.rb +1 -0
  39. data/lib/roda/plugins/padrino_render.rb +1 -0
  40. data/lib/roda/plugins/param_matchers.rb +1 -0
  41. data/lib/roda/plugins/params_capturing.rb +132 -0
  42. data/lib/roda/plugins/partials.rb +1 -0
  43. data/lib/roda/plugins/pass.rb +1 -0
  44. data/lib/roda/plugins/path.rb +1 -0
  45. data/lib/roda/plugins/path_matchers.rb +1 -0
  46. data/lib/roda/plugins/path_rewriter.rb +1 -0
  47. data/lib/roda/plugins/per_thread_caching.rb +1 -0
  48. data/lib/roda/plugins/precompile_templates.rb +1 -0
  49. data/lib/roda/plugins/render.rb +3 -1
  50. data/lib/roda/plugins/render_each.rb +1 -0
  51. data/lib/roda/plugins/response_request.rb +1 -0
  52. data/lib/roda/plugins/run_handler.rb +1 -0
  53. data/lib/roda/plugins/shared_vars.rb +1 -0
  54. data/lib/roda/plugins/sinatra_helpers.rb +1 -0
  55. data/lib/roda/plugins/slash_path_empty.rb +1 -0
  56. data/lib/roda/plugins/static.rb +1 -0
  57. data/lib/roda/plugins/status_handler.rb +1 -0
  58. data/lib/roda/plugins/streaming.rb +1 -0
  59. data/lib/roda/plugins/symbol_matchers.rb +1 -0
  60. data/lib/roda/plugins/symbol_views.rb +1 -0
  61. data/lib/roda/plugins/view_options.rb +1 -0
  62. data/lib/roda/version.rb +1 -1
  63. data/spec/plugin/params_capturing_spec.rb +38 -0
  64. data/spec/plugin/render_spec.rb +12 -0
  65. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f294c5f09434c3db4c5c1e8f883071a1381b398c
4
- data.tar.gz: bfa22f2e6fdb5bf030dd9bcdb74cc130ac42e005
3
+ metadata.gz: 8838cf12ea385cc60fd7a700596ea8e5b7d6f048
4
+ data.tar.gz: 17e8862408a8cfec0f55a4ff6bc845bef02df74b
5
5
  SHA512:
6
- metadata.gz: 62058ce501a97f2f4ce334d8a00b24a922f19545f414978b986e840a8b722bff80878c7998fe3c6403f326183341dffca76b894c598dbfd1c5024e02844aed76
7
- data.tar.gz: 87256dacdf54f10450ed05a2e750e6c312b224f53039175faf34a7084539097d916cd91785abd71be678db96f63c489c6b6d2f1ebca40a1299627cf9f5a9a77b
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 &lt;&gt;
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.
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The all_verbs plugin adds methods for http verbs other than
@@ -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
- ::Minjs::Compressor.new(:debug => false).compress(content)
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
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The backtracking_array plugin changes the handling of array
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The caching plugin adds methods related to HTTP caching.
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The chunked plugin allows you to stream responses to clients using
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The class_level_routing plugin adds routing methods at the class level, which can
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The content_for plugin is designed to be used with the
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The cookies plugin adds response methods for handling cookies.
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The default_headers plugin accepts a hash of headers,
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The default_status plugin accepts a block which should
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The delay_build plugin does not build the rack app until
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The delegate plugin allows you to easily setup instance methods in
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The delete_empty_headers plugin deletes any headers whose
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The drop_body plugin automatically drops the body and
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The empty_root plugin makes +r.root+ match both on +/+ and
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The environments plugin adds a environment class accessor to get
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The error_handler plugin adds an error handler to the routing,
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The h plugin adds an +h+ instance method that will HTML
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The halt plugin augments the standard request +halt+ method to allow the response
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The hash_matcher plugin adds the hash_matcher class method, which
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The head plugin attempts to automatically handle HEAD requests,
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The header_matchers plugin adds hash matchers for matching on less-common
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The heartbeat handles heartbeat/status requests. If a request for
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The hooks plugin adds before and after hooks to the request cycle.
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The indifferent_params plugin adds a +params+ instance
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The match_affix plugin allows changing the default prefix and suffix used for
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The middleware plugin allows the Roda app to be used as
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The module_include plugin adds request_module and response_module class methods
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The multi_route plugin allows for multiple named routes, which the
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The multi_run plugin provides the ability to easily dispatch to other
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The multi_view plugin makes it easy to render multiple views, where the
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The named_templates plugin allows you to specify templates by name,
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The not_allowed plugin makes Roda attempt to automatically
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The not_found plugin adds a +not_found+ class method which sets
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The padrino_render plugin adds rendering support that is
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The param_matchers plugin adds hash matchers that operate
@@ -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
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The partials plugin adds a +partial+ method, which renders
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The pass plugin adds a request +pass+ method to skip the current match
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The path plugin adds support for named paths. Using the +path+ class method, you can
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The path_matchers plugin adds hash matchers that operate
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The path_rewriter plugin allows you to rewrite the remaining path
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The per_thread_caching plugin changes the default cache
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The precompile_templates plugin adds support for precompiling template code.
@@ -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
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The render_each plugin allows you to render a template for each
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The response_request plugin gives the response access to the
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The run_handler plugin allows r.run to take a block, which is yielded
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The shared_vars plugin adds a shared method for storing
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The sinatra_helpers plugin ports most of the helper methods
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The slash_path_empty plugin considers "/" as an empty path,
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The static plugin loads the Rack::Static middleware into the application.
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The status_handler plugin adds a +status_handler+ method which sets a
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The streaming plugin adds support for streaming responses
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The symbol_matchers plugin allows you do define custom regexps to use
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The symbol_views plugin allows match blocks to return
@@ -1,5 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ #
3
4
  class Roda
4
5
  module RodaPlugins
5
6
  # The view_options plugin allows you to override view and layout
data/lib/roda/version.rb CHANGED
@@ -4,7 +4,7 @@ class Roda
4
4
  RodaMajorVersion = 2
5
5
 
6
6
  # The minor version of Roda, updated for new feature releases of Roda.
7
- RodaMinorVersion = 10
7
+ RodaMinorVersion = 11
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.
@@ -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
@@ -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.10.0
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-01-15 00:00:00.000000000 Z
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