roda 2.29.0 → 3.0.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 +52 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +51 -109
- data/Rakefile +7 -14
- data/doc/conventions.rdoc +4 -4
- data/doc/release_notes/1.2.0.txt +1 -1
- data/doc/release_notes/3.0.0.txt +84 -0
- data/lib/roda.rb +25 -79
- data/lib/roda/plugins/assets.rb +25 -58
- data/lib/roda/plugins/assets_preloading.rb +0 -5
- data/lib/roda/plugins/backtracking_array.rb +0 -5
- data/lib/roda/plugins/branch_locals.rb +3 -3
- data/lib/roda/plugins/caching.rb +5 -38
- data/lib/roda/plugins/chunked.rb +7 -25
- data/lib/roda/plugins/class_level_routing.rb +2 -2
- data/lib/roda/plugins/content_for.rb +7 -10
- data/lib/roda/plugins/cookies.rb +3 -3
- data/lib/roda/plugins/csrf.rb +2 -2
- data/lib/roda/plugins/delegate.rb +3 -3
- data/lib/roda/plugins/drop_body.rb +0 -7
- data/lib/roda/plugins/empty_root.rb +0 -3
- data/lib/roda/plugins/error_email.rb +4 -6
- data/lib/roda/plugins/error_handler.rb +1 -2
- data/lib/roda/plugins/error_mail.rb +3 -6
- data/lib/roda/plugins/flash.rb +0 -4
- data/lib/roda/plugins/h.rb +5 -0
- data/lib/roda/plugins/hash_matcher.rb +4 -2
- data/lib/roda/plugins/head.rb +5 -7
- data/lib/roda/plugins/header_matchers.rb +12 -33
- data/lib/roda/plugins/heartbeat.rb +2 -7
- data/lib/roda/plugins/indifferent_params.rb +2 -2
- data/lib/roda/plugins/json.rb +6 -14
- data/lib/roda/plugins/json_parser.rb +2 -13
- data/lib/roda/plugins/mailer.rb +29 -39
- data/lib/roda/plugins/match_affix.rb +0 -5
- data/lib/roda/plugins/middleware.rb +10 -15
- data/lib/roda/plugins/multi_route.rb +8 -5
- data/lib/roda/plugins/multi_run.rb +1 -0
- data/lib/roda/plugins/named_templates.rb +2 -2
- data/lib/roda/plugins/optimized_string_matchers.rb +0 -3
- data/lib/roda/plugins/padrino_render.rb +6 -9
- data/lib/roda/plugins/param_matchers.rb +6 -6
- data/lib/roda/plugins/params_capturing.rb +15 -35
- data/lib/roda/plugins/partials.rb +3 -8
- data/lib/roda/plugins/path.rb +5 -5
- data/lib/roda/plugins/path_matchers.rb +3 -3
- data/lib/roda/plugins/path_rewriter.rb +4 -9
- data/lib/roda/plugins/placeholder_string_matchers.rb +1 -1
- data/lib/roda/plugins/precompile_templates.rb +10 -20
- data/lib/roda/plugins/public.rb +6 -9
- data/lib/roda/plugins/render.rb +50 -171
- data/lib/roda/plugins/render_each.rb +4 -7
- data/lib/roda/plugins/render_locals.rb +6 -20
- data/lib/roda/plugins/request_headers.rb +2 -4
- data/lib/roda/plugins/run_append_slash.rb +1 -4
- data/lib/roda/plugins/run_handler.rb +4 -7
- data/lib/roda/plugins/shared_vars.rb +3 -6
- data/lib/roda/plugins/sinatra_helpers.rb +11 -40
- data/lib/roda/plugins/slash_path_empty.rb +0 -3
- data/lib/roda/plugins/static.rb +2 -2
- data/lib/roda/plugins/static_routing.rb +2 -3
- data/lib/roda/plugins/streaming.rb +15 -108
- data/lib/roda/plugins/strip_path_prefix.rb +1 -1
- data/lib/roda/plugins/symbol_matchers.rb +7 -23
- data/lib/roda/plugins/type_routing.rb +4 -9
- data/lib/roda/plugins/view_options.rb +10 -66
- data/lib/roda/version.rb +2 -2
- data/spec/all.rb +0 -2
- data/spec/composition_spec.rb +1 -1
- data/spec/env_spec.rb +1 -1
- data/spec/freeze_spec.rb +1 -1
- data/spec/integration_spec.rb +1 -1
- data/spec/matchers_spec.rb +26 -70
- data/spec/opts_spec.rb +1 -1
- data/spec/plugin/all_verbs_spec.rb +1 -1
- data/spec/plugin/assets_preloading_spec.rb +1 -1
- data/spec/plugin/assets_spec.rb +43 -27
- data/spec/plugin/backtracking_array_spec.rb +1 -1
- data/spec/plugin/branch_locals_spec.rb +1 -1
- data/spec/plugin/caching_spec.rb +1 -1
- data/spec/plugin/chunked_spec.rb +1 -1
- data/spec/plugin/class_level_routing_spec.rb +1 -1
- data/spec/plugin/class_matchers_spec.rb +1 -1
- data/spec/plugin/content_for_spec.rb +2 -7
- data/spec/plugin/cookies_spec.rb +1 -1
- data/spec/plugin/csrf_spec.rb +1 -1
- data/spec/plugin/default_headers_spec.rb +1 -1
- data/spec/plugin/default_status_spec.rb +1 -1
- data/spec/plugin/delay_build_spec.rb +1 -1
- data/spec/plugin/delegate_spec.rb +1 -1
- data/spec/plugin/delete_empty_headers_spec.rb +1 -1
- data/spec/plugin/disallow_file_uploads_spec.rb +2 -2
- data/spec/plugin/drop_body_spec.rb +1 -1
- data/spec/plugin/empty_root_spec.rb +1 -1
- data/spec/plugin/environments_spec.rb +1 -1
- data/spec/plugin/error_email_spec.rb +1 -1
- data/spec/plugin/error_handler_spec.rb +1 -1
- data/spec/plugin/error_mail_spec.rb +2 -2
- data/spec/plugin/flash_spec.rb +1 -1
- data/spec/plugin/h_spec.rb +1 -1
- data/spec/plugin/halt_spec.rb +2 -2
- data/spec/plugin/hash_matcher_spec.rb +1 -1
- data/spec/plugin/head_spec.rb +1 -1
- data/spec/plugin/header_matchers_spec.rb +4 -47
- data/spec/plugin/heartbeat_spec.rb +1 -1
- data/spec/plugin/hooks_spec.rb +1 -1
- data/spec/plugin/indifferent_params_spec.rb +1 -1
- data/spec/plugin/json_parser_spec.rb +12 -1
- data/spec/plugin/json_spec.rb +8 -1
- data/spec/plugin/mailer_spec.rb +1 -1
- data/spec/plugin/match_affix_spec.rb +1 -1
- data/spec/plugin/middleware_spec.rb +15 -1
- data/spec/plugin/module_include_spec.rb +1 -1
- data/spec/plugin/multi_route_spec.rb +5 -3
- data/spec/plugin/multi_run_spec.rb +1 -1
- data/spec/plugin/multi_view_spec.rb +1 -1
- data/spec/plugin/named_templates_spec.rb +1 -1
- data/spec/plugin/not_allowed_spec.rb +1 -1
- data/spec/plugin/not_found_spec.rb +1 -1
- data/spec/plugin/optimized_string_matchers_spec.rb +1 -1
- data/spec/plugin/padrino_render_spec.rb +1 -1
- data/spec/plugin/param_matchers_spec.rb +1 -1
- data/spec/plugin/params_capturing_spec.rb +6 -22
- data/spec/plugin/partials_spec.rb +1 -1
- data/spec/plugin/pass_spec.rb +1 -1
- data/spec/plugin/path_matchers_spec.rb +1 -1
- data/spec/plugin/path_rewriter_spec.rb +1 -1
- data/spec/plugin/path_spec.rb +1 -1
- data/spec/plugin/placeholder_string_matchers_spec.rb +3 -36
- data/spec/plugin/precompile_templates_spec.rb +1 -17
- data/spec/plugin/public_spec.rb +3 -4
- data/spec/plugin/render_each_spec.rb +1 -1
- data/spec/plugin/render_locals_spec.rb +1 -1
- data/spec/plugin/render_spec.rb +28 -114
- data/spec/plugin/request_headers_spec.rb +1 -1
- data/spec/plugin/response_request_spec.rb +1 -1
- data/spec/plugin/run_append_slash_spec.rb +1 -1
- data/spec/plugin/run_handler_spec.rb +1 -1
- data/spec/plugin/shared_vars_spec.rb +1 -1
- data/spec/plugin/sinatra_helpers_spec.rb +1 -1
- data/spec/plugin/slash_path_empty_spec.rb +1 -1
- data/spec/plugin/static_routing_spec.rb +1 -1
- data/spec/plugin/static_spec.rb +1 -1
- data/spec/plugin/status_303_spec.rb +1 -1
- data/spec/plugin/status_handler_spec.rb +1 -1
- data/spec/plugin/streaming_spec.rb +1 -106
- data/spec/plugin/strip_path_prefix_spec.rb +1 -1
- data/spec/plugin/symbol_matchers_spec.rb +1 -77
- data/spec/plugin/symbol_status_spec.rb +1 -1
- data/spec/plugin/symbol_views_spec.rb +1 -1
- data/spec/plugin/type_routing_spec.rb +1 -1
- data/spec/plugin/unescape_path_spec.rb +1 -1
- data/spec/plugin/view_options_spec.rb +16 -110
- data/spec/plugin_spec.rb +1 -1
- data/spec/redirect_spec.rb +1 -1
- data/spec/request_spec.rb +1 -1
- data/spec/response_spec.rb +1 -1
- data/spec/session_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -3
- data/spec/version_spec.rb +1 -1
- metadata +6 -26
- data/lib/roda/plugins/_erubis_escaping.rb +0 -59
- data/lib/roda/plugins/per_thread_caching.rb +0 -71
- data/lib/roda/plugins/static_path_info.rb +0 -12
- data/lib/roda/plugins/view_subdirs.rb +0 -7
- data/lib/roda/plugins/websockets.rb +0 -107
- data/spec/plugin/_erubis_escaping_spec.rb +0 -97
- data/spec/plugin/per_thread_caching_spec.rb +0 -28
- data/spec/plugin/websockets_spec.rb +0 -84
|
@@ -50,11 +50,6 @@ class Roda
|
|
|
50
50
|
:js => 'script'.freeze,
|
|
51
51
|
}.freeze
|
|
52
52
|
|
|
53
|
-
COMMA = ",".freeze
|
|
54
|
-
RodaPlugins.deprecate_constant(self, :COMMA)
|
|
55
|
-
NEWLINE= "\n".freeze
|
|
56
|
-
RodaPlugins.deprecate_constant(self, :NEWLINE)
|
|
57
|
-
|
|
58
53
|
# Depend on the assets plugin, as we'll be calling some functions in it.
|
|
59
54
|
def self.load_dependencies(app)
|
|
60
55
|
app.plugin :assets
|
|
@@ -26,11 +26,6 @@ class Roda
|
|
|
26
26
|
# and the match block yields.
|
|
27
27
|
module BacktrackingArray
|
|
28
28
|
module RequestMethods
|
|
29
|
-
PATH_INFO = "PATH_INFO".freeze
|
|
30
|
-
RodaPlugins.deprecate_constant(self, :PATH_INFO)
|
|
31
|
-
SCRIPT_NAME = "SCRIPT_NAME".freeze
|
|
32
|
-
RodaPlugins.deprecate_constant(self, :SCRIPT_NAME)
|
|
33
|
-
|
|
34
29
|
private
|
|
35
30
|
|
|
36
31
|
# When matching for a single array, after a successful
|
|
@@ -7,13 +7,13 @@ class Roda
|
|
|
7
7
|
# locals for specific branches and routes.
|
|
8
8
|
#
|
|
9
9
|
# plugin :render
|
|
10
|
-
# plugin :render_locals, :
|
|
10
|
+
# plugin :render_locals, render: {footer: 'Default'}, layout: {title: 'Main'}
|
|
11
11
|
# plugin :branch_locals
|
|
12
12
|
#
|
|
13
13
|
# route do |r|
|
|
14
14
|
# r.on "users" do
|
|
15
|
-
# set_layout_locals :
|
|
16
|
-
# set_view_locals :
|
|
15
|
+
# set_layout_locals title: 'Users'
|
|
16
|
+
# set_view_locals footer: '(c) Roda'
|
|
17
17
|
# end
|
|
18
18
|
# end
|
|
19
19
|
#
|
data/lib/roda/plugins/caching.rb
CHANGED
|
@@ -31,14 +31,14 @@ class Roda
|
|
|
31
31
|
# response methods. The +cache_control+ method sets the
|
|
32
32
|
# Cache-Control header using the given hash:
|
|
33
33
|
#
|
|
34
|
-
# response.cache_control :
|
|
34
|
+
# response.cache_control public: true, max_age: 60
|
|
35
35
|
# # Cache-Control: public, max-age=60
|
|
36
36
|
#
|
|
37
37
|
# The +expires+ method is similar, but in addition
|
|
38
38
|
# to setting the HTTP 1.1 Cache-Control header, it also sets
|
|
39
39
|
# the HTTP 1.0 Expires header:
|
|
40
40
|
#
|
|
41
|
-
# response.expires 60, :
|
|
41
|
+
# response.expires 60, public: true
|
|
42
42
|
# # Cache-Control: public, max-age=60
|
|
43
43
|
# # Expires: Mon, 29 Sep 2014 21:25:47 GMT
|
|
44
44
|
#
|
|
@@ -69,25 +69,7 @@ class Roda
|
|
|
69
69
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
70
70
|
# OTHER DEALINGS IN THE SOFTWARE.
|
|
71
71
|
module Caching
|
|
72
|
-
OPTS = {}.freeze
|
|
73
|
-
RodaPlugins.deprecate_constant(self, :OPTS)
|
|
74
|
-
|
|
75
72
|
module RequestMethods
|
|
76
|
-
LAST_MODIFIED = 'Last-Modified'.freeze
|
|
77
|
-
RodaPlugins.deprecate_constant(self, :LAST_MODIFIED)
|
|
78
|
-
HTTP_IF_NONE_MATCH = 'HTTP_IF_NONE_MATCH'.freeze
|
|
79
|
-
RodaPlugins.deprecate_constant(self, :HTTP_IF_NONE_MATCH)
|
|
80
|
-
HTTP_IF_MATCH = 'HTTP_IF_MATCH'.freeze
|
|
81
|
-
RodaPlugins.deprecate_constant(self, :HTTP_IF_MATCH)
|
|
82
|
-
HTTP_IF_MODIFIED_SINCE = 'HTTP_IF_MODIFIED_SINCE'.freeze
|
|
83
|
-
RodaPlugins.deprecate_constant(self, :HTTP_IF_MODIFIED_SINCE)
|
|
84
|
-
HTTP_IF_UNMODIFIED_SINCE = 'HTTP_IF_UNMODIFIED_SINCE'.freeze
|
|
85
|
-
RodaPlugins.deprecate_constant(self, :HTTP_IF_UNMODIFIED_SINCE)
|
|
86
|
-
ETAG = 'ETag'.freeze
|
|
87
|
-
RodaPlugins.deprecate_constant(self, :ETAG)
|
|
88
|
-
STAR = '*'.freeze
|
|
89
|
-
RodaPlugins.deprecate_constant(self, :STAR)
|
|
90
|
-
|
|
91
73
|
# Set the last modified time of the resource using the Last-Modified header.
|
|
92
74
|
# The +time+ argument should be a Time instance.
|
|
93
75
|
#
|
|
@@ -131,7 +113,7 @@ class Roda
|
|
|
131
113
|
#
|
|
132
114
|
# When the current request includes an If-Match header with a
|
|
133
115
|
# etag that doesn't match, immediately returns a response with a 412 status.
|
|
134
|
-
def etag(value, opts=
|
|
116
|
+
def etag(value, opts=OPTS)
|
|
135
117
|
# Before touching this code, please double check RFC 2616 14.24 and 14.26.
|
|
136
118
|
weak = opts[:weak]
|
|
137
119
|
new_resource = opts.fetch(:new_resource){post?}
|
|
@@ -174,27 +156,12 @@ class Roda
|
|
|
174
156
|
end
|
|
175
157
|
|
|
176
158
|
module ResponseMethods
|
|
177
|
-
UNDERSCORE = '_'.freeze
|
|
178
|
-
RodaPlugins.deprecate_constant(self, :UNDERSCORE)
|
|
179
|
-
DASH = '-'.freeze
|
|
180
|
-
RodaPlugins.deprecate_constant(self, :DASH)
|
|
181
|
-
COMMA = ', '.freeze
|
|
182
|
-
RodaPlugins.deprecate_constant(self, :COMMA)
|
|
183
|
-
CACHE_CONTROL = 'Cache-Control'.freeze
|
|
184
|
-
RodaPlugins.deprecate_constant(self, :CACHE_CONTROL)
|
|
185
|
-
EXPIRES = 'Expires'.freeze
|
|
186
|
-
RodaPlugins.deprecate_constant(self, :EXPIRES)
|
|
187
|
-
CONTENT_TYPE = 'Content-Type'.freeze
|
|
188
|
-
RodaPlugins.deprecate_constant(self, :CONTENT_TYPE)
|
|
189
|
-
CONTENT_LENGTH = 'Content-Length'.freeze
|
|
190
|
-
RodaPlugins.deprecate_constant(self, :CONTENT_LENGTH)
|
|
191
|
-
|
|
192
159
|
# Specify response freshness policy for using the Cache-Control header.
|
|
193
160
|
# Options can can any non-value directives (:public, :private, :no_cache,
|
|
194
161
|
# :no_store, :must_revalidate, :proxy_revalidate), with true as the value.
|
|
195
162
|
# Options can also contain value directives (:max_age, :s_maxage).
|
|
196
163
|
#
|
|
197
|
-
# response.cache_control :
|
|
164
|
+
# response.cache_control public: true, max_age: 60
|
|
198
165
|
# # => Cache-Control: public, max-age=60
|
|
199
166
|
#
|
|
200
167
|
# See RFC 2616 / 14.9 for more on standard cache control directives:
|
|
@@ -214,7 +181,7 @@ class Roda
|
|
|
214
181
|
# be an integer number of seconds that the current request should be
|
|
215
182
|
# cached for. Also sets the Expires header, useful if you have
|
|
216
183
|
# HTTP 1.0 clients (Cache-Control is an HTTP 1.1 header).
|
|
217
|
-
def expires(max_age, opts=
|
|
184
|
+
def expires(max_age, opts=OPTS)
|
|
218
185
|
cache_control(Hash[opts].merge!(:max_age=>max_age))
|
|
219
186
|
self['Expires'] = (Time.now + max_age).httpdate
|
|
220
187
|
end
|
data/lib/roda/plugins/chunked.rb
CHANGED
|
@@ -60,7 +60,7 @@ class Roda
|
|
|
60
60
|
# If you want to chunk all responses, pass the :chunk_by_default option
|
|
61
61
|
# when loading the plugin:
|
|
62
62
|
#
|
|
63
|
-
# plugin :chunked, :
|
|
63
|
+
# plugin :chunked, chunk_by_default: true
|
|
64
64
|
#
|
|
65
65
|
# then you can just use the normal view method:
|
|
66
66
|
#
|
|
@@ -104,10 +104,10 @@ class Roda
|
|
|
104
104
|
# <% flush %><%= render(:subtemplate) %>
|
|
105
105
|
#
|
|
106
106
|
# If you want to use chunked encoding when rendering a template, but don't
|
|
107
|
-
# want to use a layout, pass the :
|
|
107
|
+
# want to use a layout, pass the <tt>layout: false</tt> option to chunked.
|
|
108
108
|
#
|
|
109
109
|
# r.root do
|
|
110
|
-
# chunked(:index, :
|
|
110
|
+
# chunked(:index, layout: false)
|
|
111
111
|
# end
|
|
112
112
|
#
|
|
113
113
|
# In order to handle errors in chunked responses, you can override the
|
|
@@ -133,7 +133,7 @@ class Roda
|
|
|
133
133
|
# X-Accel-Buffering header. To set this header or similar headers for
|
|
134
134
|
# all chunked responses, pass a :headers option when loading the plugin:
|
|
135
135
|
#
|
|
136
|
-
# plugin :chunked, :
|
|
136
|
+
# plugin :chunked, headers: {'X-Accel-Buffering'=>'no'}
|
|
137
137
|
#
|
|
138
138
|
# The chunked plugin requires the render plugin, and only works for
|
|
139
139
|
# template engines that store their template output variable in
|
|
@@ -145,26 +145,15 @@ class Roda
|
|
|
145
145
|
# method is not called until template rendering, the flash may not be
|
|
146
146
|
# rotated.
|
|
147
147
|
module Chunked
|
|
148
|
-
OPTS = {}.freeze
|
|
149
|
-
RodaPlugins.deprecate_constant(self, :OPTS)
|
|
150
|
-
HTTP_VERSION = 'HTTP_VERSION'.freeze
|
|
151
|
-
RodaPlugins.deprecate_constant(self, :HTTP_VERSION)
|
|
152
|
-
HTTP11 = "HTTP/1.1".freeze
|
|
153
|
-
RodaPlugins.deprecate_constant(self, :HTTP11)
|
|
154
|
-
TRANSFER_ENCODING = 'Transfer-Encoding'.freeze
|
|
155
|
-
RodaPlugins.deprecate_constant(self, :TRANSFER_ENCODING)
|
|
156
|
-
CHUNKED = 'chunked'.freeze
|
|
157
|
-
RodaPlugins.deprecate_constant(self, :CHUNKED)
|
|
158
|
-
|
|
159
148
|
# Depend on the render plugin
|
|
160
|
-
def self.load_dependencies(app, opts=
|
|
149
|
+
def self.load_dependencies(app, opts=OPTS)
|
|
161
150
|
app.plugin :render
|
|
162
151
|
end
|
|
163
152
|
|
|
164
153
|
# Set plugin specific options. Options:
|
|
165
154
|
# :chunk_by_default :: chunk all calls to view by default
|
|
166
155
|
# :headers :: Set default additional headers to use when calling view
|
|
167
|
-
def self.configure(app, opts=
|
|
156
|
+
def self.configure(app, opts=OPTS)
|
|
168
157
|
app.opts[:chunk_by_default] = opts[:chunk_by_default]
|
|
169
158
|
if opts[:headers]
|
|
170
159
|
app.opts[:chunk_headers] = (app.opts[:chunk_headers] || {}).merge(opts[:headers]).freeze
|
|
@@ -173,13 +162,6 @@ class Roda
|
|
|
173
162
|
|
|
174
163
|
# Rack response body instance for chunked responses
|
|
175
164
|
class Body
|
|
176
|
-
CHUNK_SIZE = "%x\r\n".freeze
|
|
177
|
-
RodaPlugins.deprecate_constant(self, :CHUNK_SIZE)
|
|
178
|
-
CRLF = "\r\n".freeze
|
|
179
|
-
RodaPlugins.deprecate_constant(self, :CRLF)
|
|
180
|
-
FINISH = "0\r\n\r\n".freeze
|
|
181
|
-
RodaPlugins.deprecate_constant(self, :FINISH)
|
|
182
|
-
|
|
183
165
|
# Save the scope of the current request handling.
|
|
184
166
|
def initialize(scope)
|
|
185
167
|
@scope = scope
|
|
@@ -221,7 +203,7 @@ class Roda
|
|
|
221
203
|
|
|
222
204
|
# Render a response to the user in chunks. See Chunked for
|
|
223
205
|
# an overview. If a block is given, it is passed to #delay.
|
|
224
|
-
def chunked(template, opts=
|
|
206
|
+
def chunked(template, opts=OPTS, &block)
|
|
225
207
|
unless defined?(@_chunked)
|
|
226
208
|
@_chunked = env['HTTP_VERSION'] == "HTTP/1.1"
|
|
227
209
|
end
|
|
@@ -43,7 +43,7 @@ class Roda
|
|
|
43
43
|
# end
|
|
44
44
|
# end
|
|
45
45
|
#
|
|
46
|
-
# When using the
|
|
46
|
+
# When using the class_level_routing plugin with nested routes, you may also want to use the
|
|
47
47
|
# delegate plugin to delegate certain instance methods to the request object, so you don't have
|
|
48
48
|
# to continually use +request.+ in your routing blocks.
|
|
49
49
|
#
|
|
@@ -90,7 +90,7 @@ class Roda
|
|
|
90
90
|
super do |r|
|
|
91
91
|
opts[:class_level_routes].each do |meth, args, blk|
|
|
92
92
|
req.instance_variable_set(:@remaining_path, rp)
|
|
93
|
-
r.
|
|
93
|
+
r.public_send(meth, *args) do |*a|
|
|
94
94
|
instance_exec(*a, &blk)
|
|
95
95
|
end
|
|
96
96
|
end
|
|
@@ -28,23 +28,23 @@ class Roda
|
|
|
28
28
|
# <%= content_for :foo %>
|
|
29
29
|
#
|
|
30
30
|
# If content_for is used multiple times with the same key,
|
|
31
|
-
# by default, the last call will
|
|
32
|
-
# If you want to
|
|
33
|
-
# option when loading the plugin:
|
|
31
|
+
# by default, the last call will append previous calls.
|
|
32
|
+
# If you want to overwrite the previous content, pass the
|
|
33
|
+
# <tt>append: false</tt> option when loading the plugin:
|
|
34
34
|
#
|
|
35
|
-
# plugin :content_for, :
|
|
35
|
+
# plugin :content_for, append: false
|
|
36
36
|
module ContentFor
|
|
37
37
|
# Depend on the render plugin, since this plugin only makes
|
|
38
38
|
# sense when the render plugin is used.
|
|
39
|
-
def self.load_dependencies(app, _opts =
|
|
39
|
+
def self.load_dependencies(app, _opts = OPTS)
|
|
40
40
|
app.plugin :render
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
# Configure whether to append or overwrite if content_for
|
|
44
44
|
# is called multiple times to set data. Overwrite is default, use
|
|
45
45
|
# the :append option to append.
|
|
46
|
-
def self.configure(app, opts =
|
|
47
|
-
app.opts[:append_content_for] = opts.fetch(:append,
|
|
46
|
+
def self.configure(app, opts = OPTS)
|
|
47
|
+
app.opts[:append_content_for] = opts.fetch(:append, true)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
module InstanceMethods
|
|
@@ -71,9 +71,6 @@ class Roda
|
|
|
71
71
|
if append
|
|
72
72
|
(@_content_for[key] ||= []) << value
|
|
73
73
|
else
|
|
74
|
-
if @_content_for[key] && append.nil?
|
|
75
|
-
RodaPlugins.warn "Attempt to set content_for with same key. This currently overwrites the existing content_for for #{key}. In Roda 3, it will start appending to the existing content_for by default. Use the :append => false option to the content_for plugin to keep the existing behavior."
|
|
76
|
-
end
|
|
77
74
|
@_content_for[key] = value
|
|
78
75
|
end
|
|
79
76
|
elsif @_content_for && (value = @_content_for[key])
|
data/lib/roda/plugins/cookies.rb
CHANGED
|
@@ -14,7 +14,7 @@ class Roda
|
|
|
14
14
|
# defaults for all cookies upon setting and deleting. This is particularly
|
|
15
15
|
# useful for configuring the +domain+ and +path+ of all cookies.
|
|
16
16
|
#
|
|
17
|
-
# plugin :cookies, :
|
|
17
|
+
# plugin :cookies, domain: 'example.com', path: '/api'
|
|
18
18
|
module Cookies
|
|
19
19
|
# Allow setting default cookie options when loading the cookies plugin.
|
|
20
20
|
def self.configure(app, opts={})
|
|
@@ -28,7 +28,7 @@ class Roda
|
|
|
28
28
|
# Example:
|
|
29
29
|
#
|
|
30
30
|
# response.delete_cookie('foo')
|
|
31
|
-
# response.delete_cookie('foo', :
|
|
31
|
+
# response.delete_cookie('foo', domain: 'example.org')
|
|
32
32
|
def delete_cookie(key, value = {})
|
|
33
33
|
::Rack::Utils.delete_cookie_header!(@headers, key, roda_class.opts[:cookies_opts].merge(value))
|
|
34
34
|
end
|
|
@@ -36,7 +36,7 @@ class Roda
|
|
|
36
36
|
# Set the cookie with the given key in the headers.
|
|
37
37
|
#
|
|
38
38
|
# response.set_cookie('foo', 'bar')
|
|
39
|
-
# response.set_cookie('foo', :
|
|
39
|
+
# response.set_cookie('foo', value: 'bar', domain: 'example.org')
|
|
40
40
|
def set_cookie(key, value)
|
|
41
41
|
value = { :value=>value } unless value.respond_to?(:keys)
|
|
42
42
|
::Rack::Utils.set_cookie_header!(@headers, key, roda_class.opts[:cookies_opts].merge(value))
|
data/lib/roda/plugins/csrf.rb
CHANGED
|
@@ -8,12 +8,12 @@ class Roda
|
|
|
8
8
|
# some csrf helper methods to use in your views. To use it, load
|
|
9
9
|
# the plugin, with the options hash passed to Rack::Csrf:
|
|
10
10
|
#
|
|
11
|
-
# plugin :csrf, :
|
|
11
|
+
# plugin :csrf, raise: true
|
|
12
12
|
#
|
|
13
13
|
# Optionally you can choose not to setup rack_csrf middleware on the
|
|
14
14
|
# roda app if you already have one configured:
|
|
15
15
|
#
|
|
16
|
-
# plugin :csrf, :
|
|
16
|
+
# plugin :csrf, skip_middleware: true
|
|
17
17
|
#
|
|
18
18
|
# This adds the following instance methods:
|
|
19
19
|
#
|
|
@@ -52,21 +52,21 @@ class Roda
|
|
|
52
52
|
# Delegate the given methods to the class
|
|
53
53
|
def class_delegate(*meths)
|
|
54
54
|
meths.each do |meth|
|
|
55
|
-
define_method(meth){|*a, &block| self.class.
|
|
55
|
+
define_method(meth){|*a, &block| self.class.public_send(meth, *a, &block)}
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
# Delegate the given methods to the request
|
|
60
60
|
def request_delegate(*meths)
|
|
61
61
|
meths.each do |meth|
|
|
62
|
-
define_method(meth){|*a, &block| @_request.
|
|
62
|
+
define_method(meth){|*a, &block| @_request.public_send(meth, *a, &block)}
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
# Delegate the given methods to the response
|
|
67
67
|
def response_delegate(*meths)
|
|
68
68
|
meths.each do |meth|
|
|
69
|
-
define_method(meth){|*a, &block| @_response.
|
|
69
|
+
define_method(meth){|*a, &block| @_response.public_send(meth, *a, &block)}
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
end
|
|
@@ -12,13 +12,6 @@ class Roda
|
|
|
12
12
|
module ResponseMethods
|
|
13
13
|
DROP_BODY_STATUSES = [100, 101, 102, 204, 205, 304].freeze
|
|
14
14
|
|
|
15
|
-
EMPTY_BODY = [].freeze
|
|
16
|
-
RodaPlugins.deprecate_constant(self, :EMPTY_BODY)
|
|
17
|
-
CONTENT_LENGTH = "Content-Length".freeze
|
|
18
|
-
RodaPlugins.deprecate_constant(self, :CONTENT_LENGTH)
|
|
19
|
-
CONTENT_TYPE = "Content-Type".freeze
|
|
20
|
-
RodaPlugins.deprecate_constant(self, :CONTENT_TYPE)
|
|
21
|
-
|
|
22
15
|
# If the response status indicates a body should not be
|
|
23
16
|
# returned, use an empty body and remove the Content-Length
|
|
24
17
|
# and Content-Type headers.
|
|
@@ -31,9 +31,6 @@ class Roda
|
|
|
31
31
|
# matches only when the current PATH_INFO is +/+ and not when
|
|
32
32
|
# it is empty.
|
|
33
33
|
module EmptyRoot
|
|
34
|
-
EMPTY_STRING = ''.freeze
|
|
35
|
-
RodaPlugins.deprecate_constant(self, :EMPTY_STRING)
|
|
36
|
-
|
|
37
34
|
module RequestMethods
|
|
38
35
|
# Match when the remaining path is the empty string,
|
|
39
36
|
# in addition to the default behavior of matching when
|
|
@@ -8,7 +8,7 @@ class Roda
|
|
|
8
8
|
# send an email related to the exception. This is most useful if you are
|
|
9
9
|
# also using the error_handler plugin:
|
|
10
10
|
#
|
|
11
|
-
# plugin :error_email, :
|
|
11
|
+
# plugin :error_email, to: 'to@example.com', from: 'from@example.com'
|
|
12
12
|
# plugin :error_handler do |e|
|
|
13
13
|
# error_email(e)
|
|
14
14
|
# 'Internal Server Error'
|
|
@@ -37,10 +37,8 @@ class Roda
|
|
|
37
37
|
# for low traffic web applications. For high traffic web applications,
|
|
38
38
|
# use an error reporting service instead of this plugin.
|
|
39
39
|
module ErrorEmail
|
|
40
|
-
OPTS = {}.freeze
|
|
41
|
-
RodaPlugins.deprecate_constant(self, :OPTS)
|
|
42
40
|
DEFAULTS = {
|
|
43
|
-
:headers=>
|
|
41
|
+
:headers=>OPTS,
|
|
44
42
|
:host=>'localhost',
|
|
45
43
|
# :nocov:
|
|
46
44
|
:emailer=>lambda{|h| Net::SMTP.start(h[:host]){|s| s.send_message(h[:message], h[:from], h[:to])}},
|
|
@@ -95,10 +93,10 @@ END
|
|
|
95
93
|
|
|
96
94
|
message
|
|
97
95
|
end
|
|
98
|
-
}
|
|
96
|
+
}.freeze
|
|
99
97
|
|
|
100
98
|
# Set default opts for plugin. See ErrorEmail module RDoc for options.
|
|
101
|
-
def self.configure(app, opts=
|
|
99
|
+
def self.configure(app, opts=OPTS)
|
|
102
100
|
email_opts = app.opts[:error_email] ||= DEFAULTS
|
|
103
101
|
email_opts = email_opts.merge(opts)
|
|
104
102
|
email_opts[:headers] = email_opts[:headers].dup
|
|
@@ -30,12 +30,11 @@ class Roda
|
|
|
30
30
|
# as well set headers and/or write to the body, just like a regular
|
|
31
31
|
# request.
|
|
32
32
|
#
|
|
33
|
-
#
|
|
34
33
|
# By default, this plugin handles StandardError and ScriptError.
|
|
35
34
|
# To override the exception classes it will handle, pass a :classes
|
|
36
35
|
# option to the plugin:
|
|
37
36
|
#
|
|
38
|
-
# plugin :error_handler, :
|
|
37
|
+
# plugin :error_handler, classes: [StandardError, ScriptError, NoMemoryError]
|
|
39
38
|
module ErrorHandler
|
|
40
39
|
DEFAULT_ERROR_HANDLER_CLASSES = [StandardError, ScriptError].freeze
|
|
41
40
|
|
|
@@ -8,7 +8,7 @@ class Roda
|
|
|
8
8
|
# send an email related to the exception. This is most useful if you are
|
|
9
9
|
# also using the error_handler plugin:
|
|
10
10
|
#
|
|
11
|
-
# plugin :error_mail, :
|
|
11
|
+
# plugin :error_mail, to: 'to@example.com', from: 'from@example.com'
|
|
12
12
|
# plugin :error_handler do |e|
|
|
13
13
|
# error_mail(e)
|
|
14
14
|
# 'Internal Server Error'
|
|
@@ -36,12 +36,9 @@ class Roda
|
|
|
36
36
|
# for low traffic web applications. For high traffic web applications,
|
|
37
37
|
# use an error reporting service instead of this plugin.
|
|
38
38
|
module ErrorMail
|
|
39
|
-
OPTS = {}.freeze
|
|
40
|
-
RodaPlugins.deprecate_constant(self, :OPTS)
|
|
41
|
-
|
|
42
39
|
# Set default opts for plugin. See ErrorEmail module RDoc for options.
|
|
43
|
-
def self.configure(app, opts=
|
|
44
|
-
app.opts[:error_mail] = email_opts = (app.opts[:error_mail] ||
|
|
40
|
+
def self.configure(app, opts=OPTS)
|
|
41
|
+
app.opts[:error_mail] = email_opts = (app.opts[:error_mail] || OPTS).merge(opts).freeze
|
|
45
42
|
unless email_opts[:to] && email_opts[:from]
|
|
46
43
|
raise RodaError, "must provide :to and :from options to error_mail plugin"
|
|
47
44
|
end
|
data/lib/roda/plugins/flash.rb
CHANGED
|
@@ -36,10 +36,6 @@ class Roda
|
|
|
36
36
|
# flash['a'] # = >'b'
|
|
37
37
|
# end
|
|
38
38
|
module Flash
|
|
39
|
-
# The internal session key used to store the flash.
|
|
40
|
-
KEY = :_flash
|
|
41
|
-
RodaPlugins.deprecate_constant(self, :KEY)
|
|
42
|
-
|
|
43
39
|
# Simple flash hash, where assiging to the hash updates the flash
|
|
44
40
|
# used in the following request.
|
|
45
41
|
class FlashHash < DelegateClass(Hash)
|