roda 3.91.0 → 3.92.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: e89aa3dd4e7c27d33d8b989c87a661a42e28c771aa8c96109279cc8131a4c5f5
4
- data.tar.gz: e54282de7adf4827dcda2e29c82bbec6d8d76bbbefe29185d3d35b92f3390a50
3
+ metadata.gz: 63e0c8b5dc16e1652a1bbe309c046b681c8f11a90a31c2b2bd8368baa1b85f43
4
+ data.tar.gz: b81857ea9bc5ac7667f19fb730982d7b1259e95e1ff1b049d0c619fddf08a1be
5
5
  SHA512:
6
- metadata.gz: a403baf3ca83c6e636c59c1a598319aa41254ad8bffb6e18ba0f81eebf1260674c30f3954b471da60be605d397496d0c2bb96ff286d5e094ea17a4745dc67f82
7
- data.tar.gz: 2caeb451da13d935c1e14e7009304a16e256942926237704cd80baf32f9fa9d534b58830d8d4092cefec4940cc40fe90e01b33152183d43877900d479135e710
6
+ metadata.gz: ca7712b09048602d91378cdb22ecf30e2d03cf43a215ad52d6aa697151abd88fe4873f4e162b617782f89b434f733d0230f7a3b8bacf252880450dc65308e4ac
7
+ data.tar.gz: 625b03ba51df7bc895b69e09a739584ae5ff6c15f7701e98a5e55fec301ed0e97353f503565811ae335534c1e6e0634916246fae99493851e472148c5c666789
@@ -60,7 +60,7 @@ class Roda
60
60
  # <%= assets(:css, media: 'print') %>
61
61
  #
62
62
  # The assets method will respect the application's +:add_script_name+ option,
63
- # if it set it will automatically prefix the path with the +SCRIPT_NAME+ for
63
+ # if it is set it will automatically prefix the path with the +SCRIPT_NAME+ for
64
64
  # the request.
65
65
  #
66
66
  # == Asset Paths
@@ -0,0 +1,87 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The each_part plugin adds an each_part method, which is a
7
+ # render_each-like method that treats all keywords as locals.
8
+ #
9
+ # # Can replace this:
10
+ # render_each(enum, :template, locals: {foo: 'bar'})
11
+ #
12
+ # # With this:
13
+ # each_part(enum, :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 performance improvement.
22
+ module EachPart
23
+ def self.load_dependencies(app)
24
+ app.plugin :render_each
25
+ end
26
+
27
+ module ClassMethods
28
+ # When freezing, optimize the part method if assuming fixed locals
29
+ # and caching templates.
30
+ def freeze
31
+ if render_opts[:assume_fixed_locals] && !render_opts[:check_template_mtime]
32
+ include AssumeFixedLocalsInstanceMethods
33
+ end
34
+
35
+ super
36
+ end
37
+ end
38
+
39
+ module InstanceMethods
40
+ if RUBY_VERSION >= '2.7'
41
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
42
+ def each_part(enum, template, **locals, &block)
43
+ render_each(enum, template, :locals=>locals, &block)
44
+ end
45
+ RUBY
46
+ # :nocov:
47
+ else
48
+ def each_part(enum, template, locals=OPTS, &block)
49
+ render_each(enum, template, :locals=>locals, &block)
50
+ end
51
+ end
52
+ # :nocov:
53
+ end
54
+
55
+ module AssumeFixedLocalsInstanceMethods
56
+ # :nocov:
57
+ if RUBY_VERSION >= '3.0'
58
+ # :nocov:
59
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
60
+ def each_part(enum, template, **locals, &block)
61
+ if optimized_method = _cached_render_each_template_method(template)
62
+ optimized_method = optimized_method[0]
63
+ as = render_each_default_local(template)
64
+ if defined?(yield)
65
+ enum.each do |v|
66
+ locals[as] = v
67
+ yield send(optimized_method, **locals)
68
+ end
69
+ nil
70
+ else
71
+ enum.map do |v|
72
+ locals[as] = v
73
+ send(optimized_method, **locals)
74
+ end.join
75
+ end
76
+ else
77
+ render_each(enum, template, :locals=>locals, &block)
78
+ end
79
+ end
80
+ RUBY
81
+ end
82
+ end
83
+ end
84
+
85
+ register_plugin(:each_part, EachPart)
86
+ end
87
+ end
@@ -103,7 +103,7 @@ class Roda
103
103
  #
104
104
  # Mailer.sendmail('/welcome/1', 'foo@example.com')
105
105
  #
106
- # r.mail 'welcome' do |user_id, mail_from|
106
+ # r.mail 'welcome', Integer do |user_id, mail_from|
107
107
  # from mail_from
108
108
  # to User[user_id].email
109
109
  # # ...
@@ -91,12 +91,16 @@ class Roda
91
91
 
92
92
  if as
93
93
  opts = opts.dup
94
- if locals = opts[:locals]
95
- locals = opts[:locals] = Hash[locals]
94
+ if locals
95
+ opts[:locals] = locals
96
96
  else
97
- locals = opts[:locals] = {}
97
+ locals = opts[:locals] = if locals = opts[:locals]
98
+ Hash[locals]
99
+ else
100
+ {}
101
+ end
102
+ locals[as] = nil
98
103
  end
99
- locals[as] = nil
100
104
 
101
105
  if (opts.keys - ALLOWED_KEYS).empty? && (optimized_template = _optimized_render_method_for_locals(template, locals))
102
106
  return _optimized_render_each(enum, optimized_template, as, locals, &block)
@@ -134,7 +138,8 @@ class Roda
134
138
  case template
135
139
  when String, Symbol
136
140
  if (method_cache = render_opts[:template_method_cache])
137
- _cached_template_method_lookup(method_cache, [:_render_locals, template, [template.to_sym]])
141
+ key = render_opts[:assume_fixed_locals] ? template : [:_render_locals, template, [template.to_sym]]
142
+ _cached_template_method_lookup(method_cache, key)
138
143
  end
139
144
  else
140
145
  false
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 = 91
7
+ RodaMinorVersion = 92
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.91.0
4
+ version: 3.92.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-11 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rack
@@ -200,6 +200,7 @@ files:
200
200
  - lib/roda/plugins/direct_call.rb
201
201
  - lib/roda/plugins/disallow_file_uploads.rb
202
202
  - lib/roda/plugins/drop_body.rb
203
+ - lib/roda/plugins/each_part.rb
203
204
  - lib/roda/plugins/early_hints.rb
204
205
  - lib/roda/plugins/empty_root.rb
205
206
  - lib/roda/plugins/environments.rb
@@ -326,7 +327,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
326
327
  - !ruby/object:Gem::Version
327
328
  version: '0'
328
329
  requirements: []
329
- rubygems_version: 3.6.2
330
+ rubygems_version: 3.6.7
330
331
  specification_version: 4
331
332
  summary: Routing tree web toolkit
332
333
  test_files: []