view_component 2.33.0 → 2.34.0

Sign up to get free protection for your applications and to get access to all the features.

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: 3e1d8f453f26f7d62a3549dcfb34a85a6fadfc05a7b38515ebe53bba7500acc9
4
- data.tar.gz: 39122c530de9fb557f7e66a0a3e6b94c20c492776edc45b193e2b3b60b834e39
3
+ metadata.gz: 8ec532b985935e7b718bb74aa51eaaa5e5f26ea0df8936e0c131231c9e9c37ed
4
+ data.tar.gz: c0cde4fa2a1b4d2c0110085b8c3c1b4705117f9ffe20775a096c5c3b20aa0728
5
5
  SHA512:
6
- metadata.gz: 6f016eb4da5b952a220971e0163853b8ca77dd5bc820b634d525316b4117654b78a279ffeb7bb8d66ce68401cc41a350861696152992923445a1c3d6c587b2ed
7
- data.tar.gz: 4203337d6188eea75e7d79ca246ca5309e5af7197256207e48c37b248958dbad49c07efff0a964d206d9c462ee5d1af3365f36f9f2d9e68661f7dbfe066e4a01
6
+ metadata.gz: 37cfdfd8cbf06773a015c13ed6f8c079f9d269045ba8ab1981e56d90cccf841152a8c9ab018b66c5289b8a1bbe5e4c7d1c8a0645e70578b1e97d9da098fe95cd
7
+ data.tar.gz: fe210839c3be3a8eb83e2bac1655f3ab5c5dc8d49727a413ba5ac46eeb0b4bb41e32f18c67b295bfe927cfc207dcc9df7f0c71f6ebc7f6064ea1c7c9fef6ddb7
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  ## main
4
4
 
5
+ ## 2.34.0
6
+
7
+ * Add the ability to enable ActiveSupport notifications (`!render.view_component` event) with `config.view_component.instrumentation_enabled`.
8
+
9
+ *Svyatoslav Kryukov*
10
+
11
+ * Add [Generators](https://viewcomponent.org/guide/generators.html) page to documentation.
12
+
13
+ *Hans Lemuet*
14
+
15
+ * Fix bug where ViewComponents did not work in ActionMailers.
16
+
17
+ *dark-panda*
18
+
5
19
  ## 2.33.0
6
20
 
7
21
  * Add support for `_iteration` parameter when rendering in a collection
@@ -0,0 +1 @@
1
+ <%= render MailerComponent.new %>
@@ -8,6 +8,7 @@ module ViewComponent
8
8
  autoload :Base
9
9
  autoload :Compiler
10
10
  autoload :ComponentError
11
+ autoload :Instrumentation
11
12
  autoload :Preview
12
13
  autoload :PreviewTemplateError
13
14
  autoload :TestHelpers
@@ -136,6 +136,7 @@ module ViewComponent
136
136
  # This prevents an exception when rendering a partial inside of a component that has also been rendered outside
137
137
  # of the component. This is due to the partials compiled template method existing in the parent `view_context`,
138
138
  # and not the component's `view_context`.
139
+ #
139
140
  # @private
140
141
  def render(options = {}, args = {}, &block)
141
142
  if options.is_a? ViewComponent::Base
@@ -162,6 +163,7 @@ module ViewComponent
162
163
  end
163
164
 
164
165
  # Exposes .virtual_path as an instance method
166
+ #
165
167
  # @private
166
168
  def virtual_path
167
169
  self.class.virtual_path
@@ -174,6 +176,7 @@ module ViewComponent
174
176
  end
175
177
 
176
178
  # For caching, such as #cache_if
179
+ #
177
180
  # @private
178
181
  def format
179
182
  # Ruby 2.6 throws a warning without checking `defined?`, 2.7 does not
@@ -183,6 +186,7 @@ module ViewComponent
183
186
  end
184
187
 
185
188
  # Assign the provided content to the content area accessor
189
+ #
186
190
  # @private
187
191
  def with(area, content = nil, &block)
188
192
  unless content_areas.include?(area)
@@ -197,7 +201,10 @@ module ViewComponent
197
201
  nil
198
202
  end
199
203
 
200
- # @private TODO: add documentation
204
+ # Use the provided variant instead of the one determined by the current request.
205
+ #
206
+ # @param variant [Symbol] The variant to be used by the component.
207
+ # @return [self]
201
208
  def with_variant(variant)
202
209
  @variant = variant
203
210
 
@@ -208,7 +215,7 @@ module ViewComponent
208
215
  #
209
216
  # @return [ActionDispatch::Request]
210
217
  def request
211
- @request ||= controller.request
218
+ @request ||= controller.request if controller.respond_to?(:request)
212
219
  end
213
220
 
214
221
  private
@@ -13,6 +13,7 @@ module ViewComponent
13
13
 
14
14
  options.render_monkey_patch_enabled = true if options.render_monkey_patch_enabled.nil?
15
15
  options.show_previews = Rails.env.development? || Rails.env.test? if options.show_previews.nil?
16
+ options.instrumentation_enabled = false if options.instrumentation_enabled.nil?
16
17
  options.preview_route ||= ViewComponent::Base.preview_route
17
18
  options.preview_controller ||= ViewComponent::Base.preview_controller
18
19
 
@@ -30,7 +31,17 @@ module ViewComponent
30
31
  end
31
32
 
32
33
  ActiveSupport.on_load(:view_component) do
33
- options.each { |k, v| send("#{k}=", v) }
34
+ options.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
35
+ end
36
+ end
37
+
38
+ initializer "view_component.enable_instrumentation" do |app|
39
+ ActiveSupport.on_load(:view_component) do
40
+ if app.config.view_component.instrumentation_enabled.present?
41
+ # :nocov:
42
+ ViewComponent::Base.prepend(ViewComponent::Instrumentation)
43
+ # :nocov:
44
+ end
34
45
  end
35
46
  end
36
47
 
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/notifications"
4
+
5
+ module ViewComponent # :nodoc:
6
+ module Instrumentation
7
+ def self.included(mod)
8
+ mod.prepend(self)
9
+ end
10
+
11
+ def render_in(view_context, &block)
12
+ ActiveSupport::Notifications.instrument("!render.view_component", name: self.class.name, identifier: self.class.identifier) do
13
+ super(view_context, &block)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 33
6
+ MINOR = 34
7
7
  PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
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.33.0
4
+ version: 2.34.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: 2021-06-02 00:00:00.000000000 Z
11
+ date: 2021-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -237,6 +237,7 @@ files:
237
237
  - LICENSE.txt
238
238
  - README.md
239
239
  - app/controllers/view_components_controller.rb
240
+ - app/views/test_mailer/test_email.html.erb
240
241
  - app/views/view_components/index.html.erb
241
242
  - app/views/view_components/preview.html.erb
242
243
  - app/views/view_components/previews.html.erb
@@ -262,6 +263,7 @@ files:
262
263
  - lib/view_component/compiler.rb
263
264
  - lib/view_component/component_error.rb
264
265
  - lib/view_component/engine.rb
266
+ - lib/view_component/instrumentation.rb
265
267
  - lib/view_component/preview.rb
266
268
  - lib/view_component/preview_template_error.rb
267
269
  - lib/view_component/previewable.rb