view_component 3.23.2 → 4.0.2

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 +422 -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 +178 -158
  21. data/lib/view_component/collection.rb +19 -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 +46 -43
  38. data/lib/view_component/translatable.rb +33 -32
  39. data/lib/view_component/version.rb +2 -2
  40. data/lib/view_component.rb +8 -6
  41. metadata +31 -559
  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: 05c8fa66735f8008894ba88d64885dc307bc71381e2b88391798fa4266da7279
4
+ data.tar.gz: f217babfa1c1894f377fff73fc3b603755122422c8596e349ffd0d8689e86708
5
5
  SHA512:
6
- metadata.gz: 311478a282f72c7b703594ec119dfc2686ec8cd3c6d6e97ff9fab9a32638e09eacefdc82a3808c581e48ab2af4cbfb26f66c7064cb614367cb4916fdf3b7df76
7
- data.tar.gz: 3c059cb40bfa81c45a60bc9d107be8402923f92f0a8e1b50c6cdfcad88a4da6407244f1e5220d58f59a938c3d77e748ec22f360b8cf49041279616138ac4397d
6
+ metadata.gz: a10d8362a64c181f11dd0aff69725eb7045a4a4cb546c2e960183bf416083dc8b5bcee76c807be3341dd01919eba3fdc2636083de2794101d8751f1c405396a1
7
+ data.tar.gz: 2ae8c40ff912472d16d27e3a92af772905d74b3ab010ced00578208ee281f53f59adc31bc0ef0b170cf1ea8c64cd0750db0c0804bb65deca11a33f430cc7012d
@@ -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,428 @@ nav_order: 6
10
10
 
11
11
  ## main
12
12
 
13
+ ## 4.0.2
14
+
15
+ * Share the view context in tests to prevent out-of-order rendering issues for certain advanced use-cases, eg. testing instances of Rails' `FormBuilder`.
16
+ * Fix double rendering issue for partials that yield.
17
+
18
+ *Cameron Dutro*
19
+
20
+ ## 4.0.1
21
+
22
+ * Setup Trusted Publishing to RubyGems to improve software supply chain safety.
23
+
24
+ *Hans Lemuet*
25
+
26
+ * Conditionally add the `ViewComponent::Base#format` method back for Rails 7.1 only.
27
+ * Compute and check lockfiles into source control.
28
+ * Constrain Rails versions in gemfiles to only allow the patch version to vary, eg. `~> 7.1.0` instead of `~> 7.1`.
29
+
30
+ *Cameron Dutro*
31
+
32
+ ## 4.0.0
33
+
34
+ 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.
35
+
36
+ Please report any issues at [https://github.com/ViewComponent/view_component/issues](https://github.com/ViewComponent/view_component/issues).
37
+
38
+ ### Breaking changes (production)
39
+
40
+ * 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.
41
+ * Require [non-EOL](https://endoflife.date/rails) Rails (`>= 7.1.0`) and Ruby (`>= 3.2.0`).
42
+ * Remove `render_component` and `render` monkey patch configured with `render_monkey_patch_enabled`.
43
+ * Remove deprecated `use_helper(s)`. Use `include MyHelper` or `helpers.` proxy instead.
44
+ * Support compatibility with `Dry::Initializer`. As a result, `EmptyOrInvalidInitializerError` will no longer be raised.
45
+ * 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.
46
+ * Remove `use_deprecated_instrumentation_name` configuration option. Events will always use `render.view_component` name.
47
+ * Remove unnecessary `#format` methods that returned `nil`.
48
+ * Remove support for variant names containing `.` to be consistent with Rails.
49
+ * 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.
50
+ * Use ActionView's `lookup_context` for picking templates instead of the request format.
51
+
52
+ 3.15 added support for using templates that match the request format, that is if `/resource.csv` is requested then
53
+ ViewComponents would pick `_component.csv.erb` over `_component.html.erb`.
54
+
55
+ 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.
56
+
57
+ ### Breaking changes (dev/test)
58
+
59
+ * Remove `config.view_component.test_controller` in favor of `vc_test_controller_class` test helper method.
60
+ * `config.view_component.component_parent_class` is now `config.view_component.generate.parent_class`, moving the generator-specific option to the generator configuration namespace.
61
+ * `config.view_component.view_component_path` is now `config.view_component.generate.path`, as components have long since been able to exist in any directory.
62
+ * Move previews-related configuration (`enabled`, `route`, `paths`, `default_layout`, `controller`) to under `previews` namespace.
63
+ * `--inline` generator option now generates inline template. Use `--call` to generate `#call` method.
64
+ * Remove broken integration with `rails stats` that ignored components outside of `app/components`.
65
+ * Remove `preview_source` functionality. Consider using [Lookbook](https://lookbook.build/) instead.
66
+ * Use `Nokogiri::HTML5` instead of `Nokogiri::HTML4` for test helpers.
67
+ * Move generators to a ViewComponent namespace.
68
+
69
+ Before, ViewComponent generators pollute the generator namespace with a bunch of top level items, and claim the generic "component" name.
70
+
71
+ Now, generators live in a "view_component" module/namespace, so what was before `rails g
72
+ component` is now `rails g view_component:component`.
73
+
74
+ ### New features
75
+
76
+ * Add `SystemSpecHelpers` for use with RSpec.
77
+ * Add support for including `Turbo::StreamsHelper`.
78
+ * Add template annotations for components with `def call`.
79
+ * Graduate `SlotableDefault` to be included by default.
80
+ * Add `#current_template` accessor and `Template#path` for diagnostic usage.
81
+ * Reduce string allocations during compilation.
82
+ * Add `around_render` lifecyle method for wrapping component rendering in custom instrumentation, etc.
83
+
84
+ ### Bug fixes
85
+
86
+ * Fix bug where virtual path wasn't reset, breaking translations outside of components.
87
+ * Fix bug where `config.view_component.previews.enabled` didn't function properly in production environments.
88
+ * Fix bug in `SlotableDefault` where default couldn't be overridden when content was passed as a block.
89
+ * Fix bug where request-aware helpers didn't work outside of the request context.
90
+ * `ViewComponentsSystemTestController` shouldn't be useable outside of test environment
91
+
92
+ ### Non-functional changes
93
+
94
+ * Remove unnecessary usage of `ruby2_keywords`.
95
+ * Remove unnecessary `respond_to` checks.
96
+ * Require MFA when publishing to RubyGems.
97
+ * Clean up project dependencies, relaxing versions of development gems.
98
+ * Add test case for absolute URL path helpers in mailers.
99
+ * Update documentation on performance to reflect more representative benchmark showing 2-3x speed increase over partials.
100
+ * Add documentation note about instrumentation negatively affecting performance.
101
+ * Remove unnecessary ENABLE_RELOADING test suite flag.
102
+ * `config.view_component.previews.default_layout` should default to nil.
103
+ * Add test coverage for uncovered code.
104
+ * Test against `turbo-rails` `v2` and `rspec-rails` `v7`.
105
+
106
+ ## 4.0.0.rc5
107
+
108
+ * 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:
109
+
110
+ ```ruby
111
+ respond_to do |f|
112
+ f.html_fragment do
113
+ render(MyComponent.new)
114
+ end
115
+ end
116
+ ```
117
+
118
+ *Joel Hawksley*
119
+
120
+ ## 4.0.0.rc4
121
+
122
+ * Fix issue where generators were not included in published gem.
123
+
124
+ *Jean-Louis Giordano*
125
+
126
+ ## 4.0.0.rc3
127
+
128
+ * Reformat the avatars section to arrange them in a grid.
129
+
130
+ *Josh Cohen*
131
+
132
+ * Fix bug where relative paths in `translate` didn't work in blocks passed to ViewComponents.
133
+
134
+ *Joel Hawksley*
135
+
136
+ * Add SerpApi to "Who uses ViewComponent" list.
137
+
138
+ *Andy from SerpApi*
139
+
140
+ ## 4.0.0.rc2
141
+
142
+ * Add `around_render` lifecyle method for wrapping component rendering in custom instrumentation, etc.
143
+
144
+ *Joel Hawksley*, *Blake Williams*
145
+
146
+ ## 4.0.0.rc1
147
+
148
+ 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.
149
+
150
+ Please report any issues at [https://github.com/ViewComponent/view_component/issues](https://github.com/ViewComponent/view_component/issues).
151
+
152
+ ### 4.0.0.rc1 Breaking changes (production)
153
+
154
+ * 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.
155
+ * Require [non-EOL](https://endoflife.date/rails) Rails (`>= 7.1.0`) and Ruby (`>= 3.2.0`).
156
+ * Remove `render_component` and `render` monkey patch configured with `render_monkey_patch_enabled`.
157
+ * Remove deprecated `use_helper(s)`. Use `include MyHelper` or `helpers.` proxy instead.
158
+ * Support compatibility with `Dry::Initializer`. As a result, `EmptyOrInvalidInitializerError` will no longer be raised.
159
+ * 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.
160
+ * Remove `use_deprecated_instrumentation_name` configuration option. Events will always use `render.view_component` name.
161
+ * Remove unnecessary `#format` methods that returned `nil`.
162
+ * Remove support for variant names containing `.` to be consistent with Rails.
163
+ * 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.
164
+ * Use ActionView's `lookup_context` for picking templates instead of the request format.
165
+
166
+ 3.15 added support for using templates that match the request format, that is if `/resource.csv` is requested then
167
+ ViewComponents would pick `_component.csv.erb` over `_component.html.erb`.
168
+
169
+ 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.
170
+
171
+ ### 4.0.0.rc1 Breaking changes (dev/test)
172
+
173
+ * Rename `config.generate.component_parent_class` to `config.generate.parent_class`.
174
+ * Remove `config.test_controller` in favor of `vc_test_controller_class` test helper method.
175
+ * `config.component_parent_class` is now `config.generate.component_parent_class`, moving the generator-specific option to the generator configuration namespace.
176
+ * Move previews-related configuration (`enabled`, `route`, `paths`, `default_layout`, `controller`) to under `previews` namespace.
177
+ * `config.view_component_path` is now `config.generate.path`, as components have long since been able to exist in any directory.
178
+ * `--inline` generator option now generates inline template. Use `--call` to generate `#call` method.
179
+ * Remove broken integration with `rails stats` that ignored components outside of `app/components`.
180
+ * Remove `preview_source` functionality. Consider using [Lookbook](https://lookbook.build/) instead.
181
+ * Use `Nokogiri::HTML5` instead of `Nokogiri::HTML4` for test helpers.
182
+ * Move generators to a ViewComponent namespace.
183
+
184
+ Before, ViewComponent generators pollute the generator namespace with a bunch of top level items, and claim the generic "component" name.
185
+
186
+ Now, generators live in a "view_component" module/namespace, so what was before `rails g
187
+ component` is now `rails g view_component:component`.
188
+
189
+ ### 4.0.0.rc1 New features
190
+
191
+ * Add `SystemSpecHelpers` for use with RSpec.
192
+ * Add support for including `Turbo::StreamsHelper`.
193
+ * Add template annotations for components with `def call`.
194
+ * Graduate `SlotableDefault` to be included by default.
195
+ * Add `#current_template` accessor and `Template#path` for diagnostic usage.
196
+ * Reduce string allocations during compilation.
197
+
198
+ ### 4.0.0.rc1 Bug fixes
199
+
200
+ * Fix bug where virtual path wasn't reset, breaking translations outside of components.
201
+ * Fix bug where `config.previews.enabled` didn't function properly in production environments.
202
+ * Fix bug where response format wasn't set, which caused issues with Turbo Frames.
203
+ * Fix bug in `SlotableDefault` where default couldn't be overridden when content was passed as a block.
204
+ * Fix bug where request-aware helpers didn't work outside of the request context.
205
+ * `ViewComponentsSystemTestController` shouldn't be useable outside of test environment
206
+
207
+ ### 4.0.0.rc1 Non-functional changes
208
+
209
+ * Remove unnecessary usage of `ruby2_keywords`.
210
+ * Remove unnecessary `respond_to` checks.
211
+ * Require MFA when publishing to RubyGems.
212
+ * Clean up project dependencies, relaxing versions of development gems.
213
+ * Add test case for absolute URL path helpers in mailers.
214
+ * Update documentation on performance to reflect more representative benchmark showing 2-3x speed increase over partials.
215
+ * Add documentation note about instrumentation negatively affecting performance.
216
+ * Remove unnecessary ENABLE_RELOADING test suite flag.
217
+ * `config.previews.default_layout` should default to nil.
218
+ * Add test coverage for uncovered code.
219
+ * Test against `turbo-rails` `v2` and `rspec-rails` `v7`.
220
+
221
+ ## 4.0.0.alpha7
222
+
223
+ * BREAKING: Remove deprecated `use_helper(s)`. Use `include MyHelper` or `helpers.` proxy instead.
224
+
225
+ *Joel Hawksley*
226
+
227
+ * BREAKING: Support compatibility with `Dry::Initializer`. As a result, `EmptyOrInvalidInitializerError` will no longer be raised.
228
+
229
+ *Joel Hawksley*
230
+
231
+ * BREAKING: Rename `config.generate.component_parent_class` to `config.generate.parent_class`.
232
+
233
+ *Joel Hawksley*
234
+
235
+ * Fix bug where `config.previews.enabled` didn't function properly in production environments.
236
+
237
+ *Joel Hawksley*
238
+
239
+ * `config.previews.default_layout` should default to nil.
240
+
241
+ *Joel Hawksley*
242
+
243
+ * Add test case for absolute URL path helpers in mailers.
244
+
245
+ *Joel Hawksley*
246
+
247
+ * Fix bug where response format wasn't set, which caused issues with Turbo Frames.
248
+
249
+ *Joel Hawksley*
250
+
251
+ ## 4.0.0.alpha6
252
+
253
+ * BREAKING: Remove `config.test_controller` in favor of `vc_test_controller_class` test helper method.
254
+
255
+ *Joel Hawksley*
256
+
257
+ * BREAKING: `config.component_parent_class` is now `config.generate.component_parent_class`, moving the generator-specific option to the generator configuration namespace.
258
+
259
+ *Joel Hawksley*
260
+
261
+ * BREAKING: Move previews-related configuration (`enabled`, `route`, `paths`, `default_layout`, `controller`) to under `previews` namespace.
262
+
263
+ *Joel Hawksley*
264
+
265
+ * Add template annotations for components with `def call`.
266
+
267
+ *Joel Hawksley*
268
+
269
+ * Add support for including Turbo::StreamsHelper.
270
+
271
+ *Stephen Nelson*
272
+
273
+ * Update documentation on performance to reflect more representative benchmark showing 2-3x speed increase over partials.
274
+
275
+ *Joel Hawksley*
276
+
277
+ * Add documentation note about instrumentation negatively affecting performance.
278
+
279
+ *Joel Hawksley*
280
+
281
+ * Revert object shapes optimization due to lack of evidence of improvement.
282
+
283
+ *Joel Hawksley*
284
+
285
+ ## 4.0.0.alpha5
286
+
287
+ * BREAKING: `config.view_component_path` is now `config.generate.path`, as components have long since been able to exist in any directory.
288
+
289
+ *Joel Hawksley*
290
+
291
+ * BREAKING: Remove broken integration with `rails stats` that ignored components outside of `app/components`.
292
+
293
+ *Joel Hawksley*
294
+
295
+ ## 4.0.0.alpha4
296
+
297
+ * 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.
298
+
299
+ *Joel Hawksley*
300
+
301
+ * Graduate `SlotableDefault` to be included by default.
302
+
303
+ *Joel Hawksley*
304
+
305
+ * Fix bug in `SlotableDefault` where default couldn't be overridden when content was passed as a block.
306
+
307
+ *Bill Watts*, *Joel Hawksley*
308
+
309
+ ## 4.0.0.alpha3
310
+
311
+ * BREAKING: Remove dependency on `ActionView::Base`, eliminating the need for capture compatibility patch.
312
+
313
+ *Cameron Dutro*
314
+
315
+ ## 4.0.0.alpha2
316
+
317
+ * Add `#current_template` accessor and `Template#path` for diagnostic usage.
318
+
319
+ *Joel Hawksley*
320
+
321
+ ## 4.0.0.alpha1
322
+
323
+ 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.
324
+
325
+ This release makes the following breaking changes:
326
+
327
+ * BREAKING: `--inline` generator option now generates inline template. Use `--call` to generate `#call` method.
328
+
329
+ *Joel Hawksley*
330
+
331
+ * BREAKING: Remove `use_deprecated_instrumentation_name` configuration option. Events will always use `render.view_component` name.
332
+
333
+ *Joel Hawksley*
334
+
335
+ * BREAKING: Remove `preview_source` functionality. Consider using [Lookbook](https://lookbook.build/) instead.
336
+
337
+ *Joel Hawksley*
338
+
339
+ * BREAKING: Use `Nokogiri::HTML5` instead of `Nokogiri::HTML4` for test helpers.
340
+
341
+ *Noah Silvera*, *Joel Hawksley*
342
+
343
+ * BREAKING: Move generators to a ViewComponent namespace.
344
+
345
+ Before, ViewComponent generators pollute the generator namespace with a bunch of top level items, and claim the generic "component" name.
346
+
347
+ Now, generators live in a "view_component" module/namespace, so what was before `rails g
348
+ component` is now `rails g view_component:component`.
349
+
350
+ *Paul Sadauskas*
351
+
352
+ * BREAKING: Require [non-EOL](https://endoflife.date/rails) Rails (`>= 7.1.0`).
353
+
354
+ *Joel Hawksley*
355
+
356
+ * BREAKING: Require [non-EOL](https://www.ruby-lang.org/en/downloads/branches/) Ruby (`>= 3.2.0`).
357
+
358
+ *Joel Hawksley*
359
+
360
+ * BREAKING: Remove `render_component` and `render` monkey patch configured with `render_monkey_patch_enabled`.
361
+
362
+ *Joel Hawksley*
363
+
364
+ * BREAKING: Remove support for variant names containing `.` to be consistent with Rails.
365
+
366
+ *Stephen Nelson*
367
+
368
+ * BREAKING: Use ActionView's `lookup_context` for picking templates instead of the request format.
369
+
370
+ 3.15 added support for using templates that match the request format, that is if `/resource.csv` is requested then
371
+ ViewComponents would pick `_component.csv.erb` over `_component.html.erb`.
372
+
373
+ With this release, the request format is no longer considered and instead ViewComponent will use the Rails logic
374
+ for picking the most appropriate template type, that is the csv template will be used if it matches the `Accept` header
375
+ or because the controller uses a `respond_to` block to pick the response format.
376
+
377
+ *Stephen Nelson*
378
+
379
+ * 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.
380
+
381
+ *Joel Hawksley*
382
+
383
+ * Fix bug where request-aware helpers didn't work outside of the request context.
384
+
385
+ *Joel Hawksley*, *Stephen Nelson*
386
+
387
+ * `ViewComponentsSystemTestController` shouldn't be useable outside of test environment
388
+
389
+ *Joel Hawksley*, *Stephen Nelson*
390
+
391
+ * Remove unnecessary ENABLE_RELOADING test suite flag.
392
+
393
+ *Joel Hawksley*
394
+
395
+ * Add test coverage for uncovered code.
396
+
397
+ *Joel Hawksley*
398
+
399
+ * Remove unnecessary `#format` methods that returned `nil`.
400
+
401
+ *Joel Hawksley*
402
+
403
+ * Clean up project dependencies, relaxing versions of development gems.
404
+
405
+ *Joel Hawksley*
406
+
407
+ * Test against `turbo-rails` `v2`.
408
+
409
+ *Joel Hawksley*
410
+
411
+ * Test against `rspec-rails` `v7`.
412
+
413
+ *Joel Hawksley*
414
+
415
+ * Remove unnecessary usage of `ruby2_keywords`.
416
+
417
+ *Joel Hawksley*
418
+
419
+ * Remove unnecessary `respond_to` checks.
420
+
421
+ *Tiago Menegaz*, *Joel Hawksley*
422
+
423
+ * Introduce component-local config and migrate `strip_trailing_whitespace` to use it under the hood.
424
+
425
+ *Simon Fish*
426
+
427
+ * Deprecate `use_helper(s)`. Use `include MyHelper` or `helpers.` proxy instead.
428
+
429
+ *Joel Hawksley*
430
+
431
+ * Reduce string allocations during compilation.
432
+
433
+ *Jonathan del Strother*
434
+
13
435
  ## 3.23.2
14
436
 
15
437
  * 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