view_component 3.9.0 → 3.10.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/docs/CHANGELOG.md +19 -1
- data/lib/view_component/base.rb +20 -5
- data/lib/view_component/test_helpers.rb +3 -0
- data/lib/view_component/translatable.rb +1 -2
- data/lib/view_component/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3f4f53b04ea58ed971bef33e1bea8ab65c2564c64a49927ca5db90c118d23bc
|
4
|
+
data.tar.gz: 1a6b6024ffd5baf72cb80726b0853cf3fcab80d43505c87648cc57d6726e9185
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f75de114591fca8e662e6fa15086c0b6b11c5862a05e68abff123ba19b7b23b7f67e7b65f8adca8a78688011254117643e9f0e76b92e5a0c0c51d82ecb85194
|
7
|
+
data.tar.gz: 9771fc3c30b8472bb2f0793573926cd7b05e8f991091af18f8e51cfd5370ea8ac7f1eff40488eb0e1434a81683e901fcd74659763620f2e5ae8a26d4db0c943b
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,6 +10,24 @@ nav_order: 5
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## 3.10.0
|
14
|
+
|
15
|
+
* Fix html escaping in `#call` for non-strings.
|
16
|
+
|
17
|
+
*Reegan Viljoen, Cameron Dutro*
|
18
|
+
|
19
|
+
* Add `output_preamble` to match `output_postamble`, using the same safety checks.
|
20
|
+
|
21
|
+
*Kali Donovan, Michael Daross*
|
22
|
+
|
23
|
+
* Exclude html escaping of I18n reserved keys with `I18n::RESERVED_KEYS` rather than `I18n.reserved_keys_pattern`.
|
24
|
+
|
25
|
+
*Nick Coyne*
|
26
|
+
|
27
|
+
* Update CI configuration to use `Appraisal`.
|
28
|
+
|
29
|
+
*Hans Lemuet, Simon Fish*
|
30
|
+
|
13
31
|
## 3.9.0
|
14
32
|
|
15
33
|
* Don’t break `rails stats` if ViewComponent path is missing.
|
@@ -22,7 +40,7 @@ nav_order: 5
|
|
22
40
|
|
23
41
|
* Add support for Ruby 3.3.
|
24
42
|
|
25
|
-
|
43
|
+
*Reegan Viljoen*
|
26
44
|
|
27
45
|
* Allow translations to be inherited and overridden in subclasses.
|
28
46
|
|
data/lib/view_component/base.rb
CHANGED
@@ -104,11 +104,13 @@ module ViewComponent
|
|
104
104
|
before_render
|
105
105
|
|
106
106
|
if render?
|
107
|
-
# Avoid allocating new string when output_postamble
|
108
|
-
|
109
|
-
|
107
|
+
# Avoid allocating new string when output_preamble and output_postamble are blank
|
108
|
+
rendered_template = safe_render_template_for(@__vc_variant).to_s
|
109
|
+
|
110
|
+
if output_preamble.blank? && output_postamble.blank?
|
111
|
+
rendered_template
|
110
112
|
else
|
111
|
-
|
113
|
+
safe_output_preamble + rendered_template + safe_output_postamble
|
112
114
|
end
|
113
115
|
else
|
114
116
|
""
|
@@ -156,6 +158,13 @@ module ViewComponent
|
|
156
158
|
end
|
157
159
|
end
|
158
160
|
|
161
|
+
# Optional content to be returned before the rendered template.
|
162
|
+
#
|
163
|
+
# @return [String]
|
164
|
+
def output_preamble
|
165
|
+
@@default_output_preamble ||= "".html_safe
|
166
|
+
end
|
167
|
+
|
159
168
|
# Optional content to be returned after the rendered template.
|
160
169
|
#
|
161
170
|
# @return [String]
|
@@ -309,7 +318,7 @@ module ViewComponent
|
|
309
318
|
|
310
319
|
def maybe_escape_html(text)
|
311
320
|
return text if request && !request.format.html?
|
312
|
-
return text if text.
|
321
|
+
return text if text.blank?
|
313
322
|
|
314
323
|
if text.html_safe?
|
315
324
|
text
|
@@ -329,6 +338,12 @@ module ViewComponent
|
|
329
338
|
end
|
330
339
|
end
|
331
340
|
|
341
|
+
def safe_output_preamble
|
342
|
+
maybe_escape_html(output_preamble) do
|
343
|
+
Kernel.warn("WARNING: The #{self.class} component was provided an HTML-unsafe preamble. The preamble will be automatically escaped, but you may want to investigate.")
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
332
347
|
def safe_output_postamble
|
333
348
|
maybe_escape_html(output_postamble) do
|
334
349
|
Kernel.warn("WARNING: The #{self.class} component was provided an HTML-unsafe postamble. The postamble will be automatically escaped, but you may want to investigate.")
|
@@ -255,9 +255,11 @@ module ViewComponent
|
|
255
255
|
|
256
256
|
def __vc_test_helpers_preview_class
|
257
257
|
result = if respond_to?(:described_class)
|
258
|
+
# :nocov:
|
258
259
|
raise "`render_preview` expected a described_class, but it is nil." if described_class.nil?
|
259
260
|
|
260
261
|
"#{described_class}Preview"
|
262
|
+
# :nocov:
|
261
263
|
else
|
262
264
|
self.class.name.gsub("Test", "Preview")
|
263
265
|
end
|
@@ -265,5 +267,6 @@ module ViewComponent
|
|
265
267
|
rescue NameError
|
266
268
|
raise NameError, "`render_preview` expected to find #{result}, but it does not exist."
|
267
269
|
end
|
270
|
+
# :nocov:
|
268
271
|
end
|
269
272
|
end
|
@@ -138,8 +138,7 @@ module ViewComponent
|
|
138
138
|
end
|
139
139
|
|
140
140
|
def html_escape_translation_options!(options)
|
141
|
-
options.each do |name, value|
|
142
|
-
next if ::I18n.reserved_keys_pattern.match?(name)
|
141
|
+
options.except(*::I18n::RESERVED_KEYS).each do |name, value|
|
143
142
|
next if name == :count && value.is_a?(Numeric)
|
144
143
|
|
145
144
|
options[name] = ERB::Util.html_escape(value.to_s)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ViewComponent Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|