view_component 4.9.0 → 4.11.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd12f6e6a2acbb991781956cb7677076cc652b7f90519649d6d5503073feb364
4
- data.tar.gz: bd5b8a5ef52c8f88c718c534f75626a208cba7a77f2bbced2cf22fcde70a226d
3
+ metadata.gz: 13c7279c5aed2ac93503d70cfddae8b183b91c8a4ca0770a237d0b5aa081036c
4
+ data.tar.gz: 5fd930eb6b28a01da1152fd7d4a09e8019de0902f0508e4ea6aa0f23d6c584bd
5
5
  SHA512:
6
- metadata.gz: d580739f741633eb2db4f16a45a21ad0b23118021383395fb4435ff63a381b2fb08b800a1acb2b997f7d6e7f6d28f654e55d6a14cd261944b8820787b988751c
7
- data.tar.gz: 40592ea9f341b2cd8c11971028825e6456bf5092799f69d7cfc753443c5c6672208c102522c3ec47cfbbdf282049251800f14a8dfc6a7895c3c4e8a4b275be75
6
+ metadata.gz: d691402cf227340f287c804e6a0ce639928ca2d409dd745701eae63dba20abdae2d3b876fb6d2c81d8b63f3a4ba9b0af7aa4268da5faf37c2fff5f3f7aa9b7ee
7
+ data.tar.gz: f9a554a6d53d75875c9863a1dedba3e6a51efd134e35dd43f5eb2883e446d5cab2ecba06f9a1fddd7e81d8e046aa5d0383585d9563f12897b4530606e225906c
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "view_component/errors"
4
+
3
5
  class ViewComponentsSystemTestController < ActionController::Base # :nodoc:
4
6
  if Rails.env.test?
5
7
  before_action :validate_file_path
data/docs/CHANGELOG.md CHANGED
@@ -10,6 +10,26 @@ nav_order: 6
10
10
 
11
11
  ## main
12
12
 
13
+ ## 4.11.0
14
+
15
+ * Update `render_in` signature to accept `**_` for compatibility with Rails [#50623](https://github.com/rails/rails/pull/50623).
16
+
17
+ *Joel Hawksley*
18
+
19
+ * Fix translation scope resolution in nested lambda-backed slots. Relative `t(".key")` calls inside lambda-backed slots were resolving against an intermediate component's scope instead of the original partial's scope where the block was defined.
20
+
21
+ *Artin Boghosian*
22
+
23
+ ## 4.10.0
24
+
25
+ * Fix `NameError: uninitialized constant ViewComponent::SystemTestControllerNefariousPathError` when booting in the test environment with `eager_load = true`.
26
+
27
+ *Joel Hawksley*
28
+
29
+ * Fix yielded content rendered at wrong location when using form helpers.
30
+
31
+ *Joel Hawksley*, *Markus*
32
+
13
33
  ## 4.9.0
14
34
 
15
35
  * Fix path traversal vulnerability in `ViewComponentsSystemTestController` where sibling directories sharing a string prefix with the allowed temp directory could bypass the path containment check. The `start_with?` check has been replaced with a separator-aware prefix check, and nefarious path errors now return a 404 instead of an unhandled exception.
@@ -82,6 +82,7 @@ module ViewComponent
82
82
  # so helpers, etc work as expected.
83
83
  #
84
84
  # @param view_context [ActionView::Base] The original view context.
85
+ #
85
86
  # @return [void]
86
87
  def set_original_view_context(view_context)
87
88
  # noop
@@ -102,7 +103,7 @@ module ViewComponent
102
103
  # Returns HTML that has been escaped by the respective template handler.
103
104
  #
104
105
  # @return [String]
105
- def render_in(view_context, &block)
106
+ def render_in(view_context, **_, &block)
106
107
  self.class.__vc_compile(raise_errors: true)
107
108
 
108
109
  @view_context = view_context
@@ -278,6 +279,22 @@ module ViewComponent
278
279
  end
279
280
  end
280
281
 
282
+ # Sync @output_buffer with the view context's current output buffer before
283
+ # capturing. Form helpers create builders with @template_object pointing to
284
+ # the component. When those builders later call capture inside a partial
285
+ # (whose _run allocated a fresh OutputBuffer on the view context), the
286
+ # component's stale @output_buffer would capture from the wrong buffer.
287
+ # Temporarily switching to the view context's buffer keeps both in sync.
288
+ #
289
+ # @private
290
+ def capture(...)
291
+ old_output_buffer = @output_buffer
292
+ @output_buffer = view_context.output_buffer if view_context
293
+ super
294
+ ensure
295
+ @output_buffer = old_output_buffer
296
+ end
297
+
281
298
  # The current controller. Use sparingly as doing so introduces coupling
282
299
  # that inhibits encapsulation & reuse, often making testing difficult.
283
300
  #
@@ -10,7 +10,7 @@ module ViewComponent
10
10
 
11
11
  delegate :size, to: :@collection
12
12
 
13
- def render_in(view_context, &block)
13
+ def render_in(view_context, **_, &block)
14
14
  components.map do |component|
15
15
  component.render_in(view_context, &block)
16
16
  end.join(rendered_spacer(view_context)).html_safe
@@ -58,6 +58,7 @@ module ViewComponent
58
58
  end
59
59
 
60
60
  # @param requested_details [ActionView::TemplateDetails::Requested] i.e. locales, formats, variants
61
+ #
61
62
  # @return all matching compiled templates, in priority order based on the requested details from LookupContext
62
63
  def find_templates_for(requested_details)
63
64
  filtered_templates = @templates.select do |template|
@@ -19,6 +19,7 @@ module ViewComponent
19
19
  end
20
20
 
21
21
  # @!attribute generate
22
+ #
22
23
  # @return [ActiveSupport::OrderedOptions]
23
24
  # The subset of configuration options relating to generators.
24
25
  #
@@ -95,6 +96,7 @@ module ViewComponent
95
96
  # in `spec/views/components/` rather than the default `spec/components/`.
96
97
 
97
98
  # @!attribute previews
99
+ #
98
100
  # @return [ActiveSupport::OrderedOptions]
99
101
  # The subset of configuration options relating to previews.
100
102
  #
@@ -124,6 +126,7 @@ module ViewComponent
124
126
  #
125
127
 
126
128
  # @!attribute instrumentation_enabled
129
+ #
127
130
  # @return [Boolean]
128
131
  # Whether ActiveSupport notifications are enabled.
129
132
  # Defaults to `false`.
@@ -171,6 +174,7 @@ module ViewComponent
171
174
  end
172
175
 
173
176
  # @!attribute current
177
+ #
174
178
  # @return [ViewComponent::Config]
175
179
  # Returns the current ViewComponent::Config. This is persisted against this
176
180
  # class so that config options remain accessible before the rest of
@@ -8,7 +8,7 @@ module ViewComponent # :nodoc:
8
8
  mod.prepend(self) unless self <= ViewComponent::Instrumentation
9
9
  end
10
10
 
11
- def render_in(view_context, &block)
11
+ def render_in(view_context, **_, &block)
12
12
  return super if !Rails.application.config.view_component.instrumentation_enabled.present?
13
13
 
14
14
  payload = {
@@ -380,6 +380,7 @@ module ViewComponent
380
380
  def __vc_set_slot(slot_name, slot_definition = nil, *args, **kwargs, &block)
381
381
  slot_definition ||= self.class.registered_slots[slot_name]
382
382
  slot = Slot.new(self)
383
+ captured_block_virtual_path = nil
383
384
 
384
385
  # Passing the block to the sub-component wrapper like this has two
385
386
  # benefits:
@@ -394,7 +395,8 @@ module ViewComponent
394
395
  slot.__vc_content_block = block
395
396
  # Capture the virtual path at the time the block is defined, so that
396
397
  # translations resolve relative to where the block was created, not where it's rendered
397
- slot.__vc_content_block_virtual_path = view_context.instance_variable_get(:@virtual_path)
398
+ captured_block_virtual_path = view_context.instance_variable_get(:@virtual_path)
399
+ slot.__vc_content_block_virtual_path = captured_block_virtual_path
398
400
  end
399
401
 
400
402
  # If class
@@ -413,7 +415,7 @@ module ViewComponent
413
415
  renderable_value =
414
416
  if block
415
417
  renderable_function.call(*args, **kwargs) do |*rargs|
416
- with_captured_virtual_path(@old_virtual_path) do
418
+ with_captured_virtual_path(captured_block_virtual_path) do
417
419
  view_context.capture(*rargs, &block)
418
420
  end
419
421
  end
@@ -7,6 +7,7 @@ module ViewComponent
7
7
  # Returns a block that can be used to visit the path of the inline rendered component.
8
8
  # @param fragment [Nokogiri::Fragment] The fragment returned from `render_inline`.
9
9
  # @param layout [String] The (optional) layout to use.
10
+ #
10
11
  # @return [Proc] A block that can be used to visit the path of the inline rendered component.
11
12
  def with_rendered_component_path(fragment, layout: false, &block)
12
13
  file = Tempfile.new(
@@ -35,6 +35,7 @@ module ViewComponent
35
35
  # ```
36
36
  #
37
37
  # @param component [ViewComponent::Base, ViewComponent::Collection] The instance of the component to be rendered.
38
+ #
38
39
  # @return [Nokogiri::HTML5]
39
40
  def render_inline(component, **args, &block)
40
41
  @page = nil
@@ -74,7 +75,9 @@ module ViewComponent
74
75
  # @param name [String] The name of the preview to be rendered.
75
76
  # @param from [ViewComponent::Preview] The class of the preview to be rendered.
76
77
  # @param params [Hash] Parameters to be passed to the preview.
78
+ #
77
79
  # @return [Nokogiri::HTML5]
80
+ #
78
81
  # @note `#rendered_preview` expects a preview to be defined with the same class
79
82
  # name as the calling test, but with `Test` replaced with `Preview`:
80
83
  #
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 4
6
- MINOR = 9
6
+ MINOR = 11
7
7
  PATCH = 0
8
8
  PRE = nil
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.9.0
4
+ version: 4.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ViewComponent Team
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubygems_version: 4.0.6
138
+ rubygems_version: 4.0.10
139
139
  specification_version: 4
140
140
  summary: A framework for building reusable, testable & encapsulated view components
141
141
  in Ruby on Rails.