roda 3.63.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: 6e19674abcd02c79572ada44fe13fc8188a4cc91b780a3fbaa39da206cf7457f
4
- data.tar.gz: ffd0e850b4aab5e82b3f5cf307145853df9d420389ff8eb6170ec53d3e29ca57
3
+ metadata.gz: 715e94da6acab0fa1c5e8409051f3faf0800ca56874d8640fa8f00c2ac432322
4
+ data.tar.gz: 79d9f75da1af54c8288918f722dff874433c7935a996180311344a24acc751ec
5
5
  SHA512:
6
- metadata.gz: d91087a996b037de3c0ecc3ca5e029f6b4bb40c5da1618048d70c0aa42ac5dcc581b6ed67e55cd9236da5463c3c224c62b09f85797daeffcb9a8fb98a16bca03
7
- data.tar.gz: 62d2e2fdb0efa867299a764d4f7b36fc1a1e680147d32703d29451e29d2e3090a0f337c2c87ac46929a5a504b6461f92d18b50a14c62f422de4c114e43892c91
6
+ metadata.gz: 507d5395d337ae4e6c13a3ace905a605ecad5690bf8ceabd8d40bf3c9e2b162649a2a6cb79d1422c8c560396f4abdf891d8f3543b9866cd4f20e944acb4b6347
7
+ data.tar.gz: 37cdd77e3b2894ca55370d638e411e3bf10005101d83939a970b242a4750aa2df929994343c20546cdd6046553897e4d7cde19788f10c2406eb5b446d31e97d5
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
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
+
1
9
  = 3.63.0 (2022-12-16)
2
10
 
3
11
  * Make mailer plugin set configured content type for body part for emails with attachments when using mail 2.8+ (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,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.
@@ -13,8 +13,8 @@ class Roda
13
13
  # You can specify a single hash branch for autoloading:
14
14
  #
15
15
  # plugin :autoload_hash_branches
16
- # autoload_hash_branch('branch_name', '/path/to/file')
17
- # autoload_hash_branch('namespace', 'branch_name', '/path/to/file')
16
+ # autoload_hash_branch('branch_name', '/absolute/path/to/file')
17
+ # autoload_hash_branch('namespace', 'branch_name', 'relative/path/to/file')
18
18
  #
19
19
  # You can also set the plugin to autoload load all hash branch files in a given directory.
20
20
  # This will look at each .rb file in the directory, and add an autoload for it, using the
@@ -26,18 +26,24 @@ class Roda
26
26
  # In both cases, when the autoloaded file is required, it should redefine the same
27
27
  # hash branch. If it does not, requests to the hash branch will result in a 404 error.
28
28
  #
29
- # This plugin will not work correctly when freezing applications, because it requires
30
- # modifying the class at runtime as hash branches are autoloaded.
29
+ # When freezing an application, all hash branches are automatically loaded, because
30
+ # autoloading hash branches does not work for frozen applications.
31
31
  module AutoloadHashBranches
32
32
  def self.load_dependencies(app)
33
33
  app.plugin :hash_branches
34
34
  end
35
35
 
36
+ def self.configure(app)
37
+ app.opts[:autoload_hash_branch_files] ||= []
38
+ end
39
+
36
40
  module ClassMethods
37
41
  # Autoload the given file when there is request for the hash branch.
38
42
  # The given file should configure the hash branch specified.
39
43
  def autoload_hash_branch(namespace='', segment, file)
40
44
  segment = "/#{segment}"
45
+ file = File.expand_path(file)
46
+ opts[:autoload_hash_branch_files] << file
41
47
  routes = opts[:hash_branches][namespace] ||= {}
42
48
  meth = routes[segment] = define_roda_method(routes[segment] || "hash_branch_#{namespace}_#{segment}", 1) do |r|
43
49
  loc = method(routes[segment]).source_location
@@ -59,6 +65,12 @@ class Roda
59
65
  end
60
66
  end
61
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
62
74
  end
63
75
  end
64
76
 
@@ -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
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 = 63
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.63.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-12-16 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
@@ -236,6 +236,7 @@ extra_rdoc_files:
236
236
  - doc/release_notes/3.61.0.txt
237
237
  - doc/release_notes/3.62.0.txt
238
238
  - doc/release_notes/3.63.0.txt
239
+ - doc/release_notes/3.64.0.txt
239
240
  - doc/release_notes/3.7.0.txt
240
241
  - doc/release_notes/3.8.0.txt
241
242
  - doc/release_notes/3.9.0.txt
@@ -306,6 +307,7 @@ files:
306
307
  - doc/release_notes/3.61.0.txt
307
308
  - doc/release_notes/3.62.0.txt
308
309
  - doc/release_notes/3.63.0.txt
310
+ - doc/release_notes/3.64.0.txt
309
311
  - doc/release_notes/3.7.0.txt
310
312
  - doc/release_notes/3.8.0.txt
311
313
  - doc/release_notes/3.9.0.txt
@@ -347,6 +349,7 @@ files:
347
349
  - lib/roda/plugins/early_hints.rb
348
350
  - lib/roda/plugins/empty_root.rb
349
351
  - lib/roda/plugins/environments.rb
352
+ - lib/roda/plugins/erb_h.rb
350
353
  - lib/roda/plugins/error_email.rb
351
354
  - lib/roda/plugins/error_handler.rb
352
355
  - lib/roda/plugins/error_mail.rb
@@ -460,7 +463,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
460
463
  - !ruby/object:Gem::Version
461
464
  version: '0'
462
465
  requirements: []
463
- rubygems_version: 3.3.26
466
+ rubygems_version: 3.4.1
464
467
  signing_key:
465
468
  specification_version: 4
466
469
  summary: Routing tree web toolkit