roda 3.52.0 → 3.53.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df634d0506d88725400ff1b82d04da87928761e9b65937c443e95cd0c084b18f
4
- data.tar.gz: fd7e182f69a5f01cc33a654f2a94602aa121562c7b0e46b75c6bfb3e28b320bf
3
+ metadata.gz: 90bdf6d366ffc4bff40aa51721176291fadb80f56d7904965fe46a1385fe4172
4
+ data.tar.gz: ab1bea5320b4049e918ebb23d1b081c26d5401000f11b02c5f85a1e1b30899c3
5
5
  SHA512:
6
- metadata.gz: 9985fce952a85040aca26f103d82ae5762c0fb70d2c31ee9539bd053bbb700fcb97461114ca6c7f17f7be68eaa2a9e79e89826a54c5caad7c0004ea0d3eaefb5
7
- data.tar.gz: baf99483bd37a9c74c38c3a28bb78d030e5107fceae437065cd7d7237db3ac106535ded55727b339898c398d6198872fbd6ec8c2be23854c88d7a908502c89a4
6
+ metadata.gz: 13bc3beb138174dc8cadfc309458bd1821cbe8b6f80f1cb704752979bf085710181d5fd9df71a3cc1fba2be3b258721f36c8758e202961f9389f23b7555ee78b
7
+ data.tar.gz: 7129008315908bf7ebd6c0115cd8eb531a6357617a5f9ce3a0ffae3703a5cd68793af0d43ac4703752e280a5cc6090234b60640fe25384c4fa8aabe8e04b94af
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ = 3.53.0 (2022-02-14)
2
+
3
+ * Make indifferent_params plugin support rack main branch (jeremyevans)
4
+
5
+ * Add additional_view_directories plugin, for checking multiple view directories for templates (jeremyevans) (#229)
6
+
1
7
  = 3.52.0 (2022-01-14)
2
8
 
3
9
  * Fix return value of Roda.freeze when multi_route plugin is used (jeremyevans) (#240)
@@ -0,0 +1,14 @@
1
+ = New Features
2
+
3
+ * An additional_view_directories plugin has been added, which allows
4
+ you to specify additional directories to look in for templates.
5
+ If the template path does not exist when using the default view
6
+ directory, then each additional view directory will be checked,
7
+ returning the first path that exists:
8
+
9
+ plugin :additional_view_directories, ['admin_views', 'public_views']
10
+
11
+ = Other Improvements
12
+
13
+ * The indifferent_params plugin now avoids a deprecation warning when
14
+ using the rack main branch, which will become Rack 3.
@@ -0,0 +1,68 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The additional_view_directories plugin allows for specifying additional view
7
+ # directories to look in for templates. When rendering a template, it will
8
+ # first try the :views directory specified in the render plugin. If the template
9
+ # file to be rendered does not exist in that directory, it will try each additional
10
+ # view directory specified in this plugin, in order, using the path to the first
11
+ # template file that exists in the file system. If no such path is found, it
12
+ # uses the default path specified by the render plugin.
13
+ #
14
+ # Example:
15
+ #
16
+ # plugin :render, :views=>'dir'
17
+ # plugin :additional_view_directories, ['dir1', 'dir2', 'dir3']
18
+ #
19
+ # route do |r|
20
+ # # Will check the following in order, using path for first
21
+ # # template file that exists:
22
+ # # * dir/t.erb
23
+ # # * dir1/t.erb
24
+ # # * dir2/t.erb
25
+ # # * dir3/t.erb
26
+ # render :t
27
+ # end
28
+ module AdditionalViewDirectories
29
+ # Depend on the render plugin, since this plugin only makes
30
+ # sense when the render plugin is used.
31
+ def self.load_dependencies(app, view_dirs)
32
+ app.plugin :render
33
+ end
34
+
35
+ # Set the additional view directories to look in. Each additional view directory
36
+ # is also added as an allowed path.
37
+ def self.configure(app, view_dirs)
38
+ view_dirs = app.opts[:additional_view_directories] = view_dirs.map{|f| app.expand_path(f, nil)}.freeze
39
+ opts = app.opts[:render]
40
+ app.opts[:render] = opts.merge(:allowed_paths=>(opts[:allowed_paths] + view_dirs).uniq.freeze)
41
+ opts.freeze
42
+ end
43
+
44
+ module InstanceMethods
45
+ private
46
+
47
+ # If the template path does not exist, try looking for the template
48
+ # in each of the additional view directories, in order, returning
49
+ # the first path that exists. If no additional directory includes
50
+ # the template, return the original path.
51
+ def template_path(opts)
52
+ orig_path = super
53
+
54
+ unless File.file?(orig_path)
55
+ self.opts[:additional_view_directories].each do |view_dir|
56
+ path = super(opts.merge(:views=>view_dir))
57
+ return path if File.file?(path)
58
+ end
59
+ end
60
+
61
+ orig_path
62
+ end
63
+ end
64
+ end
65
+
66
+ register_plugin(:additional_view_directories, AdditionalViewDirectories)
67
+ end
68
+ end
@@ -52,17 +52,29 @@ class Roda
52
52
  end
53
53
 
54
54
  class Params < Rack::QueryParser::Params
55
- def initialize(limit = Rack::Utils.key_space_limit)
56
- @limit = limit
57
- @size = 0
58
- @params = Hash.new(&INDIFFERENT_PROC)
55
+ # :nocov:
56
+ if Rack.release >= '2.3'
57
+ def initialize
58
+ @size = 0
59
+ @params = Hash.new(&INDIFFERENT_PROC)
60
+ end
61
+ else
62
+ # :nocov:
63
+ def initialize(limit = Rack::Utils.key_space_limit)
64
+ @limit = limit
65
+ @size = 0
66
+ @params = Hash.new(&INDIFFERENT_PROC)
67
+ end
59
68
  end
60
69
  end
61
70
 
62
71
  end
63
72
 
64
73
  module RequestMethods
65
- QUERY_PARSER = Rack::Utils.default_query_parser = QueryParser.new(QueryParser::Params, 65536, 100)
74
+ # :nocov:
75
+ query_parser = Rack.release >= '2.3' ? QueryParser.new(QueryParser::Params, 32) : QueryParser.new(QueryParser::Params, 65536, 32)
76
+ # :nocov:
77
+ QUERY_PARSER = Rack::Utils.default_query_parser = query_parser
66
78
 
67
79
  private
68
80
 
data/lib/roda/version.rb CHANGED
@@ -4,7 +4,7 @@ class Roda
4
4
  RodaMajorVersion = 3
5
5
 
6
6
  # The minor version of Roda, updated for new feature releases of Roda.
7
- RodaMinorVersion = 52
7
+ RodaMinorVersion = 53
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.
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: 3.52.0
4
+ version: 3.53.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: 2022-01-14 00:00:00.000000000 Z
11
+ date: 2022-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -210,6 +210,7 @@ extra_rdoc_files:
210
210
  - doc/release_notes/3.50.0.txt
211
211
  - doc/release_notes/3.51.0.txt
212
212
  - doc/release_notes/3.52.0.txt
213
+ - doc/release_notes/3.53.0.txt
213
214
  - doc/release_notes/3.6.0.txt
214
215
  - doc/release_notes/3.7.0.txt
215
216
  - doc/release_notes/3.8.0.txt
@@ -269,6 +270,7 @@ files:
269
270
  - doc/release_notes/3.50.0.txt
270
271
  - doc/release_notes/3.51.0.txt
271
272
  - doc/release_notes/3.52.0.txt
273
+ - doc/release_notes/3.53.0.txt
272
274
  - doc/release_notes/3.6.0.txt
273
275
  - doc/release_notes/3.7.0.txt
274
276
  - doc/release_notes/3.8.0.txt
@@ -280,6 +282,7 @@ files:
280
282
  - lib/roda/plugins/_before_hook.rb
281
283
  - lib/roda/plugins/_optimized_matching.rb
282
284
  - lib/roda/plugins/_symbol_regexp_matchers.rb
285
+ - lib/roda/plugins/additional_view_directories.rb
283
286
  - lib/roda/plugins/all_verbs.rb
284
287
  - lib/roda/plugins/assets.rb
285
288
  - lib/roda/plugins/assets_preloading.rb