view_component 3.23.2 → 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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/view_component/preview_actions.rb +11 -14
  3. data/app/controllers/view_components_system_test_controller.rb +15 -20
  4. data/app/views/test_mailer/test_asset_email.html.erb +1 -0
  5. data/app/views/test_mailer/test_url_email.html.erb +1 -0
  6. data/app/views/view_components/preview.html.erb +1 -9
  7. data/docs/CHANGELOG.md +404 -0
  8. data/lib/{rails/generators → generators/view_component}/abstract_generator.rb +2 -2
  9. data/lib/{rails/generators → generators/view_component}/component/component_generator.rb +16 -3
  10. data/lib/{rails/generators → generators/view_component}/component/templates/component.rb.tt +6 -1
  11. data/lib/{rails/generators/erb/component_generator.rb → generators/view_component/erb/erb_generator.rb} +4 -3
  12. data/lib/{rails/generators/haml/component_generator.rb → generators/view_component/haml/haml_generator.rb} +3 -3
  13. data/lib/{rails/generators/locale/component_generator.rb → generators/view_component/locale/locale_generator.rb} +3 -3
  14. data/lib/{rails/generators/preview/component_generator.rb → generators/view_component/preview/preview_generator.rb} +3 -3
  15. data/lib/{rails/generators/rspec/component_generator.rb → generators/view_component/rspec/rspec_generator.rb} +3 -3
  16. data/lib/{rails/generators/slim/component_generator.rb → generators/view_component/slim/slim_generator.rb} +3 -3
  17. data/lib/{rails/generators/stimulus/component_generator.rb → generators/view_component/stimulus/stimulus_generator.rb} +3 -3
  18. data/lib/generators/view_component/tailwindcss/tailwindcss_generator.rb +11 -0
  19. data/lib/{rails/generators/test_unit/component_generator.rb → generators/view_component/test_unit/test_unit_generator.rb} +2 -2
  20. data/lib/view_component/base.rb +154 -157
  21. data/lib/view_component/collection.rb +11 -25
  22. data/lib/view_component/compiler.rb +52 -79
  23. data/lib/view_component/config.rb +51 -85
  24. data/lib/view_component/configurable.rb +1 -1
  25. data/lib/view_component/deprecation.rb +1 -1
  26. data/lib/view_component/engine.rb +37 -107
  27. data/lib/view_component/errors.rb +16 -34
  28. data/lib/view_component/inline_template.rb +3 -4
  29. data/lib/view_component/instrumentation.rb +4 -10
  30. data/lib/view_component/preview.rb +4 -11
  31. data/lib/view_component/request_details.rb +30 -0
  32. data/lib/view_component/slot.rb +6 -13
  33. data/lib/view_component/slotable.rb +82 -77
  34. data/lib/view_component/system_spec_helpers.rb +11 -0
  35. data/lib/view_component/system_test_helpers.rb +1 -2
  36. data/lib/view_component/template.rb +106 -83
  37. data/lib/view_component/test_helpers.rb +37 -44
  38. data/lib/view_component/translatable.rb +33 -32
  39. data/lib/view_component/version.rb +3 -3
  40. data/lib/view_component.rb +8 -6
  41. metadata +30 -558
  42. data/app/assets/vendor/prism.css +0 -4
  43. data/app/assets/vendor/prism.min.js +0 -12
  44. data/app/helpers/preview_helper.rb +0 -85
  45. data/app/views/view_components/_preview_source.html.erb +0 -17
  46. data/lib/rails/generators/tailwindcss/component_generator.rb +0 -11
  47. data/lib/view_component/capture_compatibility.rb +0 -44
  48. data/lib/view_component/component_error.rb +0 -6
  49. data/lib/view_component/rails/tasks/view_component.rake +0 -20
  50. data/lib/view_component/render_component_helper.rb +0 -10
  51. data/lib/view_component/render_component_to_string_helper.rb +0 -9
  52. data/lib/view_component/render_monkey_patch.rb +0 -13
  53. data/lib/view_component/render_to_string_monkey_patch.rb +0 -13
  54. data/lib/view_component/rendering_component_helper.rb +0 -9
  55. data/lib/view_component/rendering_monkey_patch.rb +0 -13
  56. data/lib/view_component/slotable_default.rb +0 -20
  57. data/lib/view_component/use_helpers.rb +0 -42
  58. /data/lib/{rails/generators → generators/view_component}/erb/templates/component.html.erb.tt +0 -0
  59. /data/lib/{rails/generators → generators/view_component}/haml/templates/component.html.haml.tt +0 -0
  60. /data/lib/{rails/generators → generators/view_component}/preview/templates/component_preview.rb.tt +0 -0
  61. /data/lib/{rails/generators → generators/view_component}/rspec/templates/component_spec.rb.tt +0 -0
  62. /data/lib/{rails/generators → generators/view_component}/slim/templates/component.html.slim.tt +0 -0
  63. /data/lib/{rails/generators → generators/view_component}/stimulus/templates/component_controller.js.tt +0 -0
  64. /data/lib/{rails/generators → generators/view_component}/stimulus/templates/component_controller.ts.tt +0 -0
  65. /data/lib/{rails/generators → generators/view_component}/tailwindcss/templates/component.html.erb.tt +0 -0
  66. /data/lib/{rails/generators → generators/view_component}/test_unit/templates/component_test.rb.tt +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79672f93bd1c3bfa2dae00890f833c5dfb63dec49585dd79453f6592f9f47520
4
- data.tar.gz: e6fe55dfe963ce0e7f4d793c93b67aefa92c99ee834c17c35644a9ea8b746886
3
+ metadata.gz: 315f6566baf49a86b15ce8537b28995fa64c8623c1a541c4cf2bc85891c5f837
4
+ data.tar.gz: ba7b833f7a0714e076cfc4e343c20532a2cba5737582aa654f143971c8c7a9f1
5
5
  SHA512:
6
- metadata.gz: 311478a282f72c7b703594ec119dfc2686ec8cd3c6d6e97ff9fab9a32638e09eacefdc82a3808c581e48ab2af4cbfb26f66c7064cb614367cb4916fdf3b7df76
7
- data.tar.gz: 3c059cb40bfa81c45a60bc9d107be8402923f92f0a8e1b50c6cdfcad88a4da6407244f1e5220d58f59a938c3d77e748ec22f360b8cf49041279616138ac4397d
6
+ metadata.gz: 2d7903db688c6c28a3a2a874f2480ec70328b05e081629b6f0fe1f59ae1b049cea41e127ac89de098b256d00a6c1cd20c21b76d2ec04345c550132368dada341
7
+ data.tar.gz: 1d6ad41497fbb4a4f7fb1a44fbd606897e6e6b88f48933f818b26461834fe414c0c3f840f85fefedf6ed39f206fd07786c8e597a473ef44bdaacecfbb548e43d
@@ -8,20 +8,13 @@ module ViewComponent
8
8
  prepend_view_path File.expand_path("../../../views", __dir__)
9
9
 
10
10
  around_action :set_locale, only: :previews
11
- before_action :require_local!, unless: :show_previews?
11
+ before_action :require_local!, unless: :previews_enabled?
12
12
 
13
- content_security_policy(false) if respond_to?(:content_security_policy)
13
+ content_security_policy(false)
14
14
 
15
15
  # Including helpers here ensures that we're loading the
16
16
  # latest version of helpers if code-reloading is enabled
17
- if include_all_helpers
18
- helper :all
19
- else
20
- # :nocov:
21
- # Always provide the #view_source helper
22
- helper PreviewHelper
23
- # :nocov:
24
- end
17
+ helper :all if include_all_helpers
25
18
  end
26
19
 
27
20
  def index
@@ -54,12 +47,12 @@ module ViewComponent
54
47
 
55
48
  # :doc:
56
49
  def default_preview_layout
57
- ViewComponent::Base.config.default_preview_layout
50
+ ViewComponent::Base.config.previews.default_layout
58
51
  end
59
52
 
60
53
  # :doc:
61
- def show_previews?
62
- ViewComponent::Base.config.show_previews
54
+ def previews_enabled?
55
+ ViewComponent::Base.config.previews.enabled
63
56
  end
64
57
 
65
58
  # :doc:
@@ -71,7 +64,11 @@ module ViewComponent
71
64
  if preview
72
65
  @preview = ViewComponent::Preview.find(preview)
73
66
  else
67
+ # TODO: This branch is covered in #test_returns_404_when_preview_does_not_exist,
68
+ # but Simplecov doesn't always mark it as covered.
69
+ # :nocov:
74
70
  raise AbstractController::ActionNotFound, "Component preview '#{params[:path]}' not found."
71
+ # :nocov:
75
72
  end
76
73
  end
77
74
 
@@ -102,7 +99,7 @@ module ViewComponent
102
99
  end
103
100
 
104
101
  def prepend_preview_examples_view_path
105
- prepend_view_path(ViewComponent::Base.preview_paths)
102
+ prepend_view_path(ViewComponent::Base.previews.paths)
106
103
  end
107
104
  end
108
105
  end
@@ -1,30 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViewComponentsSystemTestController < ActionController::Base # :nodoc:
4
- before_action :validate_test_env
5
- before_action :validate_file_path
4
+ if Rails.env.test?
5
+ before_action :validate_file_path
6
6
 
7
- def self.temp_dir
8
- @_tmpdir ||= FileUtils.mkdir_p("./tmp/view_components/").first
9
- end
10
-
11
- def system_test_entrypoint
12
- render file: @path
13
- end
7
+ def self.temp_dir
8
+ @_tmpdir ||= FileUtils.mkdir_p("./tmp/view_components/").first
9
+ end
14
10
 
15
- private
11
+ def system_test_entrypoint
12
+ render file: @path
13
+ end
16
14
 
17
- def validate_test_env
18
- raise ViewComponent::SystemTestControllerOnlyAllowedInTestError unless Rails.env.test?
19
- end
15
+ private
20
16
 
21
- # Ensure that the file path is valid and doesn't target files outside
22
- # the expected directory (e.g. via a path traversal or symlink attack)
23
- def validate_file_path
24
- base_path = ::File.realpath(self.class.temp_dir)
25
- @path = ::File.realpath(params.permit(:file)[:file], base_path)
26
- unless @path.start_with?(base_path)
27
- raise ViewComponent::SystemTestControllerNefariousPathError
17
+ # Ensure that the file path is valid and doesn't target files outside
18
+ # the expected directory (e.g. via a path traversal or symlink attack)
19
+ def validate_file_path
20
+ base_path = ::File.realpath(self.class.temp_dir)
21
+ @path = ::File.realpath(params.permit(:file)[:file], base_path)
22
+ raise ViewComponent::SystemTestControllerNefariousPathError unless @path.start_with?(base_path)
28
23
  end
29
24
  end
30
25
  end
@@ -0,0 +1 @@
1
+ <%= render AssetComponent.new %>
@@ -0,0 +1 @@
1
+ <%= render(UrlForMailerComponent.new) %>
@@ -1,13 +1,5 @@
1
1
  <% if @render_args[:component] %>
2
- <% if ViewComponent::Base.config.render_monkey_patch_enabled || Rails.version.to_f >= 6.1 %>
3
- <%= render(@render_args[:component], @render_args[:args], &@render_args[:block]) %>
4
- <% else %>
5
- <%= render_component(@render_args[:component], &@render_args[:block]) %>
6
- <% end %>
2
+ <%= render(@render_args[:component], @render_args[:args], &@render_args[:block]) %>
7
3
  <% else %>
8
4
  <%= render template: @render_args[:template], locals: @render_args[:locals] || {} %>
9
5
  <% end %>
10
-
11
- <% if ViewComponent::Base.config.show_previews_source %>
12
- <%= preview_source %>
13
- <% end %>
data/docs/CHANGELOG.md CHANGED
@@ -10,6 +10,410 @@ 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
+
102
+ ## 4.0.0.rc4
103
+
104
+ * Fix issue where generators were not included in published gem.
105
+
106
+ *Jean-Louis Giordano*
107
+
108
+ ## 4.0.0.rc3
109
+
110
+ * Reformat the avatars section to arrange them in a grid.
111
+
112
+ *Josh Cohen*
113
+
114
+ * Fix bug where relative paths in `translate` didn't work in blocks passed to ViewComponents.
115
+
116
+ *Joel Hawksley*
117
+
118
+ * Add SerpApi to "Who uses ViewComponent" list.
119
+
120
+ *Andy from SerpApi*
121
+
122
+ ## 4.0.0.rc2
123
+
124
+ * Add `around_render` lifecyle method for wrapping component rendering in custom instrumentation, etc.
125
+
126
+ *Joel Hawksley*, *Blake Williams*
127
+
128
+ ## 4.0.0.rc1
129
+
130
+ Almost six years after releasing [v1.0.0](https://github.com/ViewComponent/view_component/releases/tag/v1.0.0), we're proud to ship the first release candidate of 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.
131
+
132
+ Please report any issues at [https://github.com/ViewComponent/view_component/issues](https://github.com/ViewComponent/view_component/issues).
133
+
134
+ ### 4.0.0.rc1 Breaking changes (production)
135
+
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.
137
+ * Require [non-EOL](https://endoflife.date/rails) Rails (`>= 7.1.0`) and Ruby (`>= 3.2.0`).
138
+ * Remove `render_component` and `render` monkey patch configured with `render_monkey_patch_enabled`.
139
+ * Remove deprecated `use_helper(s)`. Use `include MyHelper` or `helpers.` proxy instead.
140
+ * Support compatibility with `Dry::Initializer`. As a result, `EmptyOrInvalidInitializerError` will no longer be raised.
141
+ * 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.
142
+ * Remove `use_deprecated_instrumentation_name` configuration option. Events will always use `render.view_component` name.
143
+ * Remove unnecessary `#format` methods that returned `nil`.
144
+ * Remove support for variant names containing `.` to be consistent with Rails.
145
+ * 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.
146
+ * Use ActionView's `lookup_context` for picking templates instead of the request format.
147
+
148
+ 3.15 added support for using templates that match the request format, that is if `/resource.csv` is requested then
149
+ ViewComponents would pick `_component.csv.erb` over `_component.html.erb`.
150
+
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.
152
+
153
+ ### 4.0.0.rc1 Breaking changes (dev/test)
154
+
155
+ * Rename `config.generate.component_parent_class` to `config.generate.parent_class`.
156
+ * Remove `config.test_controller` in favor of `vc_test_controller_class` test helper method.
157
+ * `config.component_parent_class` is now `config.generate.component_parent_class`, moving the generator-specific option to the generator configuration namespace.
158
+ * Move previews-related configuration (`enabled`, `route`, `paths`, `default_layout`, `controller`) to under `previews` namespace.
159
+ * `config.view_component_path` is now `config.generate.path`, as components have long since been able to exist in any directory.
160
+ * `--inline` generator option now generates inline template. Use `--call` to generate `#call` method.
161
+ * Remove broken integration with `rails stats` that ignored components outside of `app/components`.
162
+ * Remove `preview_source` functionality. Consider using [Lookbook](https://lookbook.build/) instead.
163
+ * Use `Nokogiri::HTML5` instead of `Nokogiri::HTML4` for test helpers.
164
+ * Move generators to a ViewComponent namespace.
165
+
166
+ Before, ViewComponent generators pollute the generator namespace with a bunch of top level items, and claim the generic "component" name.
167
+
168
+ Now, generators live in a "view_component" module/namespace, so what was before `rails g
169
+ component` is now `rails g view_component:component`.
170
+
171
+ ### 4.0.0.rc1 New features
172
+
173
+ * Add `SystemSpecHelpers` for use with RSpec.
174
+ * Add support for including `Turbo::StreamsHelper`.
175
+ * Add template annotations for components with `def call`.
176
+ * Graduate `SlotableDefault` to be included by default.
177
+ * Add `#current_template` accessor and `Template#path` for diagnostic usage.
178
+ * Reduce string allocations during compilation.
179
+
180
+ ### 4.0.0.rc1 Bug fixes
181
+
182
+ * Fix bug where virtual path wasn't reset, breaking translations outside of components.
183
+ * Fix bug where `config.previews.enabled` didn't function properly in production environments.
184
+ * Fix bug where response format wasn't set, which caused issues with Turbo Frames.
185
+ * Fix bug in `SlotableDefault` where default couldn't be overridden when content was passed as a block.
186
+ * Fix bug where request-aware helpers didn't work outside of the request context.
187
+ * `ViewComponentsSystemTestController` shouldn't be useable outside of test environment
188
+
189
+ ### 4.0.0.rc1 Non-functional changes
190
+
191
+ * Remove unnecessary usage of `ruby2_keywords`.
192
+ * Remove unnecessary `respond_to` checks.
193
+ * Require MFA when publishing to RubyGems.
194
+ * Clean up project dependencies, relaxing versions of development gems.
195
+ * Add test case for absolute URL path helpers in mailers.
196
+ * Update documentation on performance to reflect more representative benchmark showing 2-3x speed increase over partials.
197
+ * Add documentation note about instrumentation negatively affecting performance.
198
+ * Remove unnecessary ENABLE_RELOADING test suite flag.
199
+ * `config.previews.default_layout` should default to nil.
200
+ * Add test coverage for uncovered code.
201
+ * Test against `turbo-rails` `v2` and `rspec-rails` `v7`.
202
+
203
+ ## 4.0.0.alpha7
204
+
205
+ * BREAKING: Remove deprecated `use_helper(s)`. Use `include MyHelper` or `helpers.` proxy instead.
206
+
207
+ *Joel Hawksley*
208
+
209
+ * BREAKING: Support compatibility with `Dry::Initializer`. As a result, `EmptyOrInvalidInitializerError` will no longer be raised.
210
+
211
+ *Joel Hawksley*
212
+
213
+ * BREAKING: Rename `config.generate.component_parent_class` to `config.generate.parent_class`.
214
+
215
+ *Joel Hawksley*
216
+
217
+ * Fix bug where `config.previews.enabled` didn't function properly in production environments.
218
+
219
+ *Joel Hawksley*
220
+
221
+ * `config.previews.default_layout` should default to nil.
222
+
223
+ *Joel Hawksley*
224
+
225
+ * Add test case for absolute URL path helpers in mailers.
226
+
227
+ *Joel Hawksley*
228
+
229
+ * Fix bug where response format wasn't set, which caused issues with Turbo Frames.
230
+
231
+ *Joel Hawksley*
232
+
233
+ ## 4.0.0.alpha6
234
+
235
+ * BREAKING: Remove `config.test_controller` in favor of `vc_test_controller_class` test helper method.
236
+
237
+ *Joel Hawksley*
238
+
239
+ * BREAKING: `config.component_parent_class` is now `config.generate.component_parent_class`, moving the generator-specific option to the generator configuration namespace.
240
+
241
+ *Joel Hawksley*
242
+
243
+ * BREAKING: Move previews-related configuration (`enabled`, `route`, `paths`, `default_layout`, `controller`) to under `previews` namespace.
244
+
245
+ *Joel Hawksley*
246
+
247
+ * Add template annotations for components with `def call`.
248
+
249
+ *Joel Hawksley*
250
+
251
+ * Add support for including Turbo::StreamsHelper.
252
+
253
+ *Stephen Nelson*
254
+
255
+ * Update documentation on performance to reflect more representative benchmark showing 2-3x speed increase over partials.
256
+
257
+ *Joel Hawksley*
258
+
259
+ * Add documentation note about instrumentation negatively affecting performance.
260
+
261
+ *Joel Hawksley*
262
+
263
+ * Revert object shapes optimization due to lack of evidence of improvement.
264
+
265
+ *Joel Hawksley*
266
+
267
+ ## 4.0.0.alpha5
268
+
269
+ * BREAKING: `config.view_component_path` is now `config.generate.path`, as components have long since been able to exist in any directory.
270
+
271
+ *Joel Hawksley*
272
+
273
+ * BREAKING: Remove broken integration with `rails stats` that ignored components outside of `app/components`.
274
+
275
+ *Joel Hawksley*
276
+
277
+ ## 4.0.0.alpha4
278
+
279
+ * BREAKING: 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.
280
+
281
+ *Joel Hawksley*
282
+
283
+ * Graduate `SlotableDefault` to be included by default.
284
+
285
+ *Joel Hawksley*
286
+
287
+ * Fix bug in `SlotableDefault` where default couldn't be overridden when content was passed as a block.
288
+
289
+ *Bill Watts*, *Joel Hawksley*
290
+
291
+ ## 4.0.0.alpha3
292
+
293
+ * BREAKING: Remove dependency on `ActionView::Base`, eliminating the need for capture compatibility patch.
294
+
295
+ *Cameron Dutro*
296
+
297
+ ## 4.0.0.alpha2
298
+
299
+ * Add `#current_template` accessor and `Template#path` for diagnostic usage.
300
+
301
+ *Joel Hawksley*
302
+
303
+ ## 4.0.0.alpha1
304
+
305
+ Almost six years after releasing [v1.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.
306
+
307
+ This release makes the following breaking changes:
308
+
309
+ * BREAKING: `--inline` generator option now generates inline template. Use `--call` to generate `#call` method.
310
+
311
+ *Joel Hawksley*
312
+
313
+ * BREAKING: Remove `use_deprecated_instrumentation_name` configuration option. Events will always use `render.view_component` name.
314
+
315
+ *Joel Hawksley*
316
+
317
+ * BREAKING: Remove `preview_source` functionality. Consider using [Lookbook](https://lookbook.build/) instead.
318
+
319
+ *Joel Hawksley*
320
+
321
+ * BREAKING: Use `Nokogiri::HTML5` instead of `Nokogiri::HTML4` for test helpers.
322
+
323
+ *Noah Silvera*, *Joel Hawksley*
324
+
325
+ * BREAKING: Move generators to a ViewComponent namespace.
326
+
327
+ Before, ViewComponent generators pollute the generator namespace with a bunch of top level items, and claim the generic "component" name.
328
+
329
+ Now, generators live in a "view_component" module/namespace, so what was before `rails g
330
+ component` is now `rails g view_component:component`.
331
+
332
+ *Paul Sadauskas*
333
+
334
+ * BREAKING: Require [non-EOL](https://endoflife.date/rails) Rails (`>= 7.1.0`).
335
+
336
+ *Joel Hawksley*
337
+
338
+ * BREAKING: Require [non-EOL](https://www.ruby-lang.org/en/downloads/branches/) Ruby (`>= 3.2.0`).
339
+
340
+ *Joel Hawksley*
341
+
342
+ * BREAKING: Remove `render_component` and `render` monkey patch configured with `render_monkey_patch_enabled`.
343
+
344
+ *Joel Hawksley*
345
+
346
+ * BREAKING: Remove support for variant names containing `.` to be consistent with Rails.
347
+
348
+ *Stephen Nelson*
349
+
350
+ * BREAKING: Use ActionView's `lookup_context` for picking templates instead of the request format.
351
+
352
+ 3.15 added support for using templates that match the request format, that is if `/resource.csv` is requested then
353
+ ViewComponents would pick `_component.csv.erb` over `_component.html.erb`.
354
+
355
+ With this release, the request format is no longer considered and instead ViewComponent will use the Rails logic
356
+ for picking the most appropriate template type, that is the csv template will be used if it matches the `Accept` header
357
+ or because the controller uses a `respond_to` block to pick the response format.
358
+
359
+ *Stephen Nelson*
360
+
361
+ * BREAKING: 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.
362
+
363
+ *Joel Hawksley*
364
+
365
+ * Fix bug where request-aware helpers didn't work outside of the request context.
366
+
367
+ *Joel Hawksley*, *Stephen Nelson*
368
+
369
+ * `ViewComponentsSystemTestController` shouldn't be useable outside of test environment
370
+
371
+ *Joel Hawksley*, *Stephen Nelson*
372
+
373
+ * Remove unnecessary ENABLE_RELOADING test suite flag.
374
+
375
+ *Joel Hawksley*
376
+
377
+ * Add test coverage for uncovered code.
378
+
379
+ *Joel Hawksley*
380
+
381
+ * Remove unnecessary `#format` methods that returned `nil`.
382
+
383
+ *Joel Hawksley*
384
+
385
+ * Clean up project dependencies, relaxing versions of development gems.
386
+
387
+ *Joel Hawksley*
388
+
389
+ * Test against `turbo-rails` `v2`.
390
+
391
+ *Joel Hawksley*
392
+
393
+ * Test against `rspec-rails` `v7`.
394
+
395
+ *Joel Hawksley*
396
+
397
+ * Remove unnecessary usage of `ruby2_keywords`.
398
+
399
+ *Joel Hawksley*
400
+
401
+ * Remove unnecessary `respond_to` checks.
402
+
403
+ *Tiago Menegaz*, *Joel Hawksley*
404
+
405
+ * Introduce component-local config and migrate `strip_trailing_whitespace` to use it under the hood.
406
+
407
+ *Simon Fish*
408
+
409
+ * Deprecate `use_helper(s)`. Use `include MyHelper` or `helpers.` proxy instead.
410
+
411
+ *Joel Hawksley*
412
+
413
+ * Reduce string allocations during compilation.
414
+
415
+ *Jonathan del Strother*
416
+
13
417
  ## 3.23.2
14
418
 
15
419
  * Include .tt files in published gem. Fixes templates not being available when using generators.
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module AbstractGenerator
5
5
  def copy_view_file
6
- template "component.html.#{engine_name}", destination unless options["inline"]
6
+ template("component.html.#{engine_name}", destination) unless options["inline"] || options["call"]
7
7
  end
8
8
 
9
9
  private
@@ -29,7 +29,7 @@ module ViewComponent
29
29
  end
30
30
 
31
31
  def component_path
32
- ViewComponent::Base.config.view_component_path
32
+ ViewComponent::Base.config.generate.path
33
33
  end
34
34
 
35
35
  def stimulus_controller
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rails/generators/abstract_generator"
3
+ require "generators/view_component/abstract_generator"
4
4
 
5
- module Rails
5
+ module ViewComponent
6
6
  module Generators
7
7
  class ComponentGenerator < Rails::Generators::NamedBase
8
8
  include ViewComponent::AbstractGenerator
@@ -12,6 +12,7 @@ module Rails
12
12
  argument :attributes, type: :array, default: [], banner: "attribute"
13
13
  check_class_collision suffix: "Component"
14
14
 
15
+ class_option :call, type: :boolean, default: false
15
16
  class_option :inline, type: :boolean, default: false
16
17
  class_option :locale, type: :boolean, default: ViewComponent::Base.config.generate.locale
17
18
  class_option :parent, type: :string, desc: "The parent class for the generated component"
@@ -42,7 +43,11 @@ module Rails
42
43
  def parent_class
43
44
  return options[:parent] if options[:parent]
44
45
 
45
- ViewComponent::Base.config.component_parent_class || default_parent_class
46
+ ViewComponent::Base.config.generate.parent_class || default_parent_class
47
+ end
48
+
49
+ def initialize_signature?
50
+ initialize_signature.present?
46
51
  end
47
52
 
48
53
  def initialize_signature
@@ -56,9 +61,17 @@ module Rails
56
61
  end
57
62
 
58
63
  def initialize_call_method_for_inline?
64
+ options["call"]
65
+ end
66
+
67
+ def inline_template?
59
68
  options["inline"]
60
69
  end
61
70
 
71
+ def template_engine
72
+ options["template_engine"]
73
+ end
74
+
62
75
  def default_parent_class
63
76
  defined?(ApplicationComponent) ? ApplicationComponent : ViewComponent::Base
64
77
  end
@@ -2,7 +2,12 @@
2
2
 
3
3
  <% module_namespacing do -%>
4
4
  class <%= class_name %><%= options[:skip_suffix] ? "" : "Component" %> < <%= parent_class %>
5
- <%- if initialize_signature -%>
5
+ <%- if inline_template? -%>
6
+ <%= template_engine %>_template <<~<%= template_engine.upcase %>
7
+ <h1>Hello, World!</h1>
8
+ <%= template_engine.upcase %>
9
+ <%- end -%>
10
+ <%- if initialize_signature? -%>
6
11
  def initialize(<%= initialize_signature %>)
7
12
  <%= initialize_body %>
8
13
  end
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rails/generators/erb"
4
- require "rails/generators/abstract_generator"
4
+ require "generators/view_component/abstract_generator"
5
5
 
6
- module Erb
6
+ module ViewComponent
7
7
  module Generators
8
- class ComponentGenerator < Base
8
+ class ErbGenerator < Rails::Generators::NamedBase
9
9
  include ViewComponent::AbstractGenerator
10
10
 
11
11
  source_root File.expand_path("templates", __dir__)
12
12
  class_option :sidecar, type: :boolean, default: false
13
13
  class_option :inline, type: :boolean, default: false
14
+ class_option :call, type: :boolean, default: false
14
15
  class_option :stimulus, type: :boolean, default: false
15
16
 
16
17
  def engine_name
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rails/generators/erb/component_generator"
3
+ require "generators/view_component/erb/erb_generator"
4
4
 
5
- module Haml
5
+ module ViewComponent
6
6
  module Generators
7
- class ComponentGenerator < Erb::Generators::ComponentGenerator
7
+ class HamlGenerator < ViewComponent::Generators::ErbGenerator
8
8
  include ViewComponent::AbstractGenerator
9
9
 
10
10
  source_root File.expand_path("templates", __dir__)