view_component 3.0.0.rc1 → 3.0.0.rc2
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 +4 -4
- data/docs/CHANGELOG.md +48 -0
- data/lib/view_component/base.rb +27 -11
- data/lib/view_component/capture_compatibility.rb +42 -0
- data/lib/view_component/config.rb +9 -1
- data/lib/view_component/engine.rb +12 -5
- data/lib/view_component/rails/tasks/view_component.rake +1 -1
- data/lib/view_component/{slot_v2.rb → slot.rb} +1 -1
- data/lib/view_component/slotable.rb +361 -45
- data/lib/view_component/system_test_helpers.rb +1 -1
- data/lib/view_component/test_helpers.rb +46 -46
- data/lib/view_component/version.rb +1 -1
- data/lib/view_component.rb +1 -0
- metadata +4 -5
- data/lib/view_component/polymorphic_slots.rb +0 -91
- data/lib/view_component/slotable_v2.rb +0 -336
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2171ee963d59844894858309db964f092fb423bc4828a3bccbc917608502278
|
4
|
+
data.tar.gz: aaf7c734530bf46ea0fa5e7fdad4c6efaf7325eb45970fa2bea56d6c9f9a15c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f26a04b1af1b93be44db4436d57544c182c64a1d1036a2db62cecf0bc8b12da3f7ccf11e7cb8bf88c9c915495686ddcd774cca13a5adf7353dfc678d6c7ead1
|
7
|
+
data.tar.gz: a982b51ed80dc7da05da996005b2e60ca7af576a91c5ef13cdd68698735635fb42834e7cc45d23e5cbf45326b4ab8d8b85a1e6ddb7b2967a6d1e45638c73d50a
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,6 +10,54 @@ nav_order: 5
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## v3.0.0.rc2
|
14
|
+
|
15
|
+
Run into an issue with this release? [Let us know](https://github.com/ViewComponent/view_component/issues/1629).
|
16
|
+
|
17
|
+
* BREAKING: Rename `SlotV2` to `Slot` and `SlotableV2` to `Slotable`.
|
18
|
+
|
19
|
+
*Joel Hawksley*
|
20
|
+
|
21
|
+
* BREAKING: Incorporate `PolymorphicSlots` into `Slotable`. To migrate, remove any references to `PolymorphicSlots` as they are no longer necessary.
|
22
|
+
|
23
|
+
*Joel Hawksley*
|
24
|
+
|
25
|
+
* BREAKING: Rename private TestHelpers#controller, #build_controller, #request, and #preview_class to avoid conflicts. Note: While these methods were undocumented and marked as private, they was easily accessible in tests. As such, we're cautiously considering this to be a breaking change.
|
26
|
+
|
27
|
+
*Joel Hawksley*
|
28
|
+
|
29
|
+
* Avoid loading ActionView::Base during Rails initialization. Originally submitted in #1528.
|
30
|
+
|
31
|
+
*Jonathan del Strother*
|
32
|
+
|
33
|
+
* Improve documentation of known incompatibilities with Rails form helpers.
|
34
|
+
|
35
|
+
*Tobias L. Maier*
|
36
|
+
|
37
|
+
* Remove dependency on environment task from `view_component:statsetup`.
|
38
|
+
|
39
|
+
*Svetlin Simonyan*
|
40
|
+
|
41
|
+
* Add experimental `config.view_component.capture_compatibility_patch_enabled` option resolving rendering issues related to forms, capture, turbo frames, etc.
|
42
|
+
|
43
|
+
*Blake Williams*
|
44
|
+
|
45
|
+
* Add `#content?` method that indicates if content has been passed to component.
|
46
|
+
|
47
|
+
*Joel Hawksley*
|
48
|
+
|
49
|
+
* Added example of a custom preview controller.
|
50
|
+
|
51
|
+
*Graham Rogers*
|
52
|
+
|
53
|
+
* Add Krystal to list of companies using ViewComponent.
|
54
|
+
|
55
|
+
*Matt Bearman*
|
56
|
+
|
57
|
+
* Add Mon Ami to list of companies using ViewComponent.
|
58
|
+
|
59
|
+
*Ethan Lee-Tyson*
|
60
|
+
|
13
61
|
## 3.0.0.rc1
|
14
62
|
|
15
63
|
1,000+ days and 100+ releases later, the 200+ contributors to ViewComponent are proud to ship v3.0.0!
|
data/lib/view_component/base.rb
CHANGED
@@ -6,9 +6,8 @@ require "view_component/collection"
|
|
6
6
|
require "view_component/compile_cache"
|
7
7
|
require "view_component/compiler"
|
8
8
|
require "view_component/config"
|
9
|
-
require "view_component/polymorphic_slots"
|
10
9
|
require "view_component/preview"
|
11
|
-
require "view_component/
|
10
|
+
require "view_component/slotable"
|
12
11
|
require "view_component/translatable"
|
13
12
|
require "view_component/with_content_helper"
|
14
13
|
|
@@ -21,7 +20,7 @@ module ViewComponent
|
|
21
20
|
#
|
22
21
|
# @return [ViewComponent::Config]
|
23
22
|
def config
|
24
|
-
@config ||=
|
23
|
+
@config ||= ActiveSupport::OrderedOptions.new
|
25
24
|
end
|
26
25
|
|
27
26
|
# Replaces the entire config. You shouldn't need to use this directly
|
@@ -29,8 +28,7 @@ module ViewComponent
|
|
29
28
|
attr_writer :config
|
30
29
|
end
|
31
30
|
|
32
|
-
include ViewComponent::
|
33
|
-
include ViewComponent::SlotableV2
|
31
|
+
include ViewComponent::Slotable
|
34
32
|
include ViewComponent::Translatable
|
35
33
|
include ViewComponent::WithContentHelper
|
36
34
|
|
@@ -245,22 +243,40 @@ module ViewComponent
|
|
245
243
|
@request ||= controller.request if controller.respond_to?(:request)
|
246
244
|
end
|
247
245
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
246
|
+
# The content passed to the component instance as a block.
|
247
|
+
#
|
248
|
+
# @return [String]
|
252
249
|
def content
|
253
250
|
@__vc_content_evaluated = true
|
254
251
|
return @__vc_content if defined?(@__vc_content)
|
255
252
|
|
256
253
|
@__vc_content =
|
257
|
-
if
|
254
|
+
if __vc_render_in_block_provided?
|
258
255
|
view_context.capture(self, &@__vc_render_in_block)
|
259
|
-
elsif
|
256
|
+
elsif __vc_content_set_by_with_content_defined?
|
260
257
|
@__vc_content_set_by_with_content
|
261
258
|
end
|
262
259
|
end
|
263
260
|
|
261
|
+
# Whether `content` has been passed to the component.
|
262
|
+
#
|
263
|
+
# @return [Boolean]
|
264
|
+
def content?
|
265
|
+
__vc_render_in_block_provided? || __vc_content_set_by_with_content_defined?
|
266
|
+
end
|
267
|
+
|
268
|
+
private
|
269
|
+
|
270
|
+
attr_reader :view_context
|
271
|
+
|
272
|
+
def __vc_render_in_block_provided?
|
273
|
+
@view_context && @__vc_render_in_block
|
274
|
+
end
|
275
|
+
|
276
|
+
def __vc_content_set_by_with_content_defined?
|
277
|
+
defined?(@__vc_content_set_by_with_content)
|
278
|
+
end
|
279
|
+
|
264
280
|
def content_evaluated?
|
265
281
|
@__vc_content_evaluated
|
266
282
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ViewComponent
|
4
|
+
# CaptureCompatibility is a module that patches #capture to fix issues
|
5
|
+
# related to ViewComponent and functionality that relies on `capture`
|
6
|
+
# like forms, capture itself, turbo frames, etc.
|
7
|
+
#
|
8
|
+
# This underlying incompatibility with ViewComponent and capture is
|
9
|
+
# that several features like forms keep a reference to the primary
|
10
|
+
# `ActionView::Base` instance which has its own @output_buffer. When
|
11
|
+
# `#capture` is called on the original `ActionView::Base` instance while
|
12
|
+
# evaluating a block from a ViewComponent the @output_buffer is overridden
|
13
|
+
# in the ActionView::Base instance, and *not* the component. This results
|
14
|
+
# in a double render due to `#capture` implementation details.
|
15
|
+
#
|
16
|
+
# To resolve the issue, we override `#capture` so that we can delegate
|
17
|
+
# the `capture` logic to the ViewComponent that created the block.
|
18
|
+
module CaptureCompatibility
|
19
|
+
def self.included(base)
|
20
|
+
base.class_eval do
|
21
|
+
alias_method :original_capture, :capture
|
22
|
+
end
|
23
|
+
|
24
|
+
base.prepend(InstanceMethods)
|
25
|
+
end
|
26
|
+
|
27
|
+
module InstanceMethods
|
28
|
+
def capture(*args, &block)
|
29
|
+
# Handle blocks that originate from C code and raise, such as `&:method`
|
30
|
+
return original_capture(*args, &block) if block.source_location.nil?
|
31
|
+
|
32
|
+
block_context = block.binding.receiver
|
33
|
+
|
34
|
+
if block_context != self && block_context.class < ActionView::Base
|
35
|
+
block_context.original_capture(*args, &block)
|
36
|
+
else
|
37
|
+
original_capture(*args, &block)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -23,7 +23,8 @@ module ViewComponent
|
|
23
23
|
show_previews: Rails.env.development? || Rails.env.test?,
|
24
24
|
preview_paths: default_preview_paths,
|
25
25
|
test_controller: "ApplicationController",
|
26
|
-
default_preview_layout: nil
|
26
|
+
default_preview_layout: nil,
|
27
|
+
capture_compatibility_patch_enabled: false
|
27
28
|
})
|
28
29
|
end
|
29
30
|
|
@@ -137,6 +138,13 @@ module ViewComponent
|
|
137
138
|
# A custom default layout used for the previews index page and individual
|
138
139
|
# previews.
|
139
140
|
# Defaults to `nil`. If this is falsy, `"component_preview"` is used.
|
141
|
+
#
|
142
|
+
# @!attribute capture_compatibility_patch_enabled
|
143
|
+
# @return [Boolean]
|
144
|
+
# Enables the experimental capture compatibility patch that makes ViewComponent
|
145
|
+
# compatible with forms, capture, and other built-ins.
|
146
|
+
# previews.
|
147
|
+
# Defaults to `false`.
|
140
148
|
|
141
149
|
def default_preview_paths
|
142
150
|
return [] unless defined?(Rails.root) && Dir.exist?("#{Rails.root}/test/components/previews")
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "rails"
|
4
|
-
require "view_component/
|
4
|
+
require "view_component/config"
|
5
5
|
|
6
6
|
module ViewComponent
|
7
7
|
class Engine < Rails::Engine # :nodoc:
|
8
|
-
config.view_component = ViewComponent::
|
8
|
+
config.view_component = ViewComponent::Config.defaults
|
9
9
|
|
10
10
|
rake_tasks do
|
11
11
|
load "view_component/rails/tasks/view_component.rake"
|
@@ -14,9 +14,6 @@ module ViewComponent
|
|
14
14
|
initializer "view_component.set_configs" do |app|
|
15
15
|
options = app.config.view_component
|
16
16
|
|
17
|
-
%i[generate preview_controller preview_route show_previews_source].each do |config_option|
|
18
|
-
options[config_option] ||= ViewComponent::Base.public_send(config_option)
|
19
|
-
end
|
20
17
|
options.instrumentation_enabled = false if options.instrumentation_enabled.nil?
|
21
18
|
options.render_monkey_patch_enabled = true if options.render_monkey_patch_enabled.nil?
|
22
19
|
options.show_previews = (Rails.env.development? || Rails.env.test?) if options.show_previews.nil?
|
@@ -39,6 +36,8 @@ module ViewComponent
|
|
39
36
|
|
40
37
|
initializer "view_component.enable_instrumentation" do |app|
|
41
38
|
ActiveSupport.on_load(:view_component) do
|
39
|
+
Base.config = app.config.view_component
|
40
|
+
|
42
41
|
if app.config.view_component.instrumentation_enabled.present?
|
43
42
|
# :nocov:
|
44
43
|
ViewComponent::Base.prepend(ViewComponent::Instrumentation)
|
@@ -47,6 +46,14 @@ module ViewComponent
|
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
49
|
+
# :nocov:
|
50
|
+
initializer "view_component.enable_capture_patch" do |app|
|
51
|
+
ActiveSupport.on_load(:view_component) do
|
52
|
+
ActionView::Base.include(ViewComponent::CaptureCompatibility) if app.config.view_component.capture_compatibility_patch_enabled
|
53
|
+
end
|
54
|
+
end
|
55
|
+
# :nocov:
|
56
|
+
|
50
57
|
initializer "view_component.set_autoload_paths" do |app|
|
51
58
|
options = app.config.view_component
|
52
59
|
|