roda 3.62.0 → 3.64.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 912f354ffcb4440bf7955d4db8546f9eccbee3f3a3f91b77604a91228a2433c4
4
- data.tar.gz: 8df8254014b7e8e9b6db623fa2b8269ac5485b5087ee53978080a81ba344a60c
3
+ metadata.gz: 715e94da6acab0fa1c5e8409051f3faf0800ca56874d8640fa8f00c2ac432322
4
+ data.tar.gz: 79d9f75da1af54c8288918f722dff874433c7935a996180311344a24acc751ec
5
5
  SHA512:
6
- metadata.gz: bb43bcbad6e5421935d62a11abc3da27c40559ef1f55b9791d71ab22bd8cc4a73933f85bb68d77feb26efd6bf84f840bd5a202c80938ede330ca67cf9b51ca8b
7
- data.tar.gz: 6f3234b37c506e3037864e7a7b79280f5b190758e8dada8f213b141cd1e4826a03a98017ddccb806082fa551580af9683088c94080157811867c0a3a1ec92b04
6
+ metadata.gz: 507d5395d337ae4e6c13a3ace905a605ecad5690bf8ceabd8d40bf3c9e2b162649a2a6cb79d1422c8c560396f4abdf891d8f3543b9866cd4f20e944acb4b6347
7
+ data.tar.gz: 37cdd77e3b2894ca55370d638e411e3bf10005101d83939a970b242a4750aa2df929994343c20546cdd6046553897e4d7cde19788f10c2406eb5b446d31e97d5
data/CHANGELOG CHANGED
@@ -1,3 +1,19 @@
1
+ = 3.64.0 (2023-01-12)
2
+
3
+ * Automatically expand paths for autoload_hash_branches files, so that relative paths work (jeremyevans)
4
+
5
+ * Make autoload_hash_branches plugin eagerly load the branches when freezing the application (jeremyevans)
6
+
7
+ * Add erb_h plugin for faster (if slightly less safe) html escaping using erb/escape (jeremyevans)
8
+
9
+ = 3.63.0 (2022-12-16)
10
+
11
+ * Make mailer plugin set configured content type for body part for emails with attachments when using mail 2.8+ (jeremyevans)
12
+
13
+ * Add autoload_hash_branches plugin for autoloading file for a hash branch when there is a request for that branch (jeremyevans)
14
+
15
+ * Add mailer plugin :terminal option to make r.mail use a terminal match when provided arguments (jeremyevans)
16
+
1
17
  = 3.62.0 (2022-11-14)
2
18
 
3
19
  * Add typecast_params_sized_integers plugin for converting parameters to sized integers (jeremyevans)
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2022 Jeremy Evans
1
+ Copyright (c) 2014-2023 Jeremy Evans
2
2
  Copyright (c) 2010-2014 Michel Martens, Damian Janowski and Cyril David
3
3
  Copyright (c) 2008-2009 Christian Neukirchen
4
4
 
@@ -0,0 +1,36 @@
1
+ = New Features
2
+
3
+ * An autoload_hash_branches plugin has been added for autoloading
4
+ route files for each hash branch, instead of requiring the route
5
+ files be loaded up front. For example, to automatically load a
6
+ route file for a hash branch on the first request to that branch:
7
+
8
+ plugin :autoload_hash_branches
9
+ autoload_hash_branch('branch_name', '/path/to/file')
10
+ autoload_hash_branch('namespace', 'branch_name', '/path/to/file')
11
+
12
+ The route file loaded should define the expected hash branch.
13
+
14
+ It is common to have route files stored in a directory, with the
15
+ file name matching the branch name. In that case, you can set
16
+ autoloading for all route files in a given directory:
17
+
18
+ plugin :autoload_hash_branches
19
+ autoload_hash_branch_dir('/path/to/dir')
20
+ autoload_hash_branch_dir('namespace', '/path/to/dir')
21
+
22
+ Note that autoloading hash branches does not work if the application
23
+ is frozen. This plugin should only be used in development mode for
24
+ faster startup, or when running tests on a subset of the application
25
+ in order to avoid loading parts of the application unrelated to what
26
+ is being tested.
27
+
28
+ * The mailer plugin now supports a :terminal plugin option to make
29
+ the r.mail method force a terminal match, similar to how r.get
30
+ and other HTTP verb methods work in standard Roda. This behavior
31
+ will become the default in Roda 4.
32
+
33
+ = Other Improvements
34
+
35
+ * The mailer plugin now correctly sets the content_type of the body
36
+ for emails with attachments when using mail 2.8.0+.
@@ -0,0 +1,26 @@
1
+ = New Features
2
+
3
+ * An erb_h plugin has been added for faster HTML escaping using
4
+ erb/escape. erb 4 added erb/escape and it is included in Ruby 3.2.
5
+
6
+ The erb_h plugin is added as a separate plugin because it changes
7
+ the behavior of the h method. The h method added by the h plugin
8
+ will always return a new string, but the h method added by the
9
+ erb_h plugin will return the argument if the argument is a
10
+ string that does not need escaping. By avoiding unnecessary
11
+ string allocations, use of the erb_h plugin can speed up HTML
12
+ escaping.
13
+
14
+ = Other Improvements
15
+
16
+ * The autoload_hash_branches plugin added in Roda 3.63.0 will now
17
+ eagerly load the hash branches when freezing the application,
18
+ allowing the application to continue to work after being frozen.
19
+ Additionally, file paths for the hash branches will now be
20
+ automatically expanded, allowing the use of relative file paths.
21
+
22
+ = Backwards Compatibility
23
+
24
+ * The expanding of file paths in the autoload_hash_branches plugin
25
+ can break applications that were providing relative paths and
26
+ expecting them to be looked up using the Ruby load path.
@@ -0,0 +1,79 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The autoload_hash_branches plugin builds on the hash_branches plugin and allows for
7
+ # delaying loading of a file containing a hash branch for an application until there
8
+ # is a request that uses the hash branch. This can be useful in development
9
+ # to improvement startup time by not loading all branches up front. It can also be
10
+ # useful in testing subsets of an application by only loading the hash branches being
11
+ # tested.
12
+ #
13
+ # You can specify a single hash branch for autoloading:
14
+ #
15
+ # plugin :autoload_hash_branches
16
+ # autoload_hash_branch('branch_name', '/absolute/path/to/file')
17
+ # autoload_hash_branch('namespace', 'branch_name', 'relative/path/to/file')
18
+ #
19
+ # You can also set the plugin to autoload load all hash branch files in a given directory.
20
+ # This will look at each .rb file in the directory, and add an autoload for it, using the
21
+ # filename without the .rb as the branch name:
22
+ #
23
+ # autoload_hash_branch_dir('/path/to/dir')
24
+ # autoload_hash_branch_dir('namespace', '/path/to/dir')
25
+ #
26
+ # In both cases, when the autoloaded file is required, it should redefine the same
27
+ # hash branch. If it does not, requests to the hash branch will result in a 404 error.
28
+ #
29
+ # When freezing an application, all hash branches are automatically loaded, because
30
+ # autoloading hash branches does not work for frozen applications.
31
+ module AutoloadHashBranches
32
+ def self.load_dependencies(app)
33
+ app.plugin :hash_branches
34
+ end
35
+
36
+ def self.configure(app)
37
+ app.opts[:autoload_hash_branch_files] ||= []
38
+ end
39
+
40
+ module ClassMethods
41
+ # Autoload the given file when there is request for the hash branch.
42
+ # The given file should configure the hash branch specified.
43
+ def autoload_hash_branch(namespace='', segment, file)
44
+ segment = "/#{segment}"
45
+ file = File.expand_path(file)
46
+ opts[:autoload_hash_branch_files] << file
47
+ routes = opts[:hash_branches][namespace] ||= {}
48
+ meth = routes[segment] = define_roda_method(routes[segment] || "hash_branch_#{namespace}_#{segment}", 1) do |r|
49
+ loc = method(routes[segment]).source_location
50
+ require file
51
+ # Avoid infinite loop in case method is not overridden
52
+ if method(meth).source_location != loc
53
+ send(meth, r)
54
+ end
55
+ end
56
+ nil
57
+ end
58
+
59
+ # For each .rb file in the given directory, add an autoloaded hash branch
60
+ # based on the file name.
61
+ def autoload_hash_branch_dir(namespace='', dir)
62
+ Dir.new(dir).entries.each do |file|
63
+ if file =~ /\.rb\z/i
64
+ autoload_hash_branch(namespace, file.sub(/\.rb\z/i, ''), File.join(dir, file))
65
+ end
66
+ end
67
+ end
68
+
69
+ # Eagerly load all hash branches when freezing the application.
70
+ def freeze
71
+ opts.delete(:autoload_hash_branch_files).each{|file| require file}
72
+ super
73
+ end
74
+ end
75
+ end
76
+
77
+ register_plugin(:autoload_hash_branches, AutoloadHashBranches)
78
+ end
79
+ end
@@ -0,0 +1,43 @@
1
+ # frozen-string-literal: true
2
+
3
+ require 'erb/escape'
4
+
5
+ #
6
+ class Roda
7
+ module RodaPlugins
8
+ # The erb_h plugin adds an +h+ instance method that will HTML
9
+ # escape the input and return it. This is similar to the h
10
+ # plugin, but it uses erb/escape to implement the HTML escaping,
11
+ # which offers faster performance.
12
+ #
13
+ # To make sure that this speeds up applications using the h
14
+ # plugin, this depends on the h plugin, and overrides the
15
+ # h method.
16
+ #
17
+ # The following example will return "&lt;foo&gt;" as the body.
18
+ #
19
+ # plugin :erb_h
20
+ #
21
+ # route do |r|
22
+ # h('<foo>')
23
+ # end
24
+ #
25
+ # The faster performance offered by the erb_h plugin is due
26
+ # to erb/escape avoiding allocations if not needed (returning the
27
+ # input object if no escaping is needed). That behavior change
28
+ # can cause problems if you mutate the result of the h method
29
+ # (which can mutate the input), or mutate the input of the h
30
+ # method after calling it (which can mutate the result).
31
+ module ErbH
32
+ def self.load_dependencies(app)
33
+ app.plugin :h
34
+ end
35
+
36
+ module InstanceMethods
37
+ define_method(:h, ERB::Escape.instance_method(:html_escape))
38
+ end
39
+ end
40
+
41
+ register_plugin(:erb_h, ErbH)
42
+ end
43
+ end
@@ -401,7 +401,6 @@ END
401
401
 
402
402
  private
403
403
 
404
- # :nocov:
405
404
  if RUBY_VERSION >= '3.2'
406
405
  def exception_page_exception_message(exception)
407
406
  exception.detailed_message(highlight: false).to_s
@@ -413,6 +412,7 @@ END
413
412
  exception.message.to_s
414
413
  end
415
414
  end
415
+ # :nocov:
416
416
  end
417
417
 
418
418
  module RequestMethods
@@ -115,6 +115,11 @@ class Roda
115
115
  #
116
116
  # plugin :mailer, content_type: 'text/html'
117
117
  #
118
+ # For backwards compatibility reasons, the +r.mail+ method does not do
119
+ # a terminal match by default if provided arguments (unlike +r.get+ and
120
+ # +r.post+). You can pass the :terminal option to make +r.mail+ enforce
121
+ # a terminal match if provided arguments.
122
+ #
118
123
  # The mailer plugin does support being used inside a Roda application
119
124
  # that is handling web requests, where the routing block for mails and
120
125
  # web requests is shared. However, it's recommended that you create a
@@ -163,7 +168,8 @@ class Roda
163
168
  # any arguments passed to the +mail+ or +sendmail+ Roda class methods.
164
169
  def mail(*args)
165
170
  if @env["REQUEST_METHOD"] == "MAIL"
166
- if_match(args) do |*vs|
171
+ # RODA4: Make terminal match the default
172
+ send(roda_class.opts[:mailer][:terminal] ? :_verb : :if_match, args) do |*vs|
167
173
  yield(*(vs + @env['roda.mail_args']))
168
174
  end
169
175
  end
@@ -190,9 +196,9 @@ class Roda
190
196
 
191
197
  if content_type = header_content_type || roda_class.opts[:mailer][:content_type]
192
198
  if mail.multipart?
193
- if mail.content_type =~ /multipart\/mixed/ &&
199
+ if /multipart\/mixed/ =~ mail.content_type &&
194
200
  mail.parts.length >= 2 &&
195
- (part = mail.parts.find{|p| !p.attachment && p.content_type == "text/plain"})
201
+ (part = mail.parts.find{|p| !p.attachment && (p.encoded; /text\/plain/ =~ p.content_type)})
196
202
  part.content_type = content_type
197
203
  end
198
204
  else
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 = 62
7
+ RodaMinorVersion = 64
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.62.0
4
+ version: 3.64.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-11-14 00:00:00.000000000 Z
11
+ date: 2023-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -235,6 +235,8 @@ extra_rdoc_files:
235
235
  - doc/release_notes/3.60.0.txt
236
236
  - doc/release_notes/3.61.0.txt
237
237
  - doc/release_notes/3.62.0.txt
238
+ - doc/release_notes/3.63.0.txt
239
+ - doc/release_notes/3.64.0.txt
238
240
  - doc/release_notes/3.7.0.txt
239
241
  - doc/release_notes/3.8.0.txt
240
242
  - doc/release_notes/3.9.0.txt
@@ -304,6 +306,8 @@ files:
304
306
  - doc/release_notes/3.60.0.txt
305
307
  - doc/release_notes/3.61.0.txt
306
308
  - doc/release_notes/3.62.0.txt
309
+ - doc/release_notes/3.63.0.txt
310
+ - doc/release_notes/3.64.0.txt
307
311
  - doc/release_notes/3.7.0.txt
308
312
  - doc/release_notes/3.8.0.txt
309
313
  - doc/release_notes/3.9.0.txt
@@ -320,6 +324,7 @@ files:
320
324
  - lib/roda/plugins/all_verbs.rb
321
325
  - lib/roda/plugins/assets.rb
322
326
  - lib/roda/plugins/assets_preloading.rb
327
+ - lib/roda/plugins/autoload_hash_branches.rb
323
328
  - lib/roda/plugins/backtracking_array.rb
324
329
  - lib/roda/plugins/branch_locals.rb
325
330
  - lib/roda/plugins/caching.rb
@@ -344,6 +349,7 @@ files:
344
349
  - lib/roda/plugins/early_hints.rb
345
350
  - lib/roda/plugins/empty_root.rb
346
351
  - lib/roda/plugins/environments.rb
352
+ - lib/roda/plugins/erb_h.rb
347
353
  - lib/roda/plugins/error_email.rb
348
354
  - lib/roda/plugins/error_handler.rb
349
355
  - lib/roda/plugins/error_mail.rb
@@ -457,7 +463,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
457
463
  - !ruby/object:Gem::Version
458
464
  version: '0'
459
465
  requirements: []
460
- rubygems_version: 3.3.7
466
+ rubygems_version: 3.4.1
461
467
  signing_key:
462
468
  specification_version: 4
463
469
  summary: Routing tree web toolkit