view_component 2.31.2 → 2.32.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.

Potentially problematic release.


This version of view_component might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aed268c7e5731efdfba6e0d5764f04bcca9e456329afa15f31ebe7198c6bc79e
4
- data.tar.gz: bc455dc076927f9a374788cd4a043df0a8905f9e6b64f5475fa9b7f1b1f38cc3
3
+ metadata.gz: 0cdb5a57cbe401fab359e9daedfcb0180b2e6ec07bd332e7616c6a611442df13
4
+ data.tar.gz: 11ec2515ac60b615adc2a52cc7b526c7632871363a24a7b3128ca9a4873d57a1
5
5
  SHA512:
6
- metadata.gz: 455f1f06841908fe6239c93d9f4e2f99aa42e2bba64a6293bd4f2d5e8823225322566962c35ca46c0788bbfa085096ab15ede650e229759a05aa0c2f0f6b5e5c
7
- data.tar.gz: b2fde290f722b87ca420bfd2f722184e4f3d79a987bb3ea93c29ae8f7c587a090276e9cdcf94e7434147b6ff02b8fb8492db86945c107c9e328b1c3ab4798786
6
+ metadata.gz: ba44487de1f76102ec0fa9ea4fdd4af85c079c665c0e879855af5fe57577878a176badfef0af2a3d06d3384e852986048ab1332ed0a78fc589adea83f087b037
7
+ data.tar.gz: 32b565ca3c4759b366acf47de7f42a74ec52adb96d951013759cb5a289ffc16956b432bbee8e0dd79c3291c16386655fd7b8332da2ad3ba29db9dadcc87456a9
data/CHANGELOG.md CHANGED
@@ -2,11 +2,31 @@
2
2
 
3
3
  ## main
4
4
 
5
- ## 2.31.2
5
+ ## 2.32.0
6
6
 
7
- * Patch XSS vulnerability in `Translatable` module caused by improperly escaped interpolation arguments.
7
+ * Enable previews by default in test environment.
8
8
 
9
- *Cameron Dutro*
9
+ *Edouard Piron*
10
+
11
+ * Fix test helper compatibility with Rails 7.0, TestRequest, and TestSession.
12
+
13
+ *Leo Correa*
14
+
15
+ * Add experimental `_output_postamble` lifecyle method.
16
+
17
+ *Joel Hawksley*
18
+
19
+ * Add compatibility notes on FAQ.
20
+
21
+ *Matheus Richard*
22
+
23
+ * Add Bridgetown on Compatibility documentation.
24
+
25
+ *Matheus Richard*
26
+
27
+ * Are you interested in building the future of ViewComponent? GitHub is looking to hire a Senior Engineer to work on Primer ViewComponents and ViewComponent. Apply here: [US/Canada](https://github.com/careers) / [Europe](https://boards.greenhouse.io/github/jobs/3132294). Feel free to reach out to joelhawksley@github.com with any questions.
28
+
29
+ *Joel Hawksley*
10
30
 
11
31
  ## 2.31.1
12
32
 
@@ -16,6 +36,8 @@
16
36
 
17
37
  ## 2.31.0
18
38
 
39
+ _Note: This release includes an underlying change to Slots that may affect incorrect usage of the API, where Slots were set on a line prefixed by `<%=`. The result of setting a Slot should not be returned. (`<%`)_
40
+
19
41
  * Add `#with_content` to allow setting content without a block.
20
42
 
21
43
  *Jordan Raine, Manuel Puyol*
@@ -30,6 +30,7 @@ module ViewComponent
30
30
  # Hook for allowing components to do work as part of the compilation process.
31
31
  #
32
32
  # For example, one might compile component-specific assets at this point.
33
+ # @private TODO: add documentation
33
34
  def self._after_compile
34
35
  # noop
35
36
  end
@@ -58,6 +59,7 @@ module ViewComponent
58
59
  # returns:
59
60
  # <span title="greeting">Hello, world!</span>
60
61
  #
62
+ # @private
61
63
  def render_in(view_context, &block)
62
64
  self.class.compile(raise_errors: true)
63
65
 
@@ -89,7 +91,7 @@ module ViewComponent
89
91
  before_render
90
92
 
91
93
  if render?
92
- render_template_for(@variant)
94
+ render_template_for(@variant) + _output_postamble
93
95
  else
94
96
  ""
95
97
  end
@@ -97,18 +99,36 @@ module ViewComponent
97
99
  @current_template = old_current_template
98
100
  end
99
101
 
102
+ # EXPERIMENTAL: Optional content to be returned after the rendered template.
103
+ #
104
+ # @return [String]
105
+ def _output_postamble
106
+ ""
107
+ end
108
+
109
+ # Called before rendering the component. Override to perform operations that depend on having access to the view context, such as helpers.
110
+ #
111
+ # @return [void]
100
112
  def before_render
101
113
  before_render_check
102
114
  end
103
115
 
116
+ # Called after rendering the component.
117
+ #
118
+ # @deprecated Use `before_render` instead. Will be removed in v3.0.0.
119
+ # @return [void]
104
120
  def before_render_check
105
121
  # noop
106
122
  end
107
123
 
124
+ # Override to determine whether the ViewComponent should render.
125
+ #
126
+ # @return [Boolean]
108
127
  def render?
109
128
  true
110
129
  end
111
130
 
131
+ # @private
112
132
  def initialize(*); end
113
133
 
114
134
  # Re-use original view_context if we're not rendering a component.
@@ -116,6 +136,7 @@ module ViewComponent
116
136
  # This prevents an exception when rendering a partial inside of a component that has also been rendered outside
117
137
  # of the component. This is due to the partials compiled template method existing in the parent `view_context`,
118
138
  # and not the component's `view_context`.
139
+ # @private
119
140
  def render(options = {}, args = {}, &block)
120
141
  if options.is_a? ViewComponent::Base
121
142
  super
@@ -124,28 +145,36 @@ module ViewComponent
124
145
  end
125
146
  end
126
147
 
148
+ # The current controller. Use sparingly as doing so introduces coupling that inhibits encapsulation & reuse, often making testing difficult.
149
+ #
150
+ # @return [ActionController::Base]
127
151
  def controller
128
152
  raise ViewContextCalledBeforeRenderError, "`controller` can only be called at render time." if view_context.nil?
129
153
  @controller ||= view_context.controller
130
154
  end
131
155
 
132
- # Provides a proxy to access helper methods from the context of the current controller
156
+ # A proxy through which to access helpers. Use sparingly as doing so introduces coupling that inhibits encapsulation & reuse, often making testing difficult.
157
+ #
158
+ # @return [ActionView::Base]
133
159
  def helpers
134
160
  raise ViewContextCalledBeforeRenderError, "`helpers` can only be called at render time." if view_context.nil?
135
161
  @helpers ||= controller.view_context
136
162
  end
137
163
 
138
164
  # Exposes .virtual_path as an instance method
165
+ # @private
139
166
  def virtual_path
140
167
  self.class.virtual_path
141
168
  end
142
169
 
143
170
  # For caching, such as #cache_if
171
+ # @private
144
172
  def view_cache_dependencies
145
173
  []
146
174
  end
147
175
 
148
176
  # For caching, such as #cache_if
177
+ # @private
149
178
  def format
150
179
  # Ruby 2.6 throws a warning without checking `defined?`, 2.7 does not
151
180
  if defined?(@variant)
@@ -154,6 +183,7 @@ module ViewComponent
154
183
  end
155
184
 
156
185
  # Assign the provided content to the content area accessor
186
+ # @private
157
187
  def with(area, content = nil, &block)
158
188
  unless content_areas.include?(area)
159
189
  raise ArgumentError.new "Unknown content_area '#{area}' - expected one of '#{content_areas}'"
@@ -167,15 +197,16 @@ module ViewComponent
167
197
  nil
168
198
  end
169
199
 
200
+ # @private TODO: add documentation
170
201
  def with_variant(variant)
171
202
  @variant = variant
172
203
 
173
204
  self
174
205
  end
175
206
 
176
- # Exposes the current request to the component.
177
- # Use sparingly as doing so introduces coupling
178
- # that inhibits encapsulation & reuse.
207
+ # The current request. Use sparingly as doing so introduces coupling that inhibits encapsulation & reuse, often making testing difficult.
208
+ #
209
+ # @return [ActionDispatch::Request]
179
210
  def request
180
211
  @request ||= controller.request
181
212
  end
@@ -12,7 +12,7 @@ module ViewComponent
12
12
  options = app.config.view_component
13
13
 
14
14
  options.render_monkey_patch_enabled = true if options.render_monkey_patch_enabled.nil?
15
- options.show_previews = Rails.env.development? if options.show_previews.nil?
15
+ options.show_previews = Rails.env.development? || Rails.env.test? if options.show_previews.nil?
16
16
  options.preview_route ||= ViewComponent::Base.preview_route
17
17
  options.preview_controller ||= ViewComponent::Base.preview_controller
18
18
 
@@ -60,7 +60,7 @@ module ViewComponent
60
60
  # helper method with the same name as the slot.
61
61
  #
62
62
  # <%= render_inline(MyComponent.new) do |component| %>
63
- # <%= component.header(classes: "Foo") do %>
63
+ # <% component.header(classes: "Foo") do %>
64
64
  # <p>Bar</p>
65
65
  # <% end %>
66
66
  # <% end %>
@@ -95,7 +95,7 @@ module ViewComponent
95
95
  # helper method with the same name as the slot.
96
96
  #
97
97
  # <h1>
98
- # <%= items.each do |item| %>
98
+ # <% items.each do |item| %>
99
99
  # <%= item %>
100
100
  # <% end %>
101
101
  # </h1>
@@ -107,11 +107,11 @@ module ViewComponent
107
107
  # called multiple times to append to the slot.
108
108
  #
109
109
  # <%= render_inline(MyComponent.new) do |component| %>
110
- # <%= component.item(name: "Foo") do %>
110
+ # <% component.item(name: "Foo") do %>
111
111
  # <p>One</p>
112
112
  # <% end %>
113
113
  #
114
- # <%= component.item(name: "Bar") do %>
114
+ # <% component.item(name: "Bar") do %>
115
115
  # <p>two</p>
116
116
  # <% end %>
117
117
  # <% end %>
@@ -39,7 +39,12 @@ module ViewComponent
39
39
  end
40
40
 
41
41
  def request
42
- @request ||= ActionDispatch::TestRequest.create
42
+ @request ||=
43
+ begin
44
+ request = ActionDispatch::TestRequest.create
45
+ request.session = ActionController::TestSession.new
46
+ request
47
+ end
43
48
  end
44
49
 
45
50
  def with_variant(variant)
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "erb"
4
3
  require "set"
5
4
  require "i18n"
6
5
  require "action_view/helpers/translation_helper"
@@ -71,10 +70,6 @@ module ViewComponent
71
70
  key = key&.to_s unless key.is_a?(String)
72
71
  key = "#{i18n_scope}#{key}" if key.start_with?(".")
73
72
 
74
- if HTML_SAFE_TRANSLATION_KEY.match?(key)
75
- html_escape_translation_options!(options)
76
- end
77
-
78
73
  translated = catch(:exception) do
79
74
  i18n_backend.translate(locale, key, options)
80
75
  end
@@ -96,19 +91,5 @@ module ViewComponent
96
91
  def i18n_scope
97
92
  self.class.i18n_scope
98
93
  end
99
-
100
- private
101
-
102
- def html_escape_translation_options!(options)
103
- options.each do |name, value|
104
- unless i18n_option?(name) || (name == :count && value.is_a?(Numeric))
105
- options[name] = ERB::Util.html_escape(value.to_s)
106
- end
107
- end
108
- end
109
-
110
- def i18n_option?(name)
111
- (@i18n_option_names ||= I18n::RESERVED_KEYS.to_set).include?(name)
112
- end
113
94
  end
114
95
  end
@@ -3,8 +3,8 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 31
7
- PATCH = 2
6
+ MINOR = 32
7
+ PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  end
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: 2.31.2
4
+ version: 2.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-02 00:00:00.000000000 Z
11
+ date: 2021-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -212,6 +212,20 @@ dependencies:
212
212
  - - "~>"
213
213
  - !ruby/object:Gem::Version
214
214
  version: '0.13'
215
+ - !ruby/object:Gem::Dependency
216
+ name: yard
217
+ requirement: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - "~>"
220
+ - !ruby/object:Gem::Version
221
+ version: 0.9.25
222
+ type: :development
223
+ prerelease: false
224
+ version_requirements: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - "~>"
227
+ - !ruby/object:Gem::Version
228
+ version: 0.9.25
215
229
  description:
216
230
  email:
217
231
  - opensource+view_component@github.com
@@ -287,7 +301,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
287
301
  - !ruby/object:Gem::Version
288
302
  version: '0'
289
303
  requirements: []
290
- rubygems_version: 3.2.22
304
+ rubygems_version: 3.2.3
291
305
  signing_key:
292
306
  specification_version: 4
293
307
  summary: View components for Rails