ultra-max-sys 0.0.1

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.

Potentially problematic release.


This version of ultra-max-sys might be problematic. Click here for more details.

Files changed (163) hide show
  1. checksums.yaml +7 -0
  2. data/roda-3.106.0/MIT-LICENSE +21 -0
  3. data/roda-3.106.0/lib/roda/cache.rb +42 -0
  4. data/roda-3.106.0/lib/roda/plugins/Integer_matcher_max.rb +55 -0
  5. data/roda-3.106.0/lib/roda/plugins/_after_hook.rb +11 -0
  6. data/roda-3.106.0/lib/roda/plugins/_base64.rb +34 -0
  7. data/roda-3.106.0/lib/roda/plugins/_before_hook.rb +41 -0
  8. data/roda-3.106.0/lib/roda/plugins/_optimized_matching.rb +227 -0
  9. data/roda-3.106.0/lib/roda/plugins/_symbol_class_matchers.rb +108 -0
  10. data/roda-3.106.0/lib/roda/plugins/_symbol_regexp_matchers.rb +24 -0
  11. data/roda-3.106.0/lib/roda/plugins/additional_render_engines.rb +61 -0
  12. data/roda-3.106.0/lib/roda/plugins/additional_view_directories.rb +66 -0
  13. data/roda-3.106.0/lib/roda/plugins/all_verbs.rb +50 -0
  14. data/roda-3.106.0/lib/roda/plugins/assets.rb +902 -0
  15. data/roda-3.106.0/lib/roda/plugins/assets_preloading.rb +89 -0
  16. data/roda-3.106.0/lib/roda/plugins/assume_ssl.rb +28 -0
  17. data/roda-3.106.0/lib/roda/plugins/autoload_hash_branches.rb +79 -0
  18. data/roda-3.106.0/lib/roda/plugins/autoload_named_routes.rb +65 -0
  19. data/roda-3.106.0/lib/roda/plugins/backtracking_array.rb +88 -0
  20. data/roda-3.106.0/lib/roda/plugins/bearer_token.rb +28 -0
  21. data/roda-3.106.0/lib/roda/plugins/branch_locals.rb +76 -0
  22. data/roda-3.106.0/lib/roda/plugins/break.rb +43 -0
  23. data/roda-3.106.0/lib/roda/plugins/caching.rb +206 -0
  24. data/roda-3.106.0/lib/roda/plugins/capture_erb.rb +94 -0
  25. data/roda-3.106.0/lib/roda/plugins/chunked.rb +333 -0
  26. data/roda-3.106.0/lib/roda/plugins/class_level_routing.rb +111 -0
  27. data/roda-3.106.0/lib/roda/plugins/class_matchers.rb +155 -0
  28. data/roda-3.106.0/lib/roda/plugins/common_logger.rb +82 -0
  29. data/roda-3.106.0/lib/roda/plugins/conditional_sessions.rb +67 -0
  30. data/roda-3.106.0/lib/roda/plugins/content_for.rb +105 -0
  31. data/roda-3.106.0/lib/roda/plugins/content_security_policy.rb +333 -0
  32. data/roda-3.106.0/lib/roda/plugins/cookie_flags.rb +157 -0
  33. data/roda-3.106.0/lib/roda/plugins/cookies.rb +51 -0
  34. data/roda-3.106.0/lib/roda/plugins/csrf.rb +81 -0
  35. data/roda-3.106.0/lib/roda/plugins/custom_block_results.rb +85 -0
  36. data/roda-3.106.0/lib/roda/plugins/custom_matchers.rb +89 -0
  37. data/roda-3.106.0/lib/roda/plugins/default_headers.rb +64 -0
  38. data/roda-3.106.0/lib/roda/plugins/default_status.rb +35 -0
  39. data/roda-3.106.0/lib/roda/plugins/delay_build.rb +18 -0
  40. data/roda-3.106.0/lib/roda/plugins/delegate.rb +77 -0
  41. data/roda-3.106.0/lib/roda/plugins/delete_empty_headers.rb +36 -0
  42. data/roda-3.106.0/lib/roda/plugins/direct_call.rb +38 -0
  43. data/roda-3.106.0/lib/roda/plugins/disallow_file_uploads.rb +38 -0
  44. data/roda-3.106.0/lib/roda/plugins/drop_body.rb +43 -0
  45. data/roda-3.106.0/lib/roda/plugins/each_part.rb +87 -0
  46. data/roda-3.106.0/lib/roda/plugins/early_hints.rb +25 -0
  47. data/roda-3.106.0/lib/roda/plugins/empty_root.rb +49 -0
  48. data/roda-3.106.0/lib/roda/plugins/environments.rb +79 -0
  49. data/roda-3.106.0/lib/roda/plugins/erb_h.rb +43 -0
  50. data/roda-3.106.0/lib/roda/plugins/error_email.rb +152 -0
  51. data/roda-3.106.0/lib/roda/plugins/error_handler.rb +133 -0
  52. data/roda-3.106.0/lib/roda/plugins/error_mail.rb +149 -0
  53. data/roda-3.106.0/lib/roda/plugins/exception_page.rb +445 -0
  54. data/roda-3.106.0/lib/roda/plugins/filter_common_logger.rb +46 -0
  55. data/roda-3.106.0/lib/roda/plugins/flash.rb +119 -0
  56. data/roda-3.106.0/lib/roda/plugins/h.rb +59 -0
  57. data/roda-3.106.0/lib/roda/plugins/halt.rb +108 -0
  58. data/roda-3.106.0/lib/roda/plugins/hash_branch_view_subdir.rb +76 -0
  59. data/roda-3.106.0/lib/roda/plugins/hash_branches.rb +145 -0
  60. data/roda-3.106.0/lib/roda/plugins/hash_matcher.rb +39 -0
  61. data/roda-3.106.0/lib/roda/plugins/hash_paths.rb +128 -0
  62. data/roda-3.106.0/lib/roda/plugins/hash_public.rb +125 -0
  63. data/roda-3.106.0/lib/roda/plugins/hash_public_cache.rb +91 -0
  64. data/roda-3.106.0/lib/roda/plugins/hash_routes.rb +304 -0
  65. data/roda-3.106.0/lib/roda/plugins/head.rb +99 -0
  66. data/roda-3.106.0/lib/roda/plugins/header_matchers.rb +88 -0
  67. data/roda-3.106.0/lib/roda/plugins/heartbeat.rb +41 -0
  68. data/roda-3.106.0/lib/roda/plugins/hmac_paths.rb +413 -0
  69. data/roda-3.106.0/lib/roda/plugins/hooks.rb +92 -0
  70. data/roda-3.106.0/lib/roda/plugins/host_authorization.rb +155 -0
  71. data/roda-3.106.0/lib/roda/plugins/host_routing.rb +194 -0
  72. data/roda-3.106.0/lib/roda/plugins/hsts.rb +35 -0
  73. data/roda-3.106.0/lib/roda/plugins/indifferent_params.rb +126 -0
  74. data/roda-3.106.0/lib/roda/plugins/inject_erb.rb +33 -0
  75. data/roda-3.106.0/lib/roda/plugins/invalid_request_body.rb +107 -0
  76. data/roda-3.106.0/lib/roda/plugins/ip_from_header.rb +34 -0
  77. data/roda-3.106.0/lib/roda/plugins/json.rb +119 -0
  78. data/roda-3.106.0/lib/roda/plugins/json_parser.rb +107 -0
  79. data/roda-3.106.0/lib/roda/plugins/link_to.rb +83 -0
  80. data/roda-3.106.0/lib/roda/plugins/mail_processor.rb +629 -0
  81. data/roda-3.106.0/lib/roda/plugins/mailer.rb +285 -0
  82. data/roda-3.106.0/lib/roda/plugins/map_matcher.rb +48 -0
  83. data/roda-3.106.0/lib/roda/plugins/match_affix.rb +64 -0
  84. data/roda-3.106.0/lib/roda/plugins/match_hook.rb +34 -0
  85. data/roda-3.106.0/lib/roda/plugins/match_hook_args.rb +93 -0
  86. data/roda-3.106.0/lib/roda/plugins/middleware.rb +225 -0
  87. data/roda-3.106.0/lib/roda/plugins/middleware_stack.rb +101 -0
  88. data/roda-3.106.0/lib/roda/plugins/module_include.rb +96 -0
  89. data/roda-3.106.0/lib/roda/plugins/multi_public.rb +95 -0
  90. data/roda-3.106.0/lib/roda/plugins/multi_route.rb +156 -0
  91. data/roda-3.106.0/lib/roda/plugins/multi_run.rb +144 -0
  92. data/roda-3.106.0/lib/roda/plugins/multi_view.rb +83 -0
  93. data/roda-3.106.0/lib/roda/plugins/multibyte_string_matcher.rb +57 -0
  94. data/roda-3.106.0/lib/roda/plugins/named_routes.rb +167 -0
  95. data/roda-3.106.0/lib/roda/plugins/named_templates.rb +102 -0
  96. data/roda-3.106.0/lib/roda/plugins/not_allowed.rb +151 -0
  97. data/roda-3.106.0/lib/roda/plugins/not_found.rb +55 -0
  98. data/roda-3.106.0/lib/roda/plugins/optimized_segment_matchers.rb +53 -0
  99. data/roda-3.106.0/lib/roda/plugins/optimized_string_matchers.rb +50 -0
  100. data/roda-3.106.0/lib/roda/plugins/padrino_render.rb +42 -0
  101. data/roda-3.106.0/lib/roda/plugins/param_matchers.rb +83 -0
  102. data/roda-3.106.0/lib/roda/plugins/params_capturing.rb +118 -0
  103. data/roda-3.106.0/lib/roda/plugins/part.rb +76 -0
  104. data/roda-3.106.0/lib/roda/plugins/partials.rb +74 -0
  105. data/roda-3.106.0/lib/roda/plugins/pass.rb +47 -0
  106. data/roda-3.106.0/lib/roda/plugins/path.rb +255 -0
  107. data/roda-3.106.0/lib/roda/plugins/path_matchers.rb +54 -0
  108. data/roda-3.106.0/lib/roda/plugins/path_rewriter.rb +111 -0
  109. data/roda-3.106.0/lib/roda/plugins/permissions_policy.rb +340 -0
  110. data/roda-3.106.0/lib/roda/plugins/placeholder_string_matchers.rb +48 -0
  111. data/roda-3.106.0/lib/roda/plugins/plain_hash_response_headers.rb +32 -0
  112. data/roda-3.106.0/lib/roda/plugins/precompile_templates.rb +156 -0
  113. data/roda-3.106.0/lib/roda/plugins/public.rb +182 -0
  114. data/roda-3.106.0/lib/roda/plugins/r.rb +35 -0
  115. data/roda-3.106.0/lib/roda/plugins/recheck_precompiled_assets.rb +107 -0
  116. data/roda-3.106.0/lib/roda/plugins/redirect_http_to_https.rb +99 -0
  117. data/roda-3.106.0/lib/roda/plugins/redirect_path.rb +59 -0
  118. data/roda-3.106.0/lib/roda/plugins/relative_path.rb +76 -0
  119. data/roda-3.106.0/lib/roda/plugins/render.rb +998 -0
  120. data/roda-3.106.0/lib/roda/plugins/render_coverage.rb +105 -0
  121. data/roda-3.106.0/lib/roda/plugins/render_each.rb +224 -0
  122. data/roda-3.106.0/lib/roda/plugins/render_locals.rb +102 -0
  123. data/roda-3.106.0/lib/roda/plugins/request_aref.rb +77 -0
  124. data/roda-3.106.0/lib/roda/plugins/request_headers.rb +83 -0
  125. data/roda-3.106.0/lib/roda/plugins/response_attachment.rb +94 -0
  126. data/roda-3.106.0/lib/roda/plugins/response_content_type.rb +79 -0
  127. data/roda-3.106.0/lib/roda/plugins/response_request.rb +36 -0
  128. data/roda-3.106.0/lib/roda/plugins/route_block_args.rb +50 -0
  129. data/roda-3.106.0/lib/roda/plugins/route_csrf.rb +388 -0
  130. data/roda-3.106.0/lib/roda/plugins/run_append_slash.rb +51 -0
  131. data/roda-3.106.0/lib/roda/plugins/run_handler.rb +51 -0
  132. data/roda-3.106.0/lib/roda/plugins/run_require_slash.rb +46 -0
  133. data/roda-3.106.0/lib/roda/plugins/sec_fetch_site_csrf.rb +131 -0
  134. data/roda-3.106.0/lib/roda/plugins/send_file.rb +127 -0
  135. data/roda-3.106.0/lib/roda/plugins/sessions.rb +537 -0
  136. data/roda-3.106.0/lib/roda/plugins/shape_friendly.rb +232 -0
  137. data/roda-3.106.0/lib/roda/plugins/shared_vars.rb +86 -0
  138. data/roda-3.106.0/lib/roda/plugins/sinatra_helpers.rb +444 -0
  139. data/roda-3.106.0/lib/roda/plugins/slash_path_empty.rb +26 -0
  140. data/roda-3.106.0/lib/roda/plugins/static.rb +42 -0
  141. data/roda-3.106.0/lib/roda/plugins/static_routing.rb +89 -0
  142. data/roda-3.106.0/lib/roda/plugins/status_303.rb +34 -0
  143. data/roda-3.106.0/lib/roda/plugins/status_handler.rb +86 -0
  144. data/roda-3.106.0/lib/roda/plugins/streaming.rb +170 -0
  145. data/roda-3.106.0/lib/roda/plugins/strip_path_prefix.rb +33 -0
  146. data/roda-3.106.0/lib/roda/plugins/symbol_matchers.rb +188 -0
  147. data/roda-3.106.0/lib/roda/plugins/symbol_status.rb +32 -0
  148. data/roda-3.106.0/lib/roda/plugins/symbol_views.rb +37 -0
  149. data/roda-3.106.0/lib/roda/plugins/timestamp_public.rb +78 -0
  150. data/roda-3.106.0/lib/roda/plugins/type_routing.rb +217 -0
  151. data/roda-3.106.0/lib/roda/plugins/typecast_params.rb +1185 -0
  152. data/roda-3.106.0/lib/roda/plugins/typecast_params_sized_integers.rb +108 -0
  153. data/roda-3.106.0/lib/roda/plugins/unescape_path.rb +41 -0
  154. data/roda-3.106.0/lib/roda/plugins/view_options.rb +203 -0
  155. data/roda-3.106.0/lib/roda/plugins/view_subdir_leading_slash.rb +49 -0
  156. data/roda-3.106.0/lib/roda/plugins.rb +68 -0
  157. data/roda-3.106.0/lib/roda/request.rb +722 -0
  158. data/roda-3.106.0/lib/roda/response.rb +221 -0
  159. data/roda-3.106.0/lib/roda/session_middleware.rb +184 -0
  160. data/roda-3.106.0/lib/roda/version.rb +18 -0
  161. data/roda-3.106.0/lib/roda.rb +741 -0
  162. data/ultra-max-sys.gemspec +12 -0
  163. metadata +202 -0
@@ -0,0 +1,55 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The not_found plugin adds a +not_found+ class method which sets
7
+ # a block that is called whenever a 404 response with an empty body
8
+ # would be returned. The usual use case for this is the desire for
9
+ # nice error pages if the page is not found.
10
+ #
11
+ # You can provide the block with the plugin call:
12
+ #
13
+ # plugin :not_found do
14
+ # "Where did it go?"
15
+ # end
16
+ #
17
+ # Or later via a separate call to +not_found+:
18
+ #
19
+ # plugin :not_found
20
+ #
21
+ # not_found do
22
+ # "Where did it go?"
23
+ # end
24
+ #
25
+ # Before not_found is called, any existing headers on the response
26
+ # will be cleared. So if you want to be sure the headers are set
27
+ # even in a not_found block, you need to reset them in the
28
+ # not_found block.
29
+ #
30
+ # This plugin is now a wrapper around the +status_handler+ plugin and
31
+ # still exists mainly for backward compatibility.
32
+ module NotFound
33
+ # Require the status_handler plugin
34
+ def self.load_dependencies(app, &_)
35
+ app.plugin :status_handler
36
+ end
37
+
38
+ # If a block is given, install the block as the not_found handler.
39
+ def self.configure(app, &block)
40
+ if block
41
+ app.not_found(&block)
42
+ end
43
+ end
44
+
45
+ module ClassMethods
46
+ # Install the given block as the not_found handler.
47
+ def not_found(&block)
48
+ status_handler(404, &block)
49
+ end
50
+ end
51
+ end
52
+
53
+ register_plugin(:not_found, NotFound)
54
+ end
55
+ end
@@ -0,0 +1,53 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The optimized_segment_matchers plugin adds two optimized matcher methods,
7
+ # +r.on_segment+ and +r.is_segment+. +r.on_segment+ is an optimized version of
8
+ # +r.on String+ that accepts no arguments and yields the next segment if there
9
+ # is a segment. +r.is_segment+ is an optimized version of +r.is String+ that accepts
10
+ # no arguments and yields the next segment only if it is the last segment.
11
+ #
12
+ # plugin :optimized_segment_matchers
13
+ #
14
+ # route do |r|
15
+ # r.on_segment do |x|
16
+ # # matches any segment (e.g. /a, /b, but not /)
17
+ # r.is_segment do |y|
18
+ # # matches only if final segment (e.g. /a/b, /b/c, but not /c, /c/d/, /c/d/e)
19
+ # end
20
+ # end
21
+ # end
22
+ module OptimizedSegmentMatchers
23
+ module RequestMethods
24
+ # Optimized version of +r.on String+ that yields the next segment if there
25
+ # is a segment.
26
+ def on_segment
27
+ rp = @remaining_path
28
+ if rp.getbyte(0) == 47
29
+ if last = rp.index('/', 1)
30
+ @remaining_path = rp[last, rp.length]
31
+ always{yield rp[1, last-1]}
32
+ elsif (len = rp.length) > 1
33
+ @remaining_path = ""
34
+ always{yield rp[1, len]}
35
+ end
36
+ end
37
+ end
38
+
39
+ # Optimized version of +r.is String+ that yields the next segment only if it
40
+ # is the final segment.
41
+ def is_segment
42
+ rp = @remaining_path
43
+ if rp.getbyte(0) == 47 && !rp.index('/', 1) && (len = rp.length) > 1
44
+ @remaining_path = ""
45
+ always{yield rp[1, len]}
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ register_plugin(:optimized_segment_matchers, OptimizedSegmentMatchers)
52
+ end
53
+ end
@@ -0,0 +1,50 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The optimized_string_matchers plugin adds two optimized matcher methods,
7
+ # +r.on_branch+ and +r.is_exactly+. +r.on_branch+ is an optimized version of
8
+ # +r.on+ that only accepts a single string, and +r.is_exactly+ is an
9
+ # optimized version of +r.is+ that only accepts a single string.
10
+ #
11
+ # plugin :optimized_string_matchers
12
+ #
13
+ # route do |r|
14
+ # r.on_branch "x" do
15
+ # # matches /x and paths starting with /x/
16
+ # r.is_exactly "y" do
17
+ # # matches /x/y
18
+ # end
19
+ # end
20
+ # end
21
+ #
22
+ # If you are using the placeholder_string_matchers plugin, note
23
+ # that both of these methods only work with plain strings, not
24
+ # with strings with embedded colons for capturing. Matching will work
25
+ # correctly in such cases, but the captures will not be yielded to the
26
+ # match blocks.
27
+ module OptimizedStringMatchers
28
+ module RequestMethods
29
+ # Optimized version of +on+ that only supports a single string.
30
+ def on_branch(s)
31
+ always{yield} if _match_string(s)
32
+ end
33
+
34
+ # Optimized version of +is+ that only supports a single string.
35
+ def is_exactly(s)
36
+ rp = @remaining_path
37
+ if _match_string(s)
38
+ if @remaining_path.empty?
39
+ always{yield}
40
+ else
41
+ @remaining_path = rp
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ register_plugin(:optimized_string_matchers, OptimizedStringMatchers)
49
+ end
50
+ end
@@ -0,0 +1,42 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The padrino_render plugin adds rendering support that is
7
+ # similar to Padrino's. While not everything Padrino's
8
+ # rendering supports is supported by this plugin, it
9
+ # currently handles enough to be a drop in replacement for
10
+ # some applications.
11
+ #
12
+ # plugin :padrino_render, views: 'path/2/views'
13
+ #
14
+ # Most notably, this makes the +render+ method default to
15
+ # using the layout, similar to how the +view+ method works
16
+ # in the render plugin. If you want to call render and not
17
+ # use a layout, you can use the <tt>layout: false</tt>
18
+ # option:
19
+ #
20
+ # render('test') # layout
21
+ # render('test', layout: false) # no layout
22
+ #
23
+ # Note that this plugin loads the :partials plugin.
24
+ module PadrinoRender
25
+ # Depend on the render plugin, since this overrides
26
+ # some of its methods.
27
+ def self.load_dependencies(app, opts=OPTS)
28
+ app.plugin :partials, opts
29
+ end
30
+
31
+ module InstanceMethods
32
+ # Call view with the given arguments, so that render
33
+ # uses a layout by default.
34
+ def render(template, opts=OPTS)
35
+ view(template, opts)
36
+ end
37
+ end
38
+ end
39
+
40
+ register_plugin(:padrino_render, PadrinoRender)
41
+ end
42
+ end
@@ -0,0 +1,83 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The param_matchers plugin adds hash matchers that operate
7
+ # on the request's params.
8
+ #
9
+ # It adds a :param matcher for matching on any param with the
10
+ # same name, yielding the value of the param:
11
+ #
12
+ # r.on param: 'foo' do |foo|
13
+ # # Matches '?foo=bar', '?foo='
14
+ # # Doesn't match '?bar=foo'
15
+ # end
16
+ #
17
+ # It adds a :param! matcher for matching on any non-empty param
18
+ # with the same name, yielding the value of the param:
19
+ #
20
+ # r.on(param!: 'foo') do |foo|
21
+ # # Matches '?foo=bar'
22
+ # # Doesn't match '?foo=', '?bar=foo'
23
+ # end
24
+ #
25
+ # It also adds :params and :params! matchers, for matching multiple
26
+ # params at the same time:
27
+ #
28
+ # r.on params: ['foo', 'baz'] do |foo, baz|
29
+ # # Matches '?foo=bar&baz=quuz', '?foo=&baz='
30
+ # # Doesn't match '?foo=bar', '?baz='
31
+ # end
32
+ #
33
+ # r.on params!: ['foo', 'baz'] do |foo, baz|
34
+ # # Matches '?foo=bar&baz=quuz'
35
+ # # Doesn't match '?foo=bar', '?baz=', '?foo=&baz=', '?foo=bar&baz='
36
+ # end
37
+ #
38
+ # Because users have some control over the types of submitted parameters,
39
+ # it is recommended that you explicitly force the correct type for values
40
+ # yielded by the block:
41
+ #
42
+ # r.get(:param=>'foo') do |foo|
43
+ # foo = foo.to_s
44
+ # end
45
+ module ParamMatchers
46
+ module RequestMethods
47
+ # Match the given parameter if present, even if the parameter is empty.
48
+ # Adds match to the captures.
49
+ def match_param(key)
50
+ if v = params[key.to_s]
51
+ @captures << v
52
+ end
53
+ end
54
+
55
+ # Match the given parameter if present and not empty.
56
+ # Adds match to the captures.
57
+ def match_param!(key)
58
+ if (v = params[key.to_s]) && !v.empty?
59
+ @captures << v
60
+ end
61
+ end
62
+
63
+ # Match all given parameters if present, even if any/all parameters is empty.
64
+ # Adds all matches to the captures.
65
+ def match_params(keys)
66
+ keys.each do |key|
67
+ return false unless match_param(key)
68
+ end
69
+ end
70
+
71
+ # Match all given parameters if present and not empty.
72
+ # Adds all matches to the captures.
73
+ def match_params!(keys)
74
+ keys.each do |key|
75
+ return false unless match_param!(key)
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ register_plugin(:param_matchers, ParamMatchers)
82
+ end
83
+ end
@@ -0,0 +1,118 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The params_capturing plugin makes 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.params['bar'] #=> '123'
16
+ # r.params['baz'] #=> 'abc'
17
+ # r.params['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:
27
+ #
28
+ # r.on(:x, /(\d+)\/(\w+)/, :y) do
29
+ # r.params['x'] #=> nil
30
+ # r.params['y'] #=> nil
31
+ # r.params['captures'] #=> ["foo", "123", "abc", "67"]
32
+ # end
33
+ #
34
+ # Note that the request params +captures+ entry will be appended to with
35
+ # each nested match:
36
+ #
37
+ # r.on(:w) do
38
+ # r.on(:x) do
39
+ # r.on(:y) do
40
+ # r.on(:z) do
41
+ # r.params['captures'] # => ["foo", "123", "abc", "67"]
42
+ # end
43
+ # end
44
+ # end
45
+ # end
46
+ #
47
+ # Note that any existing params captures entry will be overwritten
48
+ # by this plugin. You can use +r.GET+ or +r.POST+ to get the underlying
49
+ # entry, depending on how it was submitted.
50
+ #
51
+ # This plugin will also handle string matchers with placeholders if
52
+ # the placeholder_string_matchers plugin is loaded before this plugin.
53
+ #
54
+ # Also note that this plugin will not work correctly if you are using
55
+ # the symbol_matchers plugin with custom symbol matching and are using
56
+ # symbols that capture multiple values or no values.
57
+ module ParamsCapturing
58
+ REQUEST_INSTANCE_VARIABLES = [:@_params_captures].freeze
59
+
60
+ module RequestMethods
61
+ # Lazily initialize captures entry when params is called.
62
+ def params
63
+ ret = super
64
+ ret['captures'] ||= []
65
+ ret
66
+ end
67
+
68
+ private
69
+
70
+ # Add the capture names from this string to list of param
71
+ # capture names if param capturing.
72
+ def _match_string(str)
73
+ cap_len = @captures.length
74
+
75
+ if (ret = super) && (pc = @_params_captures) && (cap_len != @captures.length)
76
+ # Handle use with placeholder_string_matchers plugin
77
+ pc.concat(str.scan(/(?<=:)\w+/))
78
+ end
79
+
80
+ ret
81
+ end
82
+
83
+ # Add the symbol to the list of param capture names if param capturing.
84
+ def _match_symbol(sym)
85
+ if pc = @_params_captures
86
+ pc << sym.to_s
87
+ end
88
+ super
89
+ end
90
+
91
+ # If all arguments are strings or symbols, turn on param capturing during
92
+ # the matching, but turn it back off before yielding to the block. Add
93
+ # any captures to the params based on the param capture names added by
94
+ # the matchers.
95
+ def if_match(args)
96
+ params = self.params
97
+
98
+ if args.all?{|x| x.is_a?(String) || x.is_a?(Symbol)}
99
+ pc = @_params_captures = []
100
+ end
101
+
102
+ super do |*a|
103
+ if pc
104
+ @_params_captures = nil
105
+ pc.zip(a).each do |k,v|
106
+ params[k] = v
107
+ end
108
+ end
109
+ params['captures'].concat(a)
110
+ yield(*a)
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ register_plugin(:params_capturing, ParamsCapturing)
117
+ end
118
+ end
@@ -0,0 +1,76 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The part plugin adds a part method, which is a
7
+ # render-like method that treats all keywords as locals.
8
+ #
9
+ # # Can replace this:
10
+ # render(:template, locals: {foo: 'bar'})
11
+ #
12
+ # # With this:
13
+ # part(:template, foo: 'bar')
14
+ #
15
+ # On Ruby 2.7+, the part method takes a keyword splat, so you
16
+ # must pass keywords and not a positional hash for the locals.
17
+ #
18
+ # If you are using the :assume_fixed_locals render plugin option,
19
+ # template caching is enabled, you are using Ruby 3+, and you
20
+ # are freezing your Roda application, in addition to providing a
21
+ # simpler API, this also provides a significant performance
22
+ # improvement (more significant on Ruby 3.4+).
23
+ module Part
24
+ def self.load_dependencies(app)
25
+ app.plugin :render
26
+ end
27
+
28
+ module ClassMethods
29
+ # When freezing, optimize the part method if assuming fixed locals
30
+ # and caching templates.
31
+ def freeze
32
+ if render_opts[:assume_fixed_locals] && !render_opts[:check_template_mtime]
33
+ include AssumeFixedLocalsInstanceMethods
34
+ end
35
+
36
+ super
37
+ end
38
+ end
39
+
40
+ module InstanceMethods
41
+ if RUBY_VERSION >= '2.7'
42
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
43
+ def part(template, **locals, &block)
44
+ render(template, :locals=>locals, &block)
45
+ end
46
+ RUBY
47
+ # :nocov:
48
+ else
49
+ def part(template, locals=OPTS, &block)
50
+ render(template, :locals=>locals, &block)
51
+ end
52
+ end
53
+ # :nocov:
54
+ end
55
+
56
+ module AssumeFixedLocalsInstanceMethods
57
+ # :nocov:
58
+ if RUBY_VERSION >= '3.0'
59
+ # :nocov:
60
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
61
+ def part(template, ...)
62
+ if optimized_method = _optimized_render_method_for_locals(template, OPTS)
63
+ send(optimized_method[0], ...)
64
+ else
65
+ super
66
+ end
67
+ end
68
+ RUBY
69
+ end
70
+ end
71
+ end
72
+
73
+ register_plugin(:part, Part)
74
+ end
75
+ end
76
+
@@ -0,0 +1,74 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The partials plugin adds a +partial+ method, which renders
7
+ # templates without the layout.
8
+ #
9
+ # plugin :partials, views: 'path/2/views'
10
+ #
11
+ # Template files are prefixed with an underscore:
12
+ #
13
+ # partial('test') # uses _test.erb
14
+ # partial('dir/test') # uses dir/_test.erb
15
+ #
16
+ # This is basically equivalent to:
17
+ #
18
+ # render('_test')
19
+ # render('dir/_test')
20
+ #
21
+ # To render the same template once for each object in an enumerable,
22
+ # you can use the +render_partials+ method:
23
+ #
24
+ # each_partial([1,2,3], :foo) # uses _foo.erb
25
+ #
26
+ # This is basically equivalent to:
27
+ #
28
+ # render_each([1,2,3], "_foo", local: :foo)
29
+ #
30
+ # This plugin depends on the render and render_each plugins.
31
+ module Partials
32
+ # Depend on the render plugin, passing received options to it.
33
+ # Also depend on the render_each plugin.
34
+ def self.load_dependencies(app, opts=OPTS)
35
+ app.plugin :render, opts
36
+ app.plugin :render_each
37
+ end
38
+
39
+ module InstanceMethods
40
+ # For each object in the given enumerable, render the given
41
+ # template (prefixing the template filename with an underscore).
42
+ def each_partial(enum, template, opts=OPTS)
43
+ unless opts.has_key?(:local)
44
+ opts = Hash[opts]
45
+ opts[:local] = render_each_default_local(template)
46
+ end
47
+ render_each(enum, partial_template_name(template.to_s), opts)
48
+ end
49
+
50
+ # Renders the given template without a layout, but
51
+ # prefixes the template filename to use with an
52
+ # underscore.
53
+ def partial(template, opts=OPTS)
54
+ opts = parse_template_opts(template, opts)
55
+ if opts[:template]
56
+ opts[:template] = partial_template_name(opts[:template])
57
+ end
58
+ render_template(opts)
59
+ end
60
+
61
+ private
62
+
63
+ # Prefix the template base filename with an underscore.
64
+ def partial_template_name(template)
65
+ segments = template.split('/')
66
+ segments[-1] = "_#{segments[-1]}"
67
+ segments.join('/')
68
+ end
69
+ end
70
+ end
71
+
72
+ register_plugin(:partials, Partials)
73
+ end
74
+ end
@@ -0,0 +1,47 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The pass plugin adds a request +pass+ method to skip the current match
7
+ # block as if it did not match.
8
+ #
9
+ # plugin :pass
10
+ #
11
+ # route do |r|
12
+ # r.on "foo", :bar do |bar|
13
+ # r.pass if bar == 'baz'
14
+ # "/foo/#{bar} (not baz)"
15
+ # end
16
+ #
17
+ # r.on "foo/baz" do
18
+ # "/foo/baz"
19
+ # end
20
+ # end
21
+ module Pass
22
+ module RequestMethods
23
+ # Skip the current match block as if it did not match.
24
+ def pass
25
+ throw :pass
26
+ end
27
+
28
+ private
29
+
30
+ # Handle passing inside the match block.
31
+ def always
32
+ catch(:pass){super}
33
+ end
34
+
35
+ # Handle passing inside the match block.
36
+ def if_match(_)
37
+ rp = @remaining_path
38
+ ret = catch(:pass){super}
39
+ @remaining_path = rp
40
+ ret
41
+ end
42
+ end
43
+ end
44
+
45
+ register_plugin(:pass, Pass)
46
+ end
47
+ end