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 +4 -4
- data/lib/roda/plugins/render_each.rb +54 -4
- data/lib/roda/plugins/view_options.rb +6 -1
- data/lib/roda/plugins/view_subdir_leading_slash.rb +49 -0
- data/lib/roda/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 692e6feff78ea9a3c6562026fb6d5ea0e4b1f26cf76d9c283e3482296b4253f0
|
4
|
+
data.tar.gz: 330f62ed0603dea2ef640a424c0d1286a312b90b65ca4087cdd6772f1206c151
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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) &&
|
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
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.
|
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
|