view_component 4.0.0.rc4 → 4.0.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 +4 -4
- data/docs/CHANGELOG.md +94 -5
- data/lib/view_component/base.rb +0 -6
- data/lib/view_component/compiler.rb +0 -10
- data/lib/view_component/template.rb +2 -2
- data/lib/view_component/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 315f6566baf49a86b15ce8537b28995fa64c8623c1a541c4cf2bc85891c5f837
|
4
|
+
data.tar.gz: ba7b833f7a0714e076cfc4e343c20532a2cba5737582aa654f143971c8c7a9f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d7903db688c6c28a3a2a874f2480ec70328b05e081629b6f0fe1f59ae1b049cea41e127ac89de098b256d00a6c1cd20c21b76d2ec04345c550132368dada341
|
7
|
+
data.tar.gz: 1d6ad41497fbb4a4f7fb1a44fbd606897e6e6b88f48933f818b26461834fe414c0c3f840f85fefedf6ed39f206fd07786c8e597a473ef44bdaacecfbb548e43d
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,6 +10,95 @@ nav_order: 6
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## 4.0.0
|
14
|
+
|
15
|
+
Two years after releasing [3.0.0](https://github.com/ViewComponent/view_component/releases/tag/v3.0.0) and almost six years since [1.0.0](https://github.com/ViewComponent/view_component/releases/tag/v1.0.0), we're proud to ship ViewComponent 4. This release marks a shift towards a Long Term Support model for the project, having reached significant feature maturity. While contributions are always welcome, we're unlikely to accept further breaking changes or major feature additions.
|
16
|
+
|
17
|
+
Please report any issues at [https://github.com/ViewComponent/view_component/issues](https://github.com/ViewComponent/view_component/issues).
|
18
|
+
|
19
|
+
### Breaking changes (production)
|
20
|
+
|
21
|
+
* Remove dependency on `ActionView::Base`, eliminating the need for capture compatibility patch. In some edge cases, this change may require switching to use the `helpers.` proxy.
|
22
|
+
* Require [non-EOL](https://endoflife.date/rails) Rails (`>= 7.1.0`) and Ruby (`>= 3.2.0`).
|
23
|
+
* Remove `render_component` and `render` monkey patch configured with `render_monkey_patch_enabled`.
|
24
|
+
* Remove deprecated `use_helper(s)`. Use `include MyHelper` or `helpers.` proxy instead.
|
25
|
+
* Support compatibility with `Dry::Initializer`. As a result, `EmptyOrInvalidInitializerError` will no longer be raised.
|
26
|
+
* Remove default initializer from `ViewComponent::Base`. Previously, `ViewComponent::Base` defined a catch-all initializer that allowed components without an initializer defined to be passed arbitrary arguments.
|
27
|
+
* Remove `use_deprecated_instrumentation_name` configuration option. Events will always use `render.view_component` name.
|
28
|
+
* Remove unnecessary `#format` methods that returned `nil`.
|
29
|
+
* Remove support for variant names containing `.` to be consistent with Rails.
|
30
|
+
* Rename internal methods to have `__vc_` prefix if they shouldn't be used by consumers. Make internal constants private. Make `Collection#components`, `Slotable#register_polymorphic_slot` private. Remove unused `ComponentError` class.
|
31
|
+
* Use ActionView's `lookup_context` for picking templates instead of the request format.
|
32
|
+
|
33
|
+
3.15 added support for using templates that match the request format, that is if `/resource.csv` is requested then
|
34
|
+
ViewComponents would pick `_component.csv.erb` over `_component.html.erb`.
|
35
|
+
|
36
|
+
With this release, the request format is no longer considered and instead ViewComponent will use the Rails logic for picking the most appropriate template type, that is the csv template will be used if it matches the `Accept` header or because the controller uses a `respond_to` block to pick the response format.
|
37
|
+
|
38
|
+
### Breaking changes (dev/test)
|
39
|
+
|
40
|
+
* Rename `config.generate.component_parent_class` to `config.generate.parent_class`.
|
41
|
+
* Remove `config.test_controller` in favor of `vc_test_controller_class` test helper method.
|
42
|
+
* `config.component_parent_class` is now `config.generate.component_parent_class`, moving the generator-specific option to the generator configuration namespace.
|
43
|
+
* Move previews-related configuration (`enabled`, `route`, `paths`, `default_layout`, `controller`) to under `previews` namespace.
|
44
|
+
* `config.view_component_path` is now `config.generate.path`, as components have long since been able to exist in any directory.
|
45
|
+
* `--inline` generator option now generates inline template. Use `--call` to generate `#call` method.
|
46
|
+
* Remove broken integration with `rails stats` that ignored components outside of `app/components`.
|
47
|
+
* Remove `preview_source` functionality. Consider using [Lookbook](https://lookbook.build/) instead.
|
48
|
+
* Use `Nokogiri::HTML5` instead of `Nokogiri::HTML4` for test helpers.
|
49
|
+
* Move generators to a ViewComponent namespace.
|
50
|
+
|
51
|
+
Before, ViewComponent generators pollute the generator namespace with a bunch of top level items, and claim the generic "component" name.
|
52
|
+
|
53
|
+
Now, generators live in a "view_component" module/namespace, so what was before `rails g
|
54
|
+
component` is now `rails g view_component:component`.
|
55
|
+
|
56
|
+
### New features
|
57
|
+
|
58
|
+
* Add `SystemSpecHelpers` for use with RSpec.
|
59
|
+
* Add support for including `Turbo::StreamsHelper`.
|
60
|
+
* Add template annotations for components with `def call`.
|
61
|
+
* Graduate `SlotableDefault` to be included by default.
|
62
|
+
* Add `#current_template` accessor and `Template#path` for diagnostic usage.
|
63
|
+
* Reduce string allocations during compilation.
|
64
|
+
* Add `around_render` lifecyle method for wrapping component rendering in custom instrumentation, etc.
|
65
|
+
|
66
|
+
### Bug fixes
|
67
|
+
|
68
|
+
* Fix bug where virtual path wasn't reset, breaking translations outside of components.
|
69
|
+
* Fix bug where `config.previews.enabled` didn't function properly in production environments.
|
70
|
+
* Fix bug in `SlotableDefault` where default couldn't be overridden when content was passed as a block.
|
71
|
+
* Fix bug where request-aware helpers didn't work outside of the request context.
|
72
|
+
* `ViewComponentsSystemTestController` shouldn't be useable outside of test environment
|
73
|
+
|
74
|
+
### Non-functional changes
|
75
|
+
|
76
|
+
* Remove unnecessary usage of `ruby2_keywords`.
|
77
|
+
* Remove unnecessary `respond_to` checks.
|
78
|
+
* Require MFA when publishing to RubyGems.
|
79
|
+
* Clean up project dependencies, relaxing versions of development gems.
|
80
|
+
* Add test case for absolute URL path helpers in mailers.
|
81
|
+
* Update documentation on performance to reflect more representative benchmark showing 2-3x speed increase over partials.
|
82
|
+
* Add documentation note about instrumentation negatively affecting performance.
|
83
|
+
* Remove unnecessary ENABLE_RELOADING test suite flag.
|
84
|
+
* `config.previews.default_layout` should default to nil.
|
85
|
+
* Add test coverage for uncovered code.
|
86
|
+
* Test against `turbo-rails` `v2` and `rspec-rails` `v7`.
|
87
|
+
|
88
|
+
## 4.0.0.rc5
|
89
|
+
|
90
|
+
* Revert change setting `#format`. In GitHub's codebase, the change led to hard-to-detect failures. For example, components rendered from controllers included layouts when they didn't before. In other cases, the response `content_type` changed, breaking downstream consumers. For cases where a specific content type is needed, use:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
respond_to do |f|
|
94
|
+
f.html_fragment do
|
95
|
+
render(MyComponent.new)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
100
|
+
*Joel Hawksley*
|
101
|
+
|
13
102
|
## 4.0.0.rc4
|
14
103
|
|
15
104
|
* Fix issue where generators were not included in published gem.
|
@@ -42,7 +131,7 @@ Almost six years after releasing [v1.0.0](https://github.com/ViewComponent/view_
|
|
42
131
|
|
43
132
|
Please report any issues at [https://github.com/ViewComponent/view_component/issues](https://github.com/ViewComponent/view_component/issues).
|
44
133
|
|
45
|
-
### Breaking changes (production)
|
134
|
+
### 4.0.0.rc1 Breaking changes (production)
|
46
135
|
|
47
136
|
* Remove dependency on `ActionView::Base`, eliminating the need for capture compatibility patch. In some edge cases, this change may require switching to use the `helpers.` proxy.
|
48
137
|
* Require [non-EOL](https://endoflife.date/rails) Rails (`>= 7.1.0`) and Ruby (`>= 3.2.0`).
|
@@ -61,7 +150,7 @@ Please report any issues at [https://github.com/ViewComponent/view_component/iss
|
|
61
150
|
|
62
151
|
With this release, the request format is no longer considered and instead ViewComponent will use the Rails logic for picking the most appropriate template type, that is the csv template will be used if it matches the `Accept` header or because the controller uses a `respond_to` block to pick the response format.
|
63
152
|
|
64
|
-
### Breaking changes (dev/test)
|
153
|
+
### 4.0.0.rc1 Breaking changes (dev/test)
|
65
154
|
|
66
155
|
* Rename `config.generate.component_parent_class` to `config.generate.parent_class`.
|
67
156
|
* Remove `config.test_controller` in favor of `vc_test_controller_class` test helper method.
|
@@ -79,7 +168,7 @@ Please report any issues at [https://github.com/ViewComponent/view_component/iss
|
|
79
168
|
Now, generators live in a "view_component" module/namespace, so what was before `rails g
|
80
169
|
component` is now `rails g view_component:component`.
|
81
170
|
|
82
|
-
### New features
|
171
|
+
### 4.0.0.rc1 New features
|
83
172
|
|
84
173
|
* Add `SystemSpecHelpers` for use with RSpec.
|
85
174
|
* Add support for including `Turbo::StreamsHelper`.
|
@@ -88,7 +177,7 @@ Please report any issues at [https://github.com/ViewComponent/view_component/iss
|
|
88
177
|
* Add `#current_template` accessor and `Template#path` for diagnostic usage.
|
89
178
|
* Reduce string allocations during compilation.
|
90
179
|
|
91
|
-
### Bug fixes
|
180
|
+
### 4.0.0.rc1 Bug fixes
|
92
181
|
|
93
182
|
* Fix bug where virtual path wasn't reset, breaking translations outside of components.
|
94
183
|
* Fix bug where `config.previews.enabled` didn't function properly in production environments.
|
@@ -97,7 +186,7 @@ Please report any issues at [https://github.com/ViewComponent/view_component/iss
|
|
97
186
|
* Fix bug where request-aware helpers didn't work outside of the request context.
|
98
187
|
* `ViewComponentsSystemTestController` shouldn't be useable outside of test environment
|
99
188
|
|
100
|
-
### Non-functional changes
|
189
|
+
### 4.0.0.rc1 Non-functional changes
|
101
190
|
|
102
191
|
* Remove unnecessary usage of `ruby2_keywords`.
|
103
192
|
* Remove unnecessary `respond_to` checks.
|
data/lib/view_component/base.rb
CHANGED
@@ -71,8 +71,6 @@ module ViewComponent
|
|
71
71
|
# Config option that strips trailing whitespace in templates before compiling them.
|
72
72
|
class_attribute :__vc_strip_trailing_whitespace, instance_accessor: false, instance_predicate: false, default: false
|
73
73
|
|
74
|
-
class_attribute :__vc_response_format, instance_accessor: false, instance_predicate: false, default: nil
|
75
|
-
|
76
74
|
attr_accessor :__vc_original_view_context
|
77
75
|
attr_reader :current_template
|
78
76
|
|
@@ -356,10 +354,6 @@ module ViewComponent
|
|
356
354
|
__vc_render_in_block_provided? || __vc_content_set_by_with_content_defined?
|
357
355
|
end
|
358
356
|
|
359
|
-
def format
|
360
|
-
self.class.__vc_response_format
|
361
|
-
end
|
362
|
-
|
363
357
|
# @private
|
364
358
|
def with_original_virtual_path
|
365
359
|
@view_context.instance_variable_set(:@virtual_path, @old_virtual_path)
|
@@ -48,15 +48,6 @@ module ViewComponent
|
|
48
48
|
|
49
49
|
define_render_template_for
|
50
50
|
|
51
|
-
# Set the format if the component only responds to a single format.
|
52
|
-
# Unfortunately we cannot determine which format a multi-format
|
53
|
-
# component will respond to until render time, so those components
|
54
|
-
# will not set the response format.
|
55
|
-
#
|
56
|
-
# TODO: Investigate upstream changes necessary to support multi-format renderables
|
57
|
-
unique_formats = templates.map(&:format).uniq
|
58
|
-
@component.__vc_response_format = unique_formats.last if unique_formats.one?
|
59
|
-
|
60
51
|
@component.__vc_register_default_slots
|
61
52
|
@component.__vc_build_i18n_backend
|
62
53
|
|
@@ -118,7 +109,6 @@ module ViewComponent
|
|
118
109
|
errors << "Couldn't find a template file or inline render method for #{@component}." if @templates.empty?
|
119
110
|
|
120
111
|
@templates
|
121
|
-
.reject { |template| template.inline_call? && !template.defined_on_self? }
|
122
112
|
.map { |template| [template.variant, template.format] }
|
123
113
|
.tally
|
124
114
|
.select { |_, count| count > 1 }
|
@@ -43,7 +43,7 @@ module ViewComponent
|
|
43
43
|
attr_reader :source
|
44
44
|
|
45
45
|
def initialize(component:, inline_template:)
|
46
|
-
details = ActionView::TemplateDetails.new(nil, inline_template.language.to_sym,
|
46
|
+
details = ActionView::TemplateDetails.new(nil, inline_template.language.to_sym, nil, nil)
|
47
47
|
|
48
48
|
super(
|
49
49
|
component: component,
|
@@ -63,7 +63,7 @@ module ViewComponent
|
|
63
63
|
class InlineCall < Template
|
64
64
|
def initialize(component:, method_name:, defined_on_self:)
|
65
65
|
variant = method_name.to_s.include?("call_") ? method_name.to_s.sub("call_", "").to_sym : nil
|
66
|
-
details = ActionView::TemplateDetails.new(nil, nil,
|
66
|
+
details = ActionView::TemplateDetails.new(nil, nil, nil, variant)
|
67
67
|
|
68
68
|
super(component: component, details: details)
|
69
69
|
|