view_component 4.17.0 → 4.24.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/app/views/test_mailer/test_multipart_email.html.erb +1 -0
- data/app/views/test_mailer/test_multipart_email.text.erb +1 -0
- data/docs/CHANGELOG.md +234 -0
- data/lib/generators/view_component/abstract_generator.rb +24 -4
- data/lib/generators/view_component/component/component_generator.rb +8 -6
- data/lib/generators/view_component/component/templates/component.rb.tt +1 -1
- data/lib/generators/view_component/erb/erb_generator.rb +2 -2
- data/lib/generators/view_component/haml/haml_generator.rb +1 -1
- data/lib/generators/view_component/locale/locale_generator.rb +2 -6
- data/lib/generators/view_component/preview/preview_generator.rb +9 -6
- data/lib/generators/view_component/preview/templates/component_preview.rb.tt +2 -2
- data/lib/generators/view_component/rspec/rspec_generator.rb +1 -1
- data/lib/generators/view_component/rspec/templates/component_spec.rb.tt +1 -1
- data/lib/generators/view_component/slim/slim_generator.rb +1 -1
- data/lib/generators/view_component/stimulus/stimulus_generator.rb +3 -7
- data/lib/generators/view_component/test_unit/templates/component_test.rb.tt +2 -2
- data/lib/generators/view_component/test_unit/test_unit_generator.rb +8 -7
- data/lib/view_component/base.rb +169 -94
- data/lib/view_component/cache_digest/dependency_tracking.rb +43 -11
- data/lib/view_component/cache_digest/digestor_lookup.rb +77 -0
- data/lib/view_component/cache_digest/resolver.rb +163 -65
- data/lib/view_component/cache_digest.rb +384 -75
- data/lib/view_component/{experimentally_cacheable.rb → cacheable.rb} +50 -127
- data/lib/view_component/collection.rb +4 -9
- data/lib/view_component/compile_cache.rb +63 -3
- data/lib/view_component/compiler.rb +86 -15
- data/lib/view_component/config.rb +114 -8
- data/lib/view_component/engine.rb +18 -6
- data/lib/view_component/errors.rb +16 -0
- data/lib/view_component/request_details.rb +5 -10
- data/lib/view_component/slot.rb +17 -0
- data/lib/view_component/slotable.rb +32 -8
- data/lib/view_component/template.rb +38 -16
- data/lib/view_component/test_helpers.rb +39 -15
- data/lib/view_component/translatable.rb +35 -1
- data/lib/view_component/version.rb +1 -1
- data/lib/view_component.rb +1 -1
- metadata +10 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3c6a2ef3282bf3383716c47d113e3a9ed1dccc6aee4f643080aedece5961445a
|
|
4
|
+
data.tar.gz: ad941d4a4ca2b8e155dff3bd2ed52a0213d6bfc808c65abc67e5d2e069d300e7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed286a2767cb14109d867255023c4feb6945288cc2dd4351c64ffa03203a89702a8ca75b7a79cd68c64ebc7b9e96a1a2e81e7445f61fc975ce06311c4a47d872
|
|
7
|
+
data.tar.gz: 9893da43af8559c0aee6226b4d0dd2fa96f32ec41b1fc60b14106e0d689666a5a1833af99da1cf72d568ef8a85b79854a3bbe4ef198128d9dde35c0f86cea24a
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render MultipartMailerComponent.new %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render MultipartMailerComponent.new %>
|
data/docs/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,240 @@ nav_order: 6
|
|
|
10
10
|
|
|
11
11
|
## main
|
|
12
12
|
|
|
13
|
+
## 4.24.0
|
|
14
|
+
|
|
15
|
+
* Harden GitHub Actions workflows and dependency updates to address code-scanning alerts.
|
|
16
|
+
|
|
17
|
+
*Joel Hawksley*
|
|
18
|
+
|
|
19
|
+
* Check component templates for changes from the Rails reloader instead of every executor run, avoiding filesystem scans for Action Cable broadcasts and other executor-only work.
|
|
20
|
+
|
|
21
|
+
*Joel Hawksley*
|
|
22
|
+
|
|
23
|
+
* Avoid missing-template digest errors for namespaced component renders when using Rails' regex ERB dependency tracker.
|
|
24
|
+
|
|
25
|
+
*Joel Hawksley*
|
|
26
|
+
|
|
27
|
+
* Raise `NoMethodError` on the slot instead of on `nil` when calling an undefined method on a slot without a component, including methods only `nil` defines such as `to_a` or `=~`, which used to return `nil`'s result.
|
|
28
|
+
|
|
29
|
+
*Clément Joubert*
|
|
30
|
+
|
|
31
|
+
* Update both Rails main builds to the same Rails commit through a weekly automated pull request.
|
|
32
|
+
|
|
33
|
+
*Joel Hawksley*
|
|
34
|
+
|
|
35
|
+
* Update Nokogiri to 1.19.5 for compatibility with Rails main.
|
|
36
|
+
|
|
37
|
+
*Joel Hawksley*
|
|
38
|
+
|
|
39
|
+
* Fix missing-template errors and request URL restoration with Rails main.
|
|
40
|
+
|
|
41
|
+
*Joel Hawksley*
|
|
42
|
+
|
|
43
|
+
* Keep compensating ERB line numbers for the annotation newline on future major Rails versions. The version check required a minor version above 0, so it would have stopped compensating on the next major's `.0` release.
|
|
44
|
+
|
|
45
|
+
*Clément Joubert*
|
|
46
|
+
|
|
47
|
+
## 4.23.0
|
|
48
|
+
|
|
49
|
+
* Restore request-dependent URL generation when using `render_preview` inside `with_request_url`.
|
|
50
|
+
|
|
51
|
+
*Joel Hawksley*
|
|
52
|
+
|
|
53
|
+
* Speed up cold cache digests by skipping the `# Template Dependency:` scan for sources that declare none, and by not translating class names in synthetic templates, which only declare paths.
|
|
54
|
+
|
|
55
|
+
*Erik Axel Nielsen*
|
|
56
|
+
|
|
57
|
+
## 4.22.0
|
|
58
|
+
|
|
59
|
+
* Comment on release pull requests with benchmark results compared to the previous release.
|
|
60
|
+
|
|
61
|
+
*Joel Hawksley*
|
|
62
|
+
|
|
63
|
+
* Reduce source-file reads and dependency-scanning allocations during cold cache digests and boot-time precomputation.
|
|
64
|
+
|
|
65
|
+
*Joel Hawksley*
|
|
66
|
+
|
|
67
|
+
* Share sidecar directory listings and source reads during cold cache digests, and hash shared Ruby and sidecar files once per digest computation or boot-time precomputation.
|
|
68
|
+
|
|
69
|
+
*Joel Hawksley*
|
|
70
|
+
|
|
71
|
+
* Avoid missing-template digest errors for unresolvable interpolated render paths in components and included helpers.
|
|
72
|
+
|
|
73
|
+
*Joel Hawksley*
|
|
74
|
+
|
|
75
|
+
* Cover shared helper dependencies in the boot benchmark and add a cold cache digest benchmark to the CI performance check.
|
|
76
|
+
|
|
77
|
+
*Joel Hawksley*
|
|
78
|
+
|
|
79
|
+
* Speed up cache digests of components that render shared dependencies, such as a helper module included by most components. The Digestor looks a template up once per edge of the tree rather than once per component, so each synthetic template was rebuilt, and its sources re-parsed, for every place it was rendered from, and every component digested at boot rebuilt the tree of everything it renders. Templates, dependencies and parsed sources are now shared within one digest computation and across boot-time precomputation, and dependencies whose digest is already known are no longer walked again. On an app with 1,547 components, one cold digest drops from 70 s to 0.5 s and boot-time precomputation from 144 s to 13 s, with identical digests.
|
|
80
|
+
|
|
81
|
+
*Erik Axel Nielsen*
|
|
82
|
+
|
|
83
|
+
## 4.21.0
|
|
84
|
+
|
|
85
|
+
* Avoid `NameError` during eager loading when components include modules with temporary names.
|
|
86
|
+
|
|
87
|
+
*Joel Hawksley*
|
|
88
|
+
|
|
89
|
+
* Avoid repeated scanning of unterminated ERB tags during cache dependency discovery.
|
|
90
|
+
|
|
91
|
+
*Joel Hawksley*
|
|
92
|
+
|
|
93
|
+
* Skip dependency compilation for static ERB markup and literal templates while preserving helper-rendered component tracking.
|
|
94
|
+
|
|
95
|
+
*Joel Hawksley*
|
|
96
|
+
|
|
97
|
+
* Track helper-rendered component cache dependencies, enforce single-use instances on cache hits, and emit one render notification per self-cached render.
|
|
98
|
+
|
|
99
|
+
*Joel Hawksley*
|
|
100
|
+
|
|
101
|
+
* Resolve symbolic translation defaults in sidecars, restore request URL state in tests, and refresh inherited templates whenever template reloading is enabled.
|
|
102
|
+
|
|
103
|
+
*Joel Hawksley*
|
|
104
|
+
|
|
105
|
+
* Reuse existing GitHub releases when retrying a failed gem publish.
|
|
106
|
+
|
|
107
|
+
*Joel Hawksley*
|
|
108
|
+
|
|
109
|
+
* Prevent self-cache key collisions and track component references in views and format-specific partial dependencies.
|
|
110
|
+
|
|
111
|
+
*Joel Hawksley*
|
|
112
|
+
|
|
113
|
+
* Isolate preview and request parameters, honor preview locale callbacks, restore controller view contexts, and accept nil translation keys.
|
|
114
|
+
|
|
115
|
+
*Joel Hawksley*
|
|
116
|
+
|
|
117
|
+
* Honor negative generator flags and preserve pre-release versions throughout release automation. Report gem publishing failures.
|
|
118
|
+
|
|
119
|
+
*Joel Hawksley*
|
|
120
|
+
|
|
121
|
+
* Fix fragment cache collisions after `render_parent`, missing relative-partial and inherited-template dependencies, format fallback cache collisions, and stale cached output after development template edits.
|
|
122
|
+
|
|
123
|
+
*Joel Hawksley*
|
|
124
|
+
|
|
125
|
+
* Fix template method collisions between formats and variants, preserve default slot state, and copy collection spacer slots independently.
|
|
126
|
+
|
|
127
|
+
*Joel Hawksley*
|
|
128
|
+
|
|
129
|
+
* Apply `--skip-suffix` to all generated component files and restore full request URLs after `with_request_url` blocks.
|
|
130
|
+
|
|
131
|
+
*Joel Hawksley*
|
|
132
|
+
|
|
133
|
+
* Reset the assertion page when rendering a preview so assertions inspect the latest output.
|
|
134
|
+
|
|
135
|
+
*Joel Hawksley*
|
|
136
|
+
|
|
137
|
+
* Rediscover templates after development changes, including added or removed variants and parent templates.
|
|
138
|
+
|
|
139
|
+
*Joel Hawksley*
|
|
140
|
+
|
|
141
|
+
* Include all requested variants in output cache keys, preserving fallback order.
|
|
142
|
+
|
|
143
|
+
*Joel Hawksley*
|
|
144
|
+
|
|
145
|
+
* Resolve cache dependencies in their Ruby lexical namespaces and component template scopes.
|
|
146
|
+
|
|
147
|
+
*Joel Hawksley*
|
|
148
|
+
|
|
149
|
+
* Keep default slot configuration isolated between parent components and subclasses.
|
|
150
|
+
|
|
151
|
+
*Joel Hawksley*
|
|
152
|
+
|
|
153
|
+
* Preserve the calling view's translation scope when a component returns cached output or rejects content.
|
|
154
|
+
|
|
155
|
+
*Joel Hawksley*
|
|
156
|
+
|
|
157
|
+
* Reduce rendering and collection overhead, and speed up eager loading by sharing template-path parsing and avoiding redundant template and ancestor checks.
|
|
158
|
+
|
|
159
|
+
*Joel Hawksley*
|
|
160
|
+
|
|
161
|
+
* Speed up eager loading by sharing source-file reads between template compilation and cache digest precomputation, and reduce nested-render and default-slot lookup overhead.
|
|
162
|
+
|
|
163
|
+
*Joel Hawksley*
|
|
164
|
+
|
|
165
|
+
* Speed up eager loading by sharing sidecar directory listings during compilation, and reduce per-render state reset overhead.
|
|
166
|
+
|
|
167
|
+
*Joel Hawksley*
|
|
168
|
+
|
|
169
|
+
* Ignore unresolved partial dependencies inferred from dynamic renders, such as `render UI.button`, without requiring configuration for component facades. Real partials and explicit dependencies are preserved.
|
|
170
|
+
|
|
171
|
+
*Joel Hawksley*
|
|
172
|
+
|
|
173
|
+
* Raise `ViewComponent::UnknownConfigOptionError` when setting a `config.view_component` option that doesn't exist, rather than ignoring it. This includes options renamed or removed in 4.0, such as `preview_controller` (now `previews.controller`), and the error names the replacement. Replacing `previews` or `generate` with a hash preserves this validation, including through Hash mutation methods such as `merge!`, `update`, `store`, and `replace`.
|
|
174
|
+
|
|
175
|
+
*Fiona Burcombe*
|
|
176
|
+
|
|
177
|
+
## 4.20.0
|
|
178
|
+
|
|
179
|
+
* Fix `invalid byte sequence in UTF-8` errors when precomputing cache digests for components loaded from encrypted or binary source files.
|
|
180
|
+
|
|
181
|
+
*Joel Junström*
|
|
182
|
+
|
|
183
|
+
* Fix cache digests missing components rendered through a slot declared with the component's class, through a method or variable that holds the component, or through a module the component includes. Any constant naming a component in a component's Ruby or templates now counts as a dependency, and included modules are digested like superclasses.
|
|
184
|
+
|
|
185
|
+
*Erik Axel Nielsen*
|
|
186
|
+
|
|
187
|
+
* Add an informational CI check that runs added and modified tests without a pull request's implementation changes to identify regression coverage.
|
|
188
|
+
|
|
189
|
+
*Joel Hawksley*
|
|
190
|
+
|
|
191
|
+
* Speed up rendering with direct compiled-template calls and avoid intermediate method allocations when invoking lambda-backed slots.
|
|
192
|
+
|
|
193
|
+
*Joel Hawksley*
|
|
194
|
+
|
|
195
|
+
* Fix `Couldn't find template for digesting` errors when computing cache digests for templates that render components. Action View inferred a partial from `render SomeComponent.new`, so partials inferred from component renders are now discarded. Component renders are found with Prism rather than a regular expression, adding a dependency on the `prism` gem.
|
|
196
|
+
|
|
197
|
+
*Joel Hawksley*
|
|
198
|
+
|
|
199
|
+
* Fix components rendering the template for the first format a lookup context rendered in, instead of the current one. An Action Mailer email that declares `format.text` before `format.html` rendered the text template of each component into its HTML part. Components now reuse the details key Action View memoizes, which Action View resets whenever a detail such as `formats` changes. Regression from 4.16.0.
|
|
200
|
+
|
|
201
|
+
*Jan Schilbach*
|
|
202
|
+
|
|
203
|
+
* Look up each component's sidecar templates and translations once while eager loading, instead of again when it compiles, loads its translations, and computes its cache digest, and for each of its subclasses. Time spent in ViewComponent during the boot benchmark drops by about a quarter.
|
|
204
|
+
|
|
205
|
+
*Clément Joubert*
|
|
206
|
+
|
|
207
|
+
* Measure cache digest precomputation in the boot benchmark by disabling class reloading in the benchmark app and having each generated component render another.
|
|
208
|
+
|
|
209
|
+
*Joel Hawksley*
|
|
210
|
+
|
|
211
|
+
* Add a CI performance check that fails a pull request when any benchmark scenario's component/partial render-time ratio, or ViewComponent's share of app boot time, regresses by more than 5% against the base branch on Rails 8.1 or Rails main.
|
|
212
|
+
|
|
213
|
+
*Joel Hawksley*
|
|
214
|
+
|
|
215
|
+
* Fail the test suite when a gem in the Gemfile or gemspec isn't loaded.
|
|
216
|
+
|
|
217
|
+
*Joel Hawksley*
|
|
218
|
+
|
|
219
|
+
* Remove the unused `selenium-webdriver` and `tailwindcss-rails` development dependencies.
|
|
220
|
+
|
|
221
|
+
*Joel Hawksley*
|
|
222
|
+
|
|
223
|
+
* Speed up `sidecar_files`, which 4.18's cache digest precomputation calls for every component and superclass at boot, by globbing each directory once instead of once per extension. On an app with 302 components, `compile.view_component` drops from 2.3 s to 1.2 s.
|
|
224
|
+
|
|
225
|
+
*Clément Joubert*
|
|
226
|
+
|
|
227
|
+
## 4.19.0
|
|
228
|
+
|
|
229
|
+
* Remove the unused `concurrent-ruby` dependency. `require "concurrent-ruby"` loaded every concurrent-ruby class at boot, a leftover from the `Concurrent::ReadWriteLock` the compiler no longer uses.
|
|
230
|
+
|
|
231
|
+
*Clément Joubert*
|
|
232
|
+
|
|
233
|
+
* Fix every request raising `NoMethodError` in development when an autoload path is a `Pathname`, as engines such as Madmin add. The template watcher now passes the autoload paths to the file watcher as strings.
|
|
234
|
+
|
|
235
|
+
*Anthony Veaudry*
|
|
236
|
+
|
|
237
|
+
* Fix the template annotations integration test failing when it ran after the coverage compile tests, which left components compiled without the annotation in the test cache.
|
|
238
|
+
|
|
239
|
+
*Anthony Veaudry*
|
|
240
|
+
|
|
241
|
+
## 4.18.0
|
|
242
|
+
|
|
243
|
+
* Enable caching support for all components by default, and rename `ViewComponent::ExperimentallyCacheable` to `ViewComponent::Cacheable`. Including the module is no longer necessary. Breaking: remove existing `include ViewComponent::ExperimentallyCacheable` lines. Caching is no longer experimental.
|
|
244
|
+
|
|
245
|
+
*Erik Axel Nielsen, Joel Hawksley*
|
|
246
|
+
|
|
13
247
|
## 4.17.0
|
|
14
248
|
|
|
15
249
|
* Only register the executor hook that watches component templates when Action View doesn't cache templates at boot. With template caching on, as in production, the hook did nothing but still read `ActionView::Base.cache_template_loading` on every request. That value lives in a class variable, which non-main Ractors can't read on Ruby 4.0, so under Rails' experimental `Rails.application.ractorize!` every request failed.
|
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
module ViewComponent
|
|
4
4
|
module AbstractGenerator
|
|
5
|
+
def self.included(generator)
|
|
6
|
+
generator.class_option :skip_suffix, type: :boolean, default: false
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def initialize(...)
|
|
10
|
+
super
|
|
11
|
+
generate = ViewComponent::Base.config.generate
|
|
12
|
+
defaults = {
|
|
13
|
+
"sidecar" => generate.sidecar,
|
|
14
|
+
"stimulus" => generate.stimulus_controller,
|
|
15
|
+
"typescript" => generate.typescript
|
|
16
|
+
}.slice(*self.class.class_options.keys.map(&:to_s))
|
|
17
|
+
# Resolve defaults once so hooks inherit explicit false values as well.
|
|
18
|
+
self.options = options.class.new(defaults.merge(options)).freeze
|
|
19
|
+
end
|
|
20
|
+
|
|
5
21
|
def copy_view_file
|
|
6
22
|
template("component.html.#{engine_name}", destination) unless options["inline"] || options["call"]
|
|
7
23
|
end
|
|
@@ -21,7 +37,11 @@ module ViewComponent
|
|
|
21
37
|
end
|
|
22
38
|
|
|
23
39
|
def destination_file_name
|
|
24
|
-
"#{file_name}_component"
|
|
40
|
+
"#{file_name}#{"_component" unless options[:skip_suffix]}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def component_class_name
|
|
44
|
+
"#{class_name}#{"Component" unless options[:skip_suffix]}"
|
|
25
45
|
end
|
|
26
46
|
|
|
27
47
|
def file_name
|
|
@@ -42,15 +62,15 @@ module ViewComponent
|
|
|
42
62
|
end
|
|
43
63
|
|
|
44
64
|
def sidecar?
|
|
45
|
-
options["sidecar"]
|
|
65
|
+
options["sidecar"]
|
|
46
66
|
end
|
|
47
67
|
|
|
48
68
|
def stimulus?
|
|
49
|
-
options["stimulus"]
|
|
69
|
+
options["stimulus"]
|
|
50
70
|
end
|
|
51
71
|
|
|
52
72
|
def typescript?
|
|
53
|
-
options["typescript"]
|
|
73
|
+
options["typescript"]
|
|
54
74
|
end
|
|
55
75
|
end
|
|
56
76
|
end
|
|
@@ -10,20 +10,22 @@ module ViewComponent
|
|
|
10
10
|
source_root File.expand_path("templates", __dir__)
|
|
11
11
|
|
|
12
12
|
argument :attributes, type: :array, default: [], banner: "attribute"
|
|
13
|
-
check_class_collision suffix: "Component"
|
|
14
13
|
|
|
15
14
|
class_option :call, type: :boolean, default: false
|
|
16
15
|
class_option :inline, type: :boolean, default: false
|
|
17
16
|
class_option :locale, type: :boolean, default: ViewComponent::Base.config.generate.locale
|
|
18
17
|
class_option :parent, type: :string, desc: "The parent class for the generated component"
|
|
19
18
|
class_option :preview, type: :boolean, default: ViewComponent::Base.config.generate.preview
|
|
20
|
-
class_option :sidecar, type: :boolean
|
|
21
|
-
class_option :stimulus, type: :boolean
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
class_option :sidecar, type: :boolean
|
|
20
|
+
class_option :stimulus, type: :boolean
|
|
21
|
+
class_option :typescript, type: :boolean
|
|
22
|
+
|
|
23
|
+
def check_class_collision
|
|
24
|
+
class_collisions component_class_name
|
|
25
|
+
end
|
|
24
26
|
|
|
25
27
|
def create_component_file
|
|
26
|
-
template "component.rb", File.join(component_path, class_path, "#{
|
|
28
|
+
template "component.rb", File.join(component_path, class_path, "#{destination_file_name}.rb")
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
hook_for :test_framework
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
<% module_namespacing do -%>
|
|
4
|
-
class <%=
|
|
4
|
+
class <%= component_class_name %> < <%= parent_class %>
|
|
5
5
|
<%- if inline_template? -%>
|
|
6
6
|
<%= template_engine %>_template <<~<%= template_engine.upcase %>
|
|
7
7
|
<h1>Hello, World!</h1>
|
|
@@ -9,10 +9,10 @@ module ViewComponent
|
|
|
9
9
|
include ViewComponent::AbstractGenerator
|
|
10
10
|
|
|
11
11
|
source_root File.expand_path("templates", __dir__)
|
|
12
|
-
class_option :sidecar, type: :boolean
|
|
12
|
+
class_option :sidecar, type: :boolean
|
|
13
13
|
class_option :inline, type: :boolean, default: false
|
|
14
14
|
class_option :call, type: :boolean, default: false
|
|
15
|
-
class_option :stimulus, type: :boolean
|
|
15
|
+
class_option :stimulus, type: :boolean
|
|
16
16
|
|
|
17
17
|
def engine_name
|
|
18
18
|
"erb"
|
|
@@ -9,7 +9,7 @@ module ViewComponent
|
|
|
9
9
|
|
|
10
10
|
source_root File.expand_path("templates", __dir__)
|
|
11
11
|
argument :attributes, type: :array, default: [], banner: "attribute"
|
|
12
|
-
class_option :sidecar, type: :boolean
|
|
12
|
+
class_option :sidecar, type: :boolean
|
|
13
13
|
|
|
14
14
|
def create_locale_file
|
|
15
15
|
if ViewComponent::Base.config.generate.distinct_locale_files
|
|
@@ -35,11 +35,7 @@ module ViewComponent
|
|
|
35
35
|
|
|
36
36
|
def destination(locale = nil)
|
|
37
37
|
extension = ".#{locale}" if locale
|
|
38
|
-
|
|
39
|
-
File.join(component_path, class_path, "#{file_name}_component", "#{file_name}_component#{extension}.yml")
|
|
40
|
-
else
|
|
41
|
-
File.join(component_path, class_path, "#{file_name}_component#{extension}.yml")
|
|
42
|
-
end
|
|
38
|
+
File.join(destination_directory, "#{destination_file_name}#{extension}.yml")
|
|
43
39
|
end
|
|
44
40
|
end
|
|
45
41
|
end
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "generators/view_component/abstract_generator"
|
|
4
|
+
|
|
3
5
|
module ViewComponent
|
|
4
6
|
module Generators
|
|
5
7
|
class PreviewGenerator < ::Rails::Generators::NamedBase
|
|
8
|
+
include ViewComponent::AbstractGenerator
|
|
9
|
+
|
|
6
10
|
source_root File.expand_path("templates", __dir__)
|
|
7
11
|
class_option :preview_path, type: :string, desc: "Path for previews, required when multiple preview paths are configured", default: ViewComponent::Base.config.generate.preview_path
|
|
8
12
|
|
|
9
13
|
argument :attributes, type: :array, default: [], banner: "attribute"
|
|
10
|
-
|
|
14
|
+
|
|
15
|
+
def check_class_collision
|
|
16
|
+
class_collisions "#{component_class_name}Preview"
|
|
17
|
+
end
|
|
11
18
|
|
|
12
19
|
def create_preview_file
|
|
13
20
|
preview_paths = ViewComponent::Base.config.previews.paths
|
|
@@ -20,15 +27,11 @@ module ViewComponent
|
|
|
20
27
|
preview_paths.one? ? preview_paths.first : "test/components/previews"
|
|
21
28
|
end
|
|
22
29
|
|
|
23
|
-
template "component_preview.rb", File.join(path_prefix, class_path, "#{
|
|
30
|
+
template "component_preview.rb", File.join(path_prefix, class_path, "#{destination_file_name}_preview.rb")
|
|
24
31
|
end
|
|
25
32
|
|
|
26
33
|
private
|
|
27
34
|
|
|
28
|
-
def file_name
|
|
29
|
-
@_file_name ||= super.sub(/_component\z/i, "")
|
|
30
|
-
end
|
|
31
|
-
|
|
32
35
|
def render_signature
|
|
33
36
|
return if attributes.blank?
|
|
34
37
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
<% module_namespacing do -%>
|
|
4
|
-
class <%=
|
|
4
|
+
class <%= component_class_name %>Preview < ViewComponent::Preview
|
|
5
5
|
def default
|
|
6
|
-
render(<%=
|
|
6
|
+
render(<%= component_class_name %>.new<%= "(#{render_signature})" if render_signature %>)
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
<% end -%>
|
|
@@ -10,7 +10,7 @@ module ViewComponent
|
|
|
10
10
|
source_root File.expand_path("templates", __dir__)
|
|
11
11
|
|
|
12
12
|
def create_test_file
|
|
13
|
-
template "component_spec.rb", File.join(spec_component_path, class_path, "#{
|
|
13
|
+
template "component_spec.rb", File.join(spec_component_path, class_path, "#{destination_file_name}_spec.rb")
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
private
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "rails_helper"
|
|
4
4
|
|
|
5
|
-
RSpec.describe <%= namespaced? ? "#{namespace.name}::" : '' %><%=
|
|
5
|
+
RSpec.describe <%= namespaced? ? "#{namespace.name}::" : '' %><%= component_class_name %>, type: :component do
|
|
6
6
|
pending "add some examples to (or delete) #{__FILE__}"
|
|
7
7
|
|
|
8
8
|
# it "renders something useful" do
|
|
@@ -8,8 +8,8 @@ module ViewComponent
|
|
|
8
8
|
include ViewComponent::AbstractGenerator
|
|
9
9
|
|
|
10
10
|
source_root File.expand_path("templates", __dir__)
|
|
11
|
-
class_option :sidecar, type: :boolean
|
|
12
|
-
class_option :typescript, type: :boolean
|
|
11
|
+
class_option :sidecar, type: :boolean
|
|
12
|
+
class_option :typescript, type: :boolean
|
|
13
13
|
|
|
14
14
|
def create_stimulus_controller
|
|
15
15
|
template "component_controller.#{filetype}", destination
|
|
@@ -28,11 +28,7 @@ module ViewComponent
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def destination
|
|
31
|
-
|
|
32
|
-
File.join(component_path, class_path, "#{file_name}_component", "#{file_name}_component_controller.#{filetype}")
|
|
33
|
-
else
|
|
34
|
-
File.join(component_path, class_path, "#{file_name}_component_controller.#{filetype}")
|
|
35
|
-
end
|
|
31
|
+
File.join(destination_directory, "#{destination_file_name}_controller.#{filetype}")
|
|
36
32
|
end
|
|
37
33
|
|
|
38
34
|
def legacy_stimulus?
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
require "test_helper"
|
|
4
4
|
|
|
5
|
-
class <%= namespaced? ? "#{namespace.name}::" : '' %><%=
|
|
5
|
+
class <%= namespaced? ? "#{namespace.name}::" : '' %><%= component_class_name %>Test < ViewComponent::TestCase
|
|
6
6
|
def test_component_renders_something_useful
|
|
7
7
|
# assert_equal(
|
|
8
8
|
# %(<span>Hello, components!</span>),
|
|
9
|
-
# render_inline(<%=
|
|
9
|
+
# render_inline(<%= component_class_name %>.new(message: "Hello, components!")).css("span").to_html
|
|
10
10
|
# )
|
|
11
11
|
end
|
|
12
12
|
end
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "generators/view_component/abstract_generator"
|
|
4
|
+
|
|
3
5
|
module ViewComponent
|
|
4
6
|
module Generators
|
|
5
7
|
class TestUnitGenerator < ::Rails::Generators::NamedBase
|
|
8
|
+
include ViewComponent::AbstractGenerator
|
|
9
|
+
|
|
6
10
|
source_root File.expand_path("templates", __dir__)
|
|
7
|
-
check_class_collision suffix: "ComponentTest"
|
|
8
11
|
|
|
9
|
-
def
|
|
10
|
-
|
|
12
|
+
def check_class_collision
|
|
13
|
+
class_collisions "#{component_class_name}Test"
|
|
11
14
|
end
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def file_name
|
|
16
|
-
@_file_name ||= super.sub(/_component\z/i, "")
|
|
16
|
+
def create_test_file
|
|
17
|
+
template "component_test.rb", File.join("test/components", class_path, "#{destination_file_name}_test.rb")
|
|
17
18
|
end
|
|
18
19
|
end
|
|
19
20
|
end
|