roda 3.93.0 → 3.94.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: d1e04d3df576ad873687f27895cf5100f34a6142ee2204d4e74372d8da03ffe0
4
- data.tar.gz: 6b4f577746d682fc763c765d6d9f787a251db3c392072d1fa123fe5bddab7e20
3
+ metadata.gz: 692e6feff78ea9a3c6562026fb6d5ea0e4b1f26cf76d9c283e3482296b4253f0
4
+ data.tar.gz: 330f62ed0603dea2ef640a424c0d1286a312b90b65ca4087cdd6772f1206c151
5
5
  SHA512:
6
- metadata.gz: 845525a607910671a61b61645ecfa7243ab8565963169aff78e7908cd5a982c8cbd5f8420e9e53e6689488be5fa57bfba9fc7da714d5e892f79f205c0a895ccf
7
- data.tar.gz: 37fe2d01f609363e382b0fffe45b2dc13c5c04d0467890db334417a44d42b8a906a3d95f0ec68e465b17b0c8c54667cd7ef93fe866e0ef48d0afdbf5916c5aaa
6
+ metadata.gz: b87645bffa98a056fed1fc31b032a58be23a99ef202d4f91bb9f9d10f1d62e73ebe4ae4a5008fbe978d7abdb1768b22010cf61ab1d37b677718db9477d891842
7
+ data.tar.gz: f2572f750dfcf59d1d563983c32d53246f5260d94124336332a8ae6c696f1ff4b18b269043e41105e10462ed4c5d4d1e66039291c60a80303b4a0a94fe602c0d
@@ -70,6 +70,35 @@ class Roda
70
70
 
71
71
  ALLOWED_KEYS = [:locals, :local].freeze
72
72
 
73
+ if Render::COMPILED_METHOD_SUPPORT
74
+ module ClassMethods
75
+ # If using compiled methods and assuming fixed locals, optimize
76
+ # _cached_render_each_template_method.
77
+ def freeze
78
+ if render_opts[:assume_fixed_locals] && !render_opts[:check_template_mtime]
79
+ include AssumeFixedLocalsInstanceMethods
80
+ end
81
+
82
+ super
83
+ end
84
+ end
85
+
86
+ module AssumeFixedLocalsInstanceMethods
87
+ private
88
+
89
+ # Optimize method since this module is only loaded when using fixed locals
90
+ # and when caching templates.
91
+ def _cached_render_each_template_method(template)
92
+ case template
93
+ when String, Symbol
94
+ _cached_template_method_lookup(render_opts[:template_method_cache], template)
95
+ else
96
+ false
97
+ end
98
+ end
99
+ end
100
+ end
101
+
73
102
  module InstanceMethods
74
103
  # For each value in enum, render the given template using the
75
104
  # given opts. The template and options hash are passed to +render+.
@@ -123,10 +152,31 @@ class Roda
123
152
 
124
153
  private
125
154
 
126
- # The default local variable name to use for the template, if the :local option
127
- # is not used when calling render_each.
128
- def render_each_default_local(template)
129
- File.basename(template.to_s).sub(/\..+\z/, '').to_sym
155
+ if File.basename("a/b") == "b" && File.basename("a\\b") == "a\\b" && RUBY_VERSION >= '3'
156
+ # The default local variable name to use for the template, if the :local option
157
+ # is not used when calling render_each.
158
+ def render_each_default_local(template)
159
+ # Optimize to avoid allocations when possible
160
+ template = case template
161
+ when Symbol
162
+ s = template.name
163
+ return template unless s.include?("/") || s.include?(".")
164
+ s
165
+ when String
166
+ return template.to_sym unless template.include?("/") || template.include?(".")
167
+ template
168
+ else
169
+ template.to_s
170
+ end
171
+
172
+ File.basename(template).sub(/\..+\z/, '').to_sym
173
+ end
174
+ # :nocov:
175
+ else
176
+ def render_each_default_local(template)
177
+ File.basename(template.to_s).sub(/\..+\z/, '').to_sym
178
+ end
179
+ # :nocov:
130
180
  end
131
181
 
132
182
  if Render::COMPILED_METHOD_SUPPORT
@@ -182,12 +182,17 @@ class Roda
182
182
  # contain a slash.
183
183
  def template_name(opts)
184
184
  name = super
185
- if (v = @_view_subdir) && !name.include?('/')
185
+ if (v = @_view_subdir) && use_view_subdir_for_template_name?(name)
186
186
  "#{v}/#{name}"
187
187
  else
188
188
  name
189
189
  end
190
190
  end
191
+
192
+ # Whether to use a view subdir for the template name.
193
+ def use_view_subdir_for_template_name?(name)
194
+ !name.include?('/')
195
+ end
191
196
  end
192
197
  end
193
198
 
@@ -0,0 +1,49 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The view_subdir_leading_slash plugin builds on the view_options
7
+ # plugin, and changes the behavior so that if a view subdir is set,
8
+ # it is used for all templates, unless the template starts with a
9
+ # leading slash:
10
+ #
11
+ # plugin :view_subdir_leading_slash
12
+ #
13
+ # route do |r|
14
+ # r.on "users" do
15
+ # set_view_subdir 'users'
16
+ #
17
+ # r.get 'list' do
18
+ # view 'lists/users' # uses ./views/users/lists/users.erb
19
+ # end
20
+ #
21
+ # r.get 'list' do
22
+ # view '/lists/users' # uses ./views//lists/users.erb
23
+ # end
24
+ # end
25
+ # end
26
+ #
27
+ # The default for the view_options plugin is to not use a
28
+ # view subdir if the template name contains a slash at all.
29
+ module ViewSubdirLeadingSlash
30
+ # Load the view_options plugin before this plugin, since this plugin
31
+ # works by overriding a method in the view_options plugin.
32
+ def self.load_dependencies(app)
33
+ app.plugin :view_options
34
+ end
35
+
36
+ module InstanceMethods
37
+ private
38
+
39
+ # Use a view subdir unless the template starts with a slash.
40
+ def use_view_subdir_for_template_name?(name)
41
+ !name.start_with?('/')
42
+ end
43
+ end
44
+ end
45
+
46
+ register_plugin(:view_subdir_leading_slash, ViewSubdirLeadingSlash)
47
+ end
48
+ end
49
+
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 = 93
7
+ RodaMinorVersion = 94
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.93.0
4
+ version: 3.94.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
@@ -300,6 +300,7 @@ files:
300
300
  - lib/roda/plugins/typecast_params_sized_integers.rb
301
301
  - lib/roda/plugins/unescape_path.rb
302
302
  - lib/roda/plugins/view_options.rb
303
+ - lib/roda/plugins/view_subdir_leading_slash.rb
303
304
  - lib/roda/request.rb
304
305
  - lib/roda/response.rb
305
306
  - lib/roda/session_middleware.rb