roda 2.29.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/spec/plugin_spec.rb
CHANGED
data/spec/redirect_spec.rb
CHANGED
data/spec/request_spec.rb
CHANGED
data/spec/response_spec.rb
CHANGED
data/spec/session_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
$:.unshift(File.expand_path("../lib", File.dirname(__FILE__)))
|
2
2
|
|
3
|
-
require "rubygems"
|
4
|
-
|
5
3
|
if ENV['WARNING']
|
6
4
|
require 'warning'
|
7
5
|
Warning.ignore([:missing_ivar, :method_redefined, :not_reached], File.dirname(File.dirname(__FILE__)))
|
@@ -24,7 +22,7 @@ if ENV['COVERAGE']
|
|
24
22
|
SimpleCov.roda_coverage
|
25
23
|
end
|
26
24
|
|
27
|
-
|
25
|
+
require_relative "../lib/roda"
|
28
26
|
require "stringio"
|
29
27
|
gem 'minitest'
|
30
28
|
require "minitest/autorun"
|
data/spec/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.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: 2017-
|
11
|
+
date: 2017-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: erubis
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: erubi
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -209,6 +195,7 @@ extra_rdoc_files:
|
|
209
195
|
- doc/release_notes/2.27.0.txt
|
210
196
|
- doc/release_notes/2.28.0.txt
|
211
197
|
- doc/release_notes/2.29.0.txt
|
198
|
+
- doc/release_notes/3.0.0.txt
|
212
199
|
files:
|
213
200
|
- CHANGELOG
|
214
201
|
- MIT-LICENSE
|
@@ -250,8 +237,8 @@ files:
|
|
250
237
|
- doc/release_notes/2.7.0.txt
|
251
238
|
- doc/release_notes/2.8.0.txt
|
252
239
|
- doc/release_notes/2.9.0.txt
|
240
|
+
- doc/release_notes/3.0.0.txt
|
253
241
|
- lib/roda.rb
|
254
|
-
- lib/roda/plugins/_erubis_escaping.rb
|
255
242
|
- lib/roda/plugins/_symbol_regexp_matchers.rb
|
256
243
|
- lib/roda/plugins/all_verbs.rb
|
257
244
|
- lib/roda/plugins/assets.rb
|
@@ -307,7 +294,6 @@ files:
|
|
307
294
|
- lib/roda/plugins/path.rb
|
308
295
|
- lib/roda/plugins/path_matchers.rb
|
309
296
|
- lib/roda/plugins/path_rewriter.rb
|
310
|
-
- lib/roda/plugins/per_thread_caching.rb
|
311
297
|
- lib/roda/plugins/placeholder_string_matchers.rb
|
312
298
|
- lib/roda/plugins/precompile_templates.rb
|
313
299
|
- lib/roda/plugins/public.rb
|
@@ -322,7 +308,6 @@ files:
|
|
322
308
|
- lib/roda/plugins/sinatra_helpers.rb
|
323
309
|
- lib/roda/plugins/slash_path_empty.rb
|
324
310
|
- lib/roda/plugins/static.rb
|
325
|
-
- lib/roda/plugins/static_path_info.rb
|
326
311
|
- lib/roda/plugins/static_routing.rb
|
327
312
|
- lib/roda/plugins/status_303.rb
|
328
313
|
- lib/roda/plugins/status_handler.rb
|
@@ -334,8 +319,6 @@ files:
|
|
334
319
|
- lib/roda/plugins/type_routing.rb
|
335
320
|
- lib/roda/plugins/unescape_path.rb
|
336
321
|
- lib/roda/plugins/view_options.rb
|
337
|
-
- lib/roda/plugins/view_subdirs.rb
|
338
|
-
- lib/roda/plugins/websockets.rb
|
339
322
|
- lib/roda/version.rb
|
340
323
|
- spec/all.rb
|
341
324
|
- spec/assets/css/app.scss
|
@@ -348,7 +331,6 @@ files:
|
|
348
331
|
- spec/integration_spec.rb
|
349
332
|
- spec/matchers_spec.rb
|
350
333
|
- spec/opts_spec.rb
|
351
|
-
- spec/plugin/_erubis_escaping_spec.rb
|
352
334
|
- spec/plugin/all_verbs_spec.rb
|
353
335
|
- spec/plugin/assets_preloading_spec.rb
|
354
336
|
- spec/plugin/assets_spec.rb
|
@@ -403,7 +385,6 @@ files:
|
|
403
385
|
- spec/plugin/path_matchers_spec.rb
|
404
386
|
- spec/plugin/path_rewriter_spec.rb
|
405
387
|
- spec/plugin/path_spec.rb
|
406
|
-
- spec/plugin/per_thread_caching_spec.rb
|
407
388
|
- spec/plugin/placeholder_string_matchers_spec.rb
|
408
389
|
- spec/plugin/precompile_templates_spec.rb
|
409
390
|
- spec/plugin/public_spec.rb
|
@@ -429,7 +410,6 @@ files:
|
|
429
410
|
- spec/plugin/type_routing_spec.rb
|
430
411
|
- spec/plugin/unescape_path_spec.rb
|
431
412
|
- spec/plugin/view_options_spec.rb
|
432
|
-
- spec/plugin/websockets_spec.rb
|
433
413
|
- spec/plugin_spec.rb
|
434
414
|
- spec/redirect_spec.rb
|
435
415
|
- spec/request_spec.rb
|
@@ -465,7 +445,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
465
445
|
requirements:
|
466
446
|
- - ">="
|
467
447
|
- !ruby/object:Gem::Version
|
468
|
-
version: 1.
|
448
|
+
version: 1.9.2
|
469
449
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
470
450
|
requirements:
|
471
451
|
- - ">="
|
@@ -473,7 +453,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
473
453
|
version: '0'
|
474
454
|
requirements: []
|
475
455
|
rubyforge_project:
|
476
|
-
rubygems_version: 2.6.
|
456
|
+
rubygems_version: 2.6.13
|
477
457
|
signing_key:
|
478
458
|
specification_version: 4
|
479
459
|
summary: Routing tree web toolkit
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
|
3
|
-
require 'erubis'
|
4
|
-
|
5
|
-
class Roda
|
6
|
-
module RodaPlugins
|
7
|
-
warn 'Using the render plugin :escape option for Erubis escaping support is deprecated. In Roda 3, the :escape option will use Erubi escaping support. You can turn on the Roda 3 behavior by using :escape=>:erubi.'
|
8
|
-
|
9
|
-
# The _erubis_escaping plugin handles escaping of <tt><%= %></tt> inside
|
10
|
-
# ERB templates. It is an internal plugin that should not be loaded
|
11
|
-
# directlyn by user code.
|
12
|
-
module ErubisEscaping
|
13
|
-
# Escaper which escapes by default, but does not escape instances of
|
14
|
-
# classes marked as safe.
|
15
|
-
class UnsafeClassEscaper
|
16
|
-
# Default escaper if the string needs to be escaped.
|
17
|
-
Escaper = Erubis::XmlHelper
|
18
|
-
|
19
|
-
# Record the classes to consider safe.
|
20
|
-
def initialize(safe_classes)
|
21
|
-
@safe_classes = Array(safe_classes).freeze
|
22
|
-
freeze
|
23
|
-
end
|
24
|
-
|
25
|
-
# If the string given is not an instance of one of the safe
|
26
|
-
# classes, escape it, otherwise return it verbatim. If the
|
27
|
-
# given object is not already a string, convert it to a string first.
|
28
|
-
def escape_xml(string)
|
29
|
-
unless string.is_a?(String)
|
30
|
-
string = string.to_s
|
31
|
-
end
|
32
|
-
|
33
|
-
if @safe_classes.any?{|c| string.is_a?(c)}
|
34
|
-
string
|
35
|
-
else
|
36
|
-
Escaper.escape_xml(string)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Subclass that works with specified escaper, also handling
|
42
|
-
# postfix conditionals inside <tt><%= %></tt> tags.
|
43
|
-
class Eruby < Erubis::EscapedEruby
|
44
|
-
# Set escaping object to a local variable
|
45
|
-
def convert_input(codebuf, input)
|
46
|
-
codebuf << '_erubis_escaper = render_opts[:escaper];'
|
47
|
-
super
|
48
|
-
end
|
49
|
-
|
50
|
-
# Use escaping object to escape the code, and handle postfix conditionals.
|
51
|
-
def add_expr_escaped(src, code)
|
52
|
-
src << " " << @bufvar << " << _erubis_escaper.escape_xml((" << code << "));"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
register_plugin(:_erubis_escaping, ErubisEscaping)
|
58
|
-
end
|
59
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
class Roda
|
5
|
-
module RodaPlugins
|
6
|
-
warn "The per_thread_caching plugin is deprecated and will be removed in Roda 3. Consider maintaining the plugin as a separate gem if you would like to keep using it."
|
7
|
-
|
8
|
-
# The per_thread_caching plugin changes the default cache
|
9
|
-
# from being a shared thread safe cache to a separate cache per
|
10
|
-
# thread. This means getting or setting values no longer
|
11
|
-
# needs a mutex, which may be faster when using a thread pool.
|
12
|
-
# However, since the caches are no longer shared, this will
|
13
|
-
# take up more memory.
|
14
|
-
#
|
15
|
-
# Using this plugin changes the matcher regexp cache to use
|
16
|
-
# per-thread caches, and changes the default for future
|
17
|
-
# thread-safe caches to use per-thread caches.
|
18
|
-
#
|
19
|
-
# If you want the render plugin's template cache to use
|
20
|
-
# per-thread caches, you should load this plugin before the
|
21
|
-
# render plugin.
|
22
|
-
module PerThreadCaching
|
23
|
-
def self.configure(app)
|
24
|
-
app::RodaRequest.match_pattern_cache = app.thread_safe_cache
|
25
|
-
end
|
26
|
-
|
27
|
-
class Cache
|
28
|
-
# Mutex used to ensure multiple per-thread caches
|
29
|
-
# don't use the same key
|
30
|
-
MUTEX = ::Mutex.new
|
31
|
-
|
32
|
-
n = 0
|
33
|
-
# Auto incrementing number proc used to make sure
|
34
|
-
# multiple thread-thread caches don't use the same key.
|
35
|
-
N = lambda{MUTEX.synchronize{n += 1}}
|
36
|
-
|
37
|
-
# Store unique symbol used to look up in the per
|
38
|
-
# thread caches.
|
39
|
-
def initialize
|
40
|
-
@o = :"roda_per_thread_cache_#{N.call}"
|
41
|
-
end
|
42
|
-
|
43
|
-
# Return the current thread's cached value.
|
44
|
-
def [](key)
|
45
|
-
_hash[key]
|
46
|
-
end
|
47
|
-
|
48
|
-
# Set the current thread's cached value.
|
49
|
-
def []=(key, value)
|
50
|
-
_hash[key] = value
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
# The current thread's cache.
|
56
|
-
def _hash
|
57
|
-
::Thread.current[@o] ||= {}
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
module ClassMethods
|
62
|
-
# Use the per-thread cache instead of the default cache.
|
63
|
-
def thread_safe_cache
|
64
|
-
Cache.new
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
register_plugin(:per_thread_caching, PerThreadCaching)
|
70
|
-
end
|
71
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
class Roda
|
2
|
-
module RodaPlugins
|
3
|
-
warn 'The static_path_info plugin is deprecated and will be removed in Roda 3. It has been a no-op since Roda 2, and can just be removed from the application.'
|
4
|
-
|
5
|
-
module StaticPathInfo
|
6
|
-
end
|
7
|
-
|
8
|
-
# For backwards compatibilty, don't raise an error
|
9
|
-
# if trying to load the plugin
|
10
|
-
register_plugin(:static_path_info, StaticPathInfo)
|
11
|
-
end
|
12
|
-
end
|
@@ -1,7 +0,0 @@
|
|
1
|
-
# View options is a superset of the view_subdirs plugin,
|
2
|
-
# which no longer exists. For backwards compatibility,
|
3
|
-
# make attempts to load the view_subdirs plugin load the
|
4
|
-
# view_options plugin instead.
|
5
|
-
require 'roda/plugins/view_options'
|
6
|
-
Roda::RodaPlugins.warn "The view_subdirs plugin is a deprecated alias for the view_options plugin that will be removed in Roda 3. Use the view_options plugin instead."
|
7
|
-
Roda::RodaPlugins.register_plugin(:view_subdirs, Roda::RodaPlugins::ViewOptions)
|
@@ -1,107 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
|
3
|
-
require 'faye/websocket'
|
4
|
-
|
5
|
-
class Roda
|
6
|
-
module RodaPlugins
|
7
|
-
warn "The websockets plugin is deprecated and will be removed in Roda 3. Consider maintaining the plugin as a separate gem if you would like to keep using it."
|
8
|
-
|
9
|
-
# The websocket plugin adds integration support for websockets.
|
10
|
-
# Currently, only 'faye-websocket' is supported, so eventmachine
|
11
|
-
# is required for websockets. See the
|
12
|
-
# {faye-websocket documentation}[https://github.com/faye/faye-websocket-ruby]
|
13
|
-
# for details on the faye-websocket API. Note that faye-websocket
|
14
|
-
# is only supported on ruby 1.9.3+, so the websockets plugin only works
|
15
|
-
# on ruby 1.9.3+.
|
16
|
-
#
|
17
|
-
# Here's a simplified example for a basic multi-user,
|
18
|
-
# multi-room chat server, where a message from any user in a room
|
19
|
-
# is sent to all other users in the same room, using a websocket
|
20
|
-
# per room:
|
21
|
-
#
|
22
|
-
# plugin :websockets, :adapter=>:thin, :ping=>45
|
23
|
-
#
|
24
|
-
# MUTEX = Mutex.new
|
25
|
-
# ROOMS = {}
|
26
|
-
#
|
27
|
-
# def sync
|
28
|
-
# MUTEX.synchronize{yield}
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
# route do |r|
|
32
|
-
# r.get "room", Integer do |room_id|
|
33
|
-
# room = sync{ROOMS[room_id] ||= []}
|
34
|
-
#
|
35
|
-
# r.websocket do |ws|
|
36
|
-
# # Routing block taken if request is a websocket request,
|
37
|
-
# # yields a Faye::WebSocket instance
|
38
|
-
#
|
39
|
-
# ws.on(:message) do |event|
|
40
|
-
# sync{room.dup}.each{|user| user.send(event.data)}
|
41
|
-
# end
|
42
|
-
#
|
43
|
-
# ws.on(:close) do |event|
|
44
|
-
# sync{room.delete(ws)}
|
45
|
-
# sync{room.dup}.each{|user| user.send("Someone left")}
|
46
|
-
# end
|
47
|
-
#
|
48
|
-
# sync{room.dup}.each{|user| user.send("Someone joined")}
|
49
|
-
# sync{room.push(ws)}
|
50
|
-
# end
|
51
|
-
#
|
52
|
-
# # If the request is not a websocket request, execution
|
53
|
-
# # continues, similar to how routing in general works.
|
54
|
-
# view 'room'
|
55
|
-
# end
|
56
|
-
# end
|
57
|
-
module Websockets
|
58
|
-
WebSocket = ::Faye::WebSocket
|
59
|
-
OPTS = {}.freeze
|
60
|
-
|
61
|
-
# Add default opions used for websockets. These options are
|
62
|
-
# passed to Faye:WebSocket.new, except that the following
|
63
|
-
# options are handled separately.
|
64
|
-
#
|
65
|
-
# :adapter :: Calls Faye::WebSocket.load adapter with the given
|
66
|
-
# value, used to set the adapter to load, if Faye
|
67
|
-
# requires an adapter to work with the webserver.
|
68
|
-
# Possible options: :thin, :rainbows, :goliath
|
69
|
-
#
|
70
|
-
# See RequestMethods#websocket for additional supported options.
|
71
|
-
def self.configure(app, opts=OPTS)
|
72
|
-
opts = app.opts[:websockets_opts] = (app.opts[:websockets_opts] || {}).merge(opts || {})
|
73
|
-
if adapter = opts.delete(:adapter)
|
74
|
-
WebSocket.load_adapter(adapter.to_s)
|
75
|
-
end
|
76
|
-
opts.freeze
|
77
|
-
end
|
78
|
-
|
79
|
-
module RequestMethods
|
80
|
-
# True if this request is a websocket request, false otherwise.
|
81
|
-
def websocket?
|
82
|
-
WebSocket.websocket?(env)
|
83
|
-
end
|
84
|
-
|
85
|
-
# If the request is a websocket request, yield a websocket to the
|
86
|
-
# block, and return the appropriate rack response after the block
|
87
|
-
# returns. +opts+ is an options hash used when creating the
|
88
|
-
# websocket, except the following options are handled specially:
|
89
|
-
#
|
90
|
-
# :protocols :: Set the protocols to accept, should be an array
|
91
|
-
# of strings.
|
92
|
-
def websocket(opts=OPTS)
|
93
|
-
if websocket?
|
94
|
-
always do
|
95
|
-
opts = Hash[roda_class.opts[:websockets_opts]].merge!(opts)
|
96
|
-
ws = WebSocket.new(env, opts.delete(:protocols), opts)
|
97
|
-
yield ws
|
98
|
-
halt ws.rack_response
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
register_plugin(:websockets, Websockets)
|
106
|
-
end
|
107
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'erubis'
|
5
|
-
require 'tilt'
|
6
|
-
require 'tilt/erb'
|
7
|
-
begin
|
8
|
-
require 'tilt/erubis'
|
9
|
-
rescue LoadError
|
10
|
-
# Tilt 1 support
|
11
|
-
end
|
12
|
-
rescue LoadError
|
13
|
-
warn "tilt or erubis not installed, skipping _erubis_escaping plugin test"
|
14
|
-
else
|
15
|
-
describe "_erubis_escaping plugin" do
|
16
|
-
before do
|
17
|
-
if defined?(Tilt::ErubisTemplate) && ::Tilt['erb'] != Tilt::ErubisTemplate
|
18
|
-
# Set erubis as default erb template handler
|
19
|
-
Tilt.register(Tilt::ErubisTemplate, 'erb')
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
deprecated "should escape inside <%= %> and not inside <%== %>, and handle postfix conditionals" do
|
24
|
-
app(:bare) do
|
25
|
-
plugin :render, :escape=>true
|
26
|
-
|
27
|
-
route do |r|
|
28
|
-
render(:inline=>'<%= "<>" %> <%== "<>" %><%= "<>" if false %>')
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
body.must_equal '<> <>'
|
33
|
-
end
|
34
|
-
|
35
|
-
deprecated "should consider classes in :escape_safe_classes as safe" do
|
36
|
-
c = Class.new(String)
|
37
|
-
c2 = Class.new(String)
|
38
|
-
app(:bare) do
|
39
|
-
plugin :render, :escape=>true, :escape_safe_classes=>c
|
40
|
-
|
41
|
-
route do |r|
|
42
|
-
@c, @c2 = c, c2
|
43
|
-
render(:inline=>'<%= @c2.new("<>") %> <%= @c.new("<>") %>')
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
body.must_equal '<> <>'
|
48
|
-
end
|
49
|
-
|
50
|
-
deprecated "should covnert arguments to strings when escaping with safe classes" do
|
51
|
-
app(:bare) do
|
52
|
-
plugin :render, :escape=>true, :escape_safe_classes=>[]
|
53
|
-
|
54
|
-
route do |r|
|
55
|
-
render(:inline=>'<%= :"<>" %> <%== :"<>" %><%= :"<>" if false %>')
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
body.must_equal '<> <>'
|
60
|
-
end
|
61
|
-
|
62
|
-
deprecated "should allow use of custom :escaper" do
|
63
|
-
escaper = Object.new
|
64
|
-
def escaper.escape_xml(s)
|
65
|
-
s.gsub("'", "''")
|
66
|
-
end
|
67
|
-
app(:bare) do
|
68
|
-
plugin :render, :escape=>true, :escaper=>escaper
|
69
|
-
|
70
|
-
route do |r|
|
71
|
-
render(:inline=>'<%= "ab\'1" %> <%== "ab\'1" %>')
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
body.must_equal "ab''1 ab'1"
|
76
|
-
end
|
77
|
-
|
78
|
-
deprecated "should allow for per-branch escaping via set_view options" do
|
79
|
-
app(:bare) do
|
80
|
-
plugin :render, :escape=>true
|
81
|
-
plugin :view_options
|
82
|
-
|
83
|
-
route do |r|
|
84
|
-
set_view_options :template_opts=>{:engine_class=>nil}
|
85
|
-
r.is 'a' do
|
86
|
-
set_view_options :template_opts=>{:engine_class=>render_opts[:template_opts][:engine_class]}
|
87
|
-
render(:inline=>'<%= "<>" %>')
|
88
|
-
end
|
89
|
-
render(:inline=>'<%= "<>" %>')
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
body('/a').must_equal '<>'
|
94
|
-
body.must_equal '<>'
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|