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
data/doc/conventions.rdoc
CHANGED
|
@@ -78,14 +78,14 @@ Large applications generally need more structure:
|
|
|
78
78
|
|
|
79
79
|
For larger apps, the +Rakefile+, +assets/+, +migrate+, +models.rb+, +models/+, +public/+, remain the same.
|
|
80
80
|
|
|
81
|
-
+app_name.rb+ should use the +multi_route+ and +
|
|
81
|
+
+app_name.rb+ should use the +multi_route+ and +view_options+ plugin, or the +multi_run+ plugin.
|
|
82
82
|
The routes used by the +multi_route+ or +multi_run+ should be stored in routing files in the +routes/+
|
|
83
83
|
directory, with one file per prefix.
|
|
84
84
|
|
|
85
85
|
For specs/tests, you should have +spec/models/+ and +spec/web/+, with one file per model in +spec/models/+
|
|
86
86
|
and one file per prefix in +spec/web/+.
|
|
87
87
|
|
|
88
|
-
You should have a separate view subdirectory per prefix. If you are using +multi_route+ and +
|
|
88
|
+
You should have a separate view subdirectory per prefix. If you are using +multi_route+ and +view_options+ plugins,
|
|
89
89
|
use +set_view_subdir+ in your routing files to specify the subdirectory to use, so it doesn't need to be
|
|
90
90
|
specified on every call to view.
|
|
91
91
|
|
|
@@ -147,7 +147,7 @@ For larger applications, there are some slight changes to the Roda application f
|
|
|
147
147
|
|
|
148
148
|
plugin :render
|
|
149
149
|
plugin :assets
|
|
150
|
-
plugin :
|
|
150
|
+
plugin :view_options
|
|
151
151
|
plugin :multi_route
|
|
152
152
|
Dir['./routes/*.rb'].each{|f| require f}
|
|
153
153
|
|
|
@@ -158,7 +158,7 @@ For larger applications, there are some slight changes to the Roda application f
|
|
|
158
158
|
Dir['./helpers/*.rb'].each{|f| require f}
|
|
159
159
|
end
|
|
160
160
|
|
|
161
|
-
After loading the +
|
|
161
|
+
After loading the +view_options+ and +multi_route+ plugin, you require all of your
|
|
162
162
|
routing files. Inside your route block, instead of defining your routes, you just call
|
|
163
163
|
+r.multi_route+, which will dispatch to all of your routing files. After your route
|
|
164
164
|
block, you require all of your helper files containing the instance methods for your
|
data/doc/release_notes/1.2.0.txt
CHANGED
|
@@ -322,7 +322,7 @@
|
|
|
322
322
|
be set to false if you do not want subclasses to inherit
|
|
323
323
|
middleware from the superclass. This is useful if the
|
|
324
324
|
superclass dispatches to the subclass via r.run, as otherwise
|
|
325
|
-
it would have to run the
|
|
325
|
+
it would have to run the same middleware stack twice.
|
|
326
326
|
|
|
327
327
|
* A clear_middleware! class accessor has been added, allowing
|
|
328
328
|
you to clear the current middleware stack.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
= Major Changes
|
|
2
|
+
|
|
3
|
+
* String matchers now match literally by default, for simplicity,
|
|
4
|
+
understandability, and performance. Use the String class matcher
|
|
5
|
+
or a symbol matcher to match arbitrary segments.
|
|
6
|
+
|
|
7
|
+
# Before
|
|
8
|
+
r.is "artists/:name" do |artist_name|
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Now
|
|
12
|
+
r.is "artists", String do |artist_name|
|
|
13
|
+
end
|
|
14
|
+
# or
|
|
15
|
+
r.is "artists", :name do |artist_name|
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
You can use the placeholder_string_matchers plugin to restore
|
|
19
|
+
the historical behavior if you don't want to modify your
|
|
20
|
+
routes.
|
|
21
|
+
|
|
22
|
+
* Using an unsupported matcher now raises an error, making it
|
|
23
|
+
more likely to detect using a unexpected value as a matcher
|
|
24
|
+
(which previously matched everything).
|
|
25
|
+
|
|
26
|
+
* Have a route/match block return an unsupported value now
|
|
27
|
+
raises an error if nothing has been written to the body, making
|
|
28
|
+
it more likely to detect using an unexpected value as a block
|
|
29
|
+
result (which previously was ignored).
|
|
30
|
+
|
|
31
|
+
= Backwards Compatibility
|
|
32
|
+
|
|
33
|
+
* Deprecated plugins, features, and constants have been removed.
|
|
34
|
+
Before upgrading to 3.0.0, please upgrade to 2.29.0 first and
|
|
35
|
+
fix any deprecation warnings.
|
|
36
|
+
|
|
37
|
+
* Ruby 1.8.7 support has been dropped. Ruby 1.9.2 is the new
|
|
38
|
+
minimum supported version.
|
|
39
|
+
|
|
40
|
+
* The :check_paths render plugin option now defaults to true so that
|
|
41
|
+
generated template paths are checked by default, reducing the risk
|
|
42
|
+
of rendering arbitrary files.
|
|
43
|
+
|
|
44
|
+
* The assets plugin now defaults to using subresource integrity
|
|
45
|
+
with SHA256 for compiled assets, and using SHA256 instead of
|
|
46
|
+
SHA1 for compiled asset hashes.
|
|
47
|
+
|
|
48
|
+
* Subclassing a Roda app that uses the render plugin now always
|
|
49
|
+
uses a copy of the superclass's template cache.
|
|
50
|
+
|
|
51
|
+
* Using a Roda app as middleware now always uses a subclass
|
|
52
|
+
of the app for the middleware.
|
|
53
|
+
|
|
54
|
+
* public_send is now used instead of send internally unless it is
|
|
55
|
+
expected that private methods will be called.
|
|
56
|
+
|
|
57
|
+
* The match methods added by the symbol_matchers and hash_matchers
|
|
58
|
+
plugins are now private instead of public.
|
|
59
|
+
|
|
60
|
+
= Other Improvements
|
|
61
|
+
|
|
62
|
+
* The streaming plugin has been greatly simplified, by dropping
|
|
63
|
+
deprecated compatibility for EventMachine.
|
|
64
|
+
|
|
65
|
+
* It is now possible to reset the :include_request option to false
|
|
66
|
+
in the json and json_parser plugins by loading the plugin a
|
|
67
|
+
second time with the option set.
|
|
68
|
+
|
|
69
|
+
* The precompile_templates plugin now always sorts locals. This
|
|
70
|
+
plugin should now be used with Tilt 2.0.1+ (which also sorts
|
|
71
|
+
locals), though it will still work with earlier Tilt versions.
|
|
72
|
+
|
|
73
|
+
* The multi_run plugin now recomputes the regexp when freezing the
|
|
74
|
+
app.
|
|
75
|
+
|
|
76
|
+
= Deprecated Features
|
|
77
|
+
|
|
78
|
+
These features will be removed in Roda 3.1.0:
|
|
79
|
+
|
|
80
|
+
* Roda.thread_safe_cache is now deprecated. RodaCache is now used
|
|
81
|
+
as the thread-safe cache class.
|
|
82
|
+
|
|
83
|
+
* RodaRequest#placeholder_string_matcher? (private method) is now
|
|
84
|
+
deprecated and always returns false.
|
data/lib/roda.rb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "rack"
|
|
4
4
|
require "thread"
|
|
5
|
-
|
|
5
|
+
require_relative "roda/version"
|
|
6
6
|
|
|
7
7
|
# The main class for Roda. Roda is built completely out of plugins, with the
|
|
8
8
|
# default plugin being Roda::RodaPlugins::Base, so this class is mostly empty
|
|
@@ -102,9 +102,11 @@ class Roda
|
|
|
102
102
|
# Deprecate the constant with the given name in the given module,
|
|
103
103
|
# if the ruby version supports it.
|
|
104
104
|
def self.deprecate_constant(mod, name)
|
|
105
|
+
# :nocov:
|
|
105
106
|
if RUBY_VERSION >= '2.3'
|
|
106
107
|
mod.deprecate_constant(name)
|
|
107
108
|
end
|
|
109
|
+
# :nocov:
|
|
108
110
|
end
|
|
109
111
|
|
|
110
112
|
# The base plugin for Roda, implementing all default functionality.
|
|
@@ -177,7 +179,7 @@ class Roda
|
|
|
177
179
|
|
|
178
180
|
request_class = Class.new(self::RodaRequest)
|
|
179
181
|
request_class.roda_class = subclass
|
|
180
|
-
request_class.match_pattern_cache =
|
|
182
|
+
request_class.match_pattern_cache = RodaCache.new
|
|
181
183
|
subclass.const_set(:RodaRequest, request_class)
|
|
182
184
|
|
|
183
185
|
response_class = Class.new(self::RodaResponse)
|
|
@@ -223,16 +225,17 @@ class Roda
|
|
|
223
225
|
build_rack_app
|
|
224
226
|
end
|
|
225
227
|
|
|
226
|
-
# A new thread safe cache instance. This is a method so it can be
|
|
227
|
-
# easily overridden for alternative implementations.
|
|
228
228
|
def thread_safe_cache
|
|
229
|
+
# :nocov:
|
|
230
|
+
RodaPlugins.warn "Roda.thread_safe_cache is deprecated and will be removed from Roda 3.1."
|
|
229
231
|
RodaCache.new
|
|
232
|
+
# :nocov:
|
|
230
233
|
end
|
|
231
234
|
|
|
232
235
|
# Add a middleware to use for the rack application. Must be
|
|
233
236
|
# called before calling #route to have an effect. Example:
|
|
234
237
|
#
|
|
235
|
-
# Roda.use Rack::Session::Cookie, :
|
|
238
|
+
# Roda.use Rack::Session::Cookie, secret: ENV['secret']
|
|
236
239
|
def use(*args, &block)
|
|
237
240
|
@middleware << [args, block].freeze
|
|
238
241
|
build_rack_app
|
|
@@ -357,27 +360,6 @@ class Roda
|
|
|
357
360
|
# Instance methods for RodaRequest, mostly related to handling routing
|
|
358
361
|
# for the request.
|
|
359
362
|
module RequestMethods
|
|
360
|
-
PATH_INFO = "PATH_INFO".freeze
|
|
361
|
-
RodaPlugins.deprecate_constant(self, :PATH_INFO)
|
|
362
|
-
SCRIPT_NAME = "SCRIPT_NAME".freeze
|
|
363
|
-
RodaPlugins.deprecate_constant(self, :SCRIPT_NAME)
|
|
364
|
-
REQUEST_METHOD = "REQUEST_METHOD".freeze
|
|
365
|
-
RodaPlugins.deprecate_constant(self, :REQUEST_METHOD)
|
|
366
|
-
EMPTY_STRING = "".freeze
|
|
367
|
-
RodaPlugins.deprecate_constant(self, :EMPTY_STRING)
|
|
368
|
-
SLASH = "/".freeze
|
|
369
|
-
RodaPlugins.deprecate_constant(self, :SLASH)
|
|
370
|
-
COLON = ":".freeze
|
|
371
|
-
RodaPlugins.deprecate_constant(self, :COLON)
|
|
372
|
-
SEGMENT = "([^\\/]+)".freeze
|
|
373
|
-
RodaPlugins.deprecate_constant(self, :SEGMENT)
|
|
374
|
-
TERM_INSPECT = "TERM".freeze
|
|
375
|
-
RodaPlugins.deprecate_constant(self, :TERM_INSPECT)
|
|
376
|
-
GET_REQUEST_METHOD = 'GET'.freeze
|
|
377
|
-
RodaPlugins.deprecate_constant(self, :GET_REQUEST_METHOD)
|
|
378
|
-
SESSION_KEY = 'rack.session'.freeze
|
|
379
|
-
RodaPlugins.deprecate_constant(self, :SESSION_KEY)
|
|
380
|
-
|
|
381
363
|
TERM = Object.new
|
|
382
364
|
def TERM.inspect
|
|
383
365
|
"TERM"
|
|
@@ -611,7 +593,7 @@ class Roda
|
|
|
611
593
|
self.class.roda_class
|
|
612
594
|
end
|
|
613
595
|
|
|
614
|
-
#
|
|
596
|
+
# Match method that only matches +GET+ requests where the current
|
|
615
597
|
# path is +/+. If it matches, the match block is executed, and when
|
|
616
598
|
# the match block returns, the rack response is returned.
|
|
617
599
|
#
|
|
@@ -722,6 +704,7 @@ class Roda
|
|
|
722
704
|
def _match_class(klass)
|
|
723
705
|
meth = :"_match_class_#{klass}"
|
|
724
706
|
if respond_to?(meth, true)
|
|
707
|
+
# Allow calling private methods, as match methods are generally private
|
|
725
708
|
send(meth)
|
|
726
709
|
else
|
|
727
710
|
unsupported_matcher(klass)
|
|
@@ -730,6 +713,7 @@ class Roda
|
|
|
730
713
|
|
|
731
714
|
# Match the given hash if all hash matchers match.
|
|
732
715
|
def _match_hash(hash)
|
|
716
|
+
# Allow calling private methods, as match methods are generally private
|
|
733
717
|
hash.all?{|k,v| send("match_#{k}", v)}
|
|
734
718
|
end
|
|
735
719
|
|
|
@@ -749,35 +733,14 @@ class Roda
|
|
|
749
733
|
# string so that regexp metacharacters are not matched, and recognizes
|
|
750
734
|
# colon tokens for placeholders.
|
|
751
735
|
def _match_string(str)
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
end
|
|
761
|
-
_match_symbol_regexp(match)
|
|
762
|
-
end})
|
|
763
|
-
else
|
|
764
|
-
rp = @remaining_path
|
|
765
|
-
if rp.start_with?("/#{str}")
|
|
766
|
-
last = str.length + 1
|
|
767
|
-
case rp[last]
|
|
768
|
-
when "/"
|
|
769
|
-
@remaining_path = rp[last, rp.length]
|
|
770
|
-
when nil
|
|
771
|
-
@remaining_path = ""
|
|
772
|
-
when Integer
|
|
773
|
-
# :nocov:
|
|
774
|
-
# RODA3: Remove
|
|
775
|
-
# Ruby 1.8 support
|
|
776
|
-
if rp[last].chr == "/"
|
|
777
|
-
@remaining_path = rp[last, rp.length]
|
|
778
|
-
end
|
|
779
|
-
# :nocov:
|
|
780
|
-
end
|
|
736
|
+
rp = @remaining_path
|
|
737
|
+
if rp.start_with?("/#{str}")
|
|
738
|
+
last = str.length + 1
|
|
739
|
+
case rp[last]
|
|
740
|
+
when "/"
|
|
741
|
+
@remaining_path = rp[last, rp.length]
|
|
742
|
+
when nil
|
|
743
|
+
@remaining_path = ""
|
|
781
744
|
end
|
|
782
745
|
end
|
|
783
746
|
end
|
|
@@ -801,11 +764,6 @@ class Roda
|
|
|
801
764
|
# Match any nonempty segment. This should be called without an argument.
|
|
802
765
|
alias _match_class_String _match_symbol
|
|
803
766
|
|
|
804
|
-
# RODA3: Remove
|
|
805
|
-
def _match_symbol_regexp(s)
|
|
806
|
-
"([^\\/]+)"
|
|
807
|
-
end
|
|
808
|
-
|
|
809
767
|
# The base remaining path to use.
|
|
810
768
|
def _remaining_path(env)
|
|
811
769
|
env["PATH_INFO"]
|
|
@@ -838,11 +796,7 @@ class Roda
|
|
|
838
796
|
when nil, false
|
|
839
797
|
# nothing
|
|
840
798
|
else
|
|
841
|
-
|
|
842
|
-
raise RodaError, "unsupported block result: #{result.inspect}"
|
|
843
|
-
else
|
|
844
|
-
RodaPlugins.warn("Unsupported match block return result: #{result.inspect}. This is currently ignored, but will raise an error in Roda 3. Have the block return nil or false to ignore the result.")
|
|
845
|
-
end
|
|
799
|
+
raise RodaError, "unsupported block result: #{result.inspect}"
|
|
846
800
|
end
|
|
847
801
|
end
|
|
848
802
|
|
|
@@ -946,16 +900,15 @@ class Roda
|
|
|
946
900
|
# Whether string matchers are used verbatim, without handling
|
|
947
901
|
# placeholders via colons.
|
|
948
902
|
def placeholder_string_matcher?
|
|
949
|
-
|
|
903
|
+
# :nocov:
|
|
904
|
+
RodaPlugins.warn "Roda::RodaRequest.placeholder_string_matcher? is deprecated and will be removed from Roda 3.1."
|
|
905
|
+
false
|
|
906
|
+
# :nocov:
|
|
950
907
|
end
|
|
951
908
|
|
|
952
909
|
# Handle an unsupported matcher.
|
|
953
910
|
def unsupported_matcher(matcher)
|
|
954
|
-
|
|
955
|
-
raise RodaError, "unsupported matcher: #{matcher.inspect}"
|
|
956
|
-
end
|
|
957
|
-
RodaPlugins.warn("Unsupported matcher used: #{matcher.inspect}. This currently always matches, but will raise an error in Roda 3. Switch to using true if you want the matcher to always match.")
|
|
958
|
-
matcher
|
|
911
|
+
raise RodaError, "unsupported matcher: #{matcher.inspect}"
|
|
959
912
|
end
|
|
960
913
|
end
|
|
961
914
|
|
|
@@ -976,13 +929,6 @@ class Roda
|
|
|
976
929
|
module ResponseMethods
|
|
977
930
|
DEFAULT_HEADERS = {"Content-Type" => "text/html".freeze}.freeze
|
|
978
931
|
|
|
979
|
-
CONTENT_LENGTH = "Content-Length".freeze
|
|
980
|
-
RodaPlugins.deprecate_constant(self, :CONTENT_LENGTH)
|
|
981
|
-
CONTENT_TYPE = "Content-Type".freeze
|
|
982
|
-
RodaPlugins.deprecate_constant(self, :CONTENT_TYPE)
|
|
983
|
-
LOCATION = "Location".freeze
|
|
984
|
-
RodaPlugins.deprecate_constant(self, :LOCATION)
|
|
985
|
-
|
|
986
932
|
# The body for the current response.
|
|
987
933
|
attr_reader :body
|
|
988
934
|
|
data/lib/roda/plugins/assets.rb
CHANGED
|
@@ -24,7 +24,7 @@ class Roda
|
|
|
24
24
|
# When loading the plugin, use the :css and :js options
|
|
25
25
|
# to set the source file(s) to use for CSS and javascript assets:
|
|
26
26
|
#
|
|
27
|
-
# plugin :assets, :
|
|
27
|
+
# plugin :assets, css: 'some_file.scss', js: 'some_file.coffee'
|
|
28
28
|
#
|
|
29
29
|
# This will look for the following files:
|
|
30
30
|
#
|
|
@@ -57,10 +57,10 @@ class Roda
|
|
|
57
57
|
#
|
|
58
58
|
# You can add attributes to the tags by using an options hash:
|
|
59
59
|
#
|
|
60
|
-
# <%= assets(:css, :
|
|
60
|
+
# <%= assets(:css, media: 'print') %>
|
|
61
61
|
#
|
|
62
|
-
# The assets method will respect the application's
|
|
63
|
-
# if it set it will automatically prefix the path with the SCRIPT_NAME for
|
|
62
|
+
# The assets method will respect the application's +:add_script_name+ option,
|
|
63
|
+
# if it set it will automatically prefix the path with the +SCRIPT_NAME+ for
|
|
64
64
|
# the request.
|
|
65
65
|
#
|
|
66
66
|
# == Asset Paths
|
|
@@ -84,8 +84,8 @@ class Roda
|
|
|
84
84
|
# css/js files for your front end and back end. To use asset groups, you
|
|
85
85
|
# pass a hash for the :css and/or :js options:
|
|
86
86
|
#
|
|
87
|
-
# plugin :assets, :
|
|
88
|
-
#
|
|
87
|
+
# plugin :assets, css: {frontend: 'some_frontend_file.scss',
|
|
88
|
+
# backend: 'some_backend_file.scss'}
|
|
89
89
|
#
|
|
90
90
|
# This expects the following directory structure for your assets:
|
|
91
91
|
#
|
|
@@ -93,7 +93,7 @@ class Roda
|
|
|
93
93
|
# assets/css/backend/some_backend_file.scss
|
|
94
94
|
#
|
|
95
95
|
# If you do not want to force that directory structure when using
|
|
96
|
-
# asset groups, you can use the <tt
|
|
96
|
+
# asset groups, you can use the <tt>group_subdirs: false</tt> option.
|
|
97
97
|
#
|
|
98
98
|
# In your view code use an array argument in your call to assets:
|
|
99
99
|
#
|
|
@@ -106,7 +106,7 @@ class Roda
|
|
|
106
106
|
# the plugin:
|
|
107
107
|
#
|
|
108
108
|
# plugin :assets,
|
|
109
|
-
# :
|
|
109
|
+
# css: {frontend: {dashboard: 'some_frontend_file.scss'}}
|
|
110
110
|
#
|
|
111
111
|
# and an extra entry per nesting level when creating the tags.
|
|
112
112
|
#
|
|
@@ -126,7 +126,7 @@ class Roda
|
|
|
126
126
|
# dependencies of those asset files:
|
|
127
127
|
#
|
|
128
128
|
# app.plugin :assets,
|
|
129
|
-
# :
|
|
129
|
+
# dependencies: {'assets/css/bootstrap.scss'=>Dir['assets/css/bootstrap/' '**/*.scss']}
|
|
130
130
|
#
|
|
131
131
|
# == Asset Compilation
|
|
132
132
|
#
|
|
@@ -134,7 +134,7 @@ class Roda
|
|
|
134
134
|
# into a single file, with you can do by calling compile_assets after
|
|
135
135
|
# loading the plugin:
|
|
136
136
|
#
|
|
137
|
-
# plugin :assets, :
|
|
137
|
+
# plugin :assets, css: 'some_file.scss', js: 'some_file.coffee'
|
|
138
138
|
# compile_assets
|
|
139
139
|
#
|
|
140
140
|
# After calling compile_assets, calls to assets in your views will default
|
|
@@ -224,8 +224,8 @@ class Roda
|
|
|
224
224
|
# You can use this to call Autoprefixer on your CSS:
|
|
225
225
|
#
|
|
226
226
|
# plugin :assets, {
|
|
227
|
-
# :
|
|
228
|
-
# :
|
|
227
|
+
# css: [ 'style.scss' ],
|
|
228
|
+
# postprocessor: lambda do |file, type, content|
|
|
229
229
|
# type == :css ? AutoprefixerRails.process(content).css : content
|
|
230
230
|
# end
|
|
231
231
|
# }
|
|
@@ -292,7 +292,8 @@ class Roda
|
|
|
292
292
|
# paths will be considered relative to the application's :root option.
|
|
293
293
|
# :sri :: Enables subresource integrity when setting up references to compiled assets. The value should be
|
|
294
294
|
# :sha256, :sha384, or :sha512 depending on which hash algorithm you want to use. This changes the
|
|
295
|
-
# hash algorithm that Roda will use when naming compiled asset files.
|
|
295
|
+
# hash algorithm that Roda will use when naming compiled asset files. The default is :sha256, you
|
|
296
|
+
# can use nil to disable subresource integrity.
|
|
296
297
|
module Assets
|
|
297
298
|
DEFAULTS = {
|
|
298
299
|
:compiled_name => 'app'.freeze,
|
|
@@ -305,37 +306,9 @@ class Roda
|
|
|
305
306
|
:group_subdirs => true,
|
|
306
307
|
:compiled_css_dir => nil,
|
|
307
308
|
:compiled_js_dir => nil,
|
|
309
|
+
:sri => :sha256
|
|
308
310
|
}.freeze
|
|
309
311
|
|
|
310
|
-
EMPTY_ATTRS = {}.freeze
|
|
311
|
-
RodaPlugins.deprecate_constant(self, :EMPTY_ATTRS)
|
|
312
|
-
JS_END = "\"></script>".freeze
|
|
313
|
-
RodaPlugins.deprecate_constant(self, :JS_END)
|
|
314
|
-
CSS_END = "\" />".freeze
|
|
315
|
-
RodaPlugins.deprecate_constant(self, :CSS_END)
|
|
316
|
-
SPACE = ' '.freeze
|
|
317
|
-
RodaPlugins.deprecate_constant(self, :SPACE)
|
|
318
|
-
DOT = '.'.freeze
|
|
319
|
-
RodaPlugins.deprecate_constant(self, :DOT)
|
|
320
|
-
SLASH = '/'.freeze
|
|
321
|
-
RodaPlugins.deprecate_constant(self, :SLASH)
|
|
322
|
-
NEWLINE = "\n".freeze
|
|
323
|
-
RodaPlugins.deprecate_constant(self, :NEWLINE)
|
|
324
|
-
EMPTY_STRING = ''.freeze
|
|
325
|
-
RodaPlugins.deprecate_constant(self, :EMPTY_STRING)
|
|
326
|
-
JS_SUFFIX = '.js'.freeze
|
|
327
|
-
RodaPlugins.deprecate_constant(self, :JS_SUFFIX)
|
|
328
|
-
CSS_SUFFIX = '.css'.freeze
|
|
329
|
-
RodaPlugins.deprecate_constant(self, :CSS_SUFFIX)
|
|
330
|
-
HTTP_ACCEPT_ENCODING = 'HTTP_ACCEPT_ENCODING'.freeze
|
|
331
|
-
RodaPlugins.deprecate_constant(self, :HTTP_ACCEPT_ENCODING)
|
|
332
|
-
CONTENT_ENCODING = 'Content-Encoding'.freeze
|
|
333
|
-
RodaPlugins.deprecate_constant(self, :CONTENT_ENCODING)
|
|
334
|
-
GZIP = 'gzip'.freeze
|
|
335
|
-
RodaPlugins.deprecate_constant(self, :GZIP)
|
|
336
|
-
DOTGZ = '.gz'.freeze
|
|
337
|
-
RodaPlugins.deprecate_constant(self, :DOTGZ)
|
|
338
|
-
|
|
339
312
|
# Internal exception raised when a compressor cannot be found
|
|
340
313
|
CompressorNotFound = Class.new(RodaError)
|
|
341
314
|
|
|
@@ -527,10 +500,8 @@ class Roda
|
|
|
527
500
|
nil
|
|
528
501
|
end
|
|
529
502
|
|
|
530
|
-
# Compress the given content for the given type using
|
|
531
|
-
#
|
|
532
|
-
# a java runtime. This method can be overridden by the application
|
|
533
|
-
# to use a different compressor.
|
|
503
|
+
# Compress the given content for the given type by using the
|
|
504
|
+
# configured compressor, or trying the supported compressors.
|
|
534
505
|
def compress_asset(content, type)
|
|
535
506
|
case compressor = assets_opts[:"#{type}_compressor"]
|
|
536
507
|
when :none
|
|
@@ -538,6 +509,7 @@ class Roda
|
|
|
538
509
|
when nil
|
|
539
510
|
# default, try different compressors
|
|
540
511
|
else
|
|
512
|
+
# Allow calling private compress methods
|
|
541
513
|
return send("compress_#{type}_#{compressor}", content)
|
|
542
514
|
end
|
|
543
515
|
|
|
@@ -549,6 +521,7 @@ class Roda
|
|
|
549
521
|
|
|
550
522
|
compressors.each do |comp|
|
|
551
523
|
begin
|
|
524
|
+
# Allow calling private compress methods
|
|
552
525
|
if c = send("compress_#{type}_#{comp}", content)
|
|
553
526
|
return c
|
|
554
527
|
end
|
|
@@ -595,25 +568,19 @@ class Roda
|
|
|
595
568
|
# Compress the CSS/JS using YUI Compressor, requires java runtime
|
|
596
569
|
def compress_yui(content, meth)
|
|
597
570
|
require 'yuicompressor'
|
|
598
|
-
::YUICompressor.
|
|
571
|
+
::YUICompressor.public_send(meth, content, :munge => true)
|
|
599
572
|
rescue ::Errno::ENOENT => e
|
|
600
573
|
raise CompressorNotFound, "#{e.class}: #{e.message}", e.backtrace
|
|
601
574
|
end
|
|
602
575
|
|
|
603
576
|
# Return a unique id for the given content. By default, uses the
|
|
604
|
-
#
|
|
577
|
+
# SHA256 hash of the content. This method can be overridden to use
|
|
605
578
|
# a different digest type or to return a static string if you don't
|
|
606
579
|
# want to use a unique value.
|
|
607
580
|
def asset_digest(content)
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
else
|
|
612
|
-
require 'digest/sha1'
|
|
613
|
-
::Digest::SHA1
|
|
614
|
-
end
|
|
615
|
-
|
|
616
|
-
klass.hexdigest(content)
|
|
581
|
+
require 'digest/sha2'
|
|
582
|
+
algo = assets_opts[:sri] || :sha256
|
|
583
|
+
::Digest.const_get(algo.to_s.upcase).hexdigest(content)
|
|
617
584
|
end
|
|
618
585
|
end
|
|
619
586
|
|
|
@@ -682,7 +649,7 @@ class Roda
|
|
|
682
649
|
# Render the asset with the given filename. When assets are compiled,
|
|
683
650
|
# or when the file is already of the given type (no rendering necessary),
|
|
684
651
|
# this returns the contents of the compiled file.
|
|
685
|
-
# When assets are not compiled and the file is not already
|
|
652
|
+
# When assets are not compiled and the file is not already in the same format,
|
|
686
653
|
# this will render the asset using the render plugin.
|
|
687
654
|
# In both cases, if the file has not been modified since the last request,
|
|
688
655
|
# this will return a 304 response.
|