view_component 3.9.0 → 3.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d167b54bcd09ae6e5a8ace98cdb2cfac7386a29029cd8b4b34d1e5aa00093fd
4
- data.tar.gz: 5ea5073913c8c6026dbf5d5e6d04671bc28a42564a9788988dfe0ee18d03af9d
3
+ metadata.gz: d3f4f53b04ea58ed971bef33e1bea8ab65c2564c64a49927ca5db90c118d23bc
4
+ data.tar.gz: 1a6b6024ffd5baf72cb80726b0853cf3fcab80d43505c87648cc57d6726e9185
5
5
  SHA512:
6
- metadata.gz: 2232e4237c3d851577dc10cb9054c03a7614113761e2f6b2b33e3005ad05e665dd1031d29c84f10fcc7bef1a72fa3529866d11082c4ddbc9dd395e415ae5b2b9
7
- data.tar.gz: 67d9aa02848b03e68b5eb56c2bb37d27b39d757d53b4a30b466c9f7e73db29fe5771f2732f6447a135a3d1a120abc387350451b8d875923ce3dae6db06f5ce24
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
- *Reegan Viljoen*
43
+ *Reegan Viljoen*
26
44
 
27
45
  * Allow translations to be inherited and overridden in subclasses.
28
46
 
@@ -104,11 +104,13 @@ module ViewComponent
104
104
  before_render
105
105
 
106
106
  if render?
107
- # Avoid allocating new string when output_postamble is blank
108
- if output_postamble.blank?
109
- safe_render_template_for(@__vc_variant).to_s
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
- safe_render_template_for(@__vc_variant).to_s + safe_output_postamble
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.nil? || text.empty?
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)
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 3
6
- MINOR = 9
6
+ MINOR = 10
7
7
  PATCH = 0
8
8
  PRE = nil
9
9
 
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.9.0
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-04 00:00:00.000000000 Z
11
+ date: 2024-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport