view_component 4.20.0 → 4.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/CHANGELOG.md +120 -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 +110 -102
- data/lib/view_component/cache_digest/dependency_tracking.rb +25 -19
- data/lib/view_component/cache_digest/digestor_lookup.rb +47 -1
- data/lib/view_component/cache_digest/resolver.rb +73 -41
- data/lib/view_component/cache_digest.rb +221 -61
- data/lib/view_component/cacheable.rb +16 -18
- data/lib/view_component/collection.rb +4 -9
- data/lib/view_component/compile_cache.rb +51 -9
- data/lib/view_component/compiler.rb +50 -2
- data/lib/view_component/config.rb +114 -8
- data/lib/view_component/engine.rb +1 -2
- data/lib/view_component/errors.rb +16 -0
- data/lib/view_component/slot.rb +12 -0
- data/lib/view_component/slotable.rb +28 -4
- data/lib/view_component/template.rb +16 -3
- data/lib/view_component/test_helpers.rb +38 -16
- data/lib/view_component/translatable.rb +34 -0
- data/lib/view_component/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 347185365d72f04ae47e10751bdaafc79ca1b92a5cc60659464cd91ea3fe5b1d
|
|
4
|
+
data.tar.gz: 8cc35ca70babcf15504c6cf3329357045b92cf5bce0b7059a376b465b9d82b3a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f65ef1db7168f46ff4c0e41bcd7d329e30f5da9cfb05b06500c67686eaef0705b9b26433f644b39138c79ecf5d904176451c511f8dc48438cae9d9d6cbe81f8
|
|
7
|
+
data.tar.gz: 5b8df5a1f324a0fb481da6c822333e08e0bd424535310d851634da151702cb50a6a92d56be23f49f573c66aa5b9f9b8137a288969d85f4d5cec47ea59c114cca
|
data/docs/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,126 @@ nav_order: 6
|
|
|
10
10
|
|
|
11
11
|
## main
|
|
12
12
|
|
|
13
|
+
## 4.22.0
|
|
14
|
+
|
|
15
|
+
* Comment on release pull requests with benchmark results compared to the previous release.
|
|
16
|
+
|
|
17
|
+
*Joel Hawksley*
|
|
18
|
+
|
|
19
|
+
* Reduce source-file reads and dependency-scanning allocations during cold cache digests and boot-time precomputation.
|
|
20
|
+
|
|
21
|
+
*Joel Hawksley*
|
|
22
|
+
|
|
23
|
+
* 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.
|
|
24
|
+
|
|
25
|
+
*Joel Hawksley*
|
|
26
|
+
|
|
27
|
+
* Avoid missing-template digest errors for unresolvable interpolated render paths in components and included helpers.
|
|
28
|
+
|
|
29
|
+
*Joel Hawksley*
|
|
30
|
+
|
|
31
|
+
* Cover shared helper dependencies in the boot benchmark and add a cold cache digest benchmark to the CI performance check.
|
|
32
|
+
|
|
33
|
+
*Joel Hawksley*
|
|
34
|
+
|
|
35
|
+
* 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.
|
|
36
|
+
|
|
37
|
+
*Erik Axel Nielsen*
|
|
38
|
+
|
|
39
|
+
## 4.21.0
|
|
40
|
+
|
|
41
|
+
* Avoid `NameError` during eager loading when components include modules with temporary names.
|
|
42
|
+
|
|
43
|
+
*Joel Hawksley*
|
|
44
|
+
|
|
45
|
+
* Avoid repeated scanning of unterminated ERB tags during cache dependency discovery.
|
|
46
|
+
|
|
47
|
+
*Joel Hawksley*
|
|
48
|
+
|
|
49
|
+
* Skip dependency compilation for static ERB markup and literal templates while preserving helper-rendered component tracking.
|
|
50
|
+
|
|
51
|
+
*Joel Hawksley*
|
|
52
|
+
|
|
53
|
+
* Track helper-rendered component cache dependencies, enforce single-use instances on cache hits, and emit one render notification per self-cached render.
|
|
54
|
+
|
|
55
|
+
*Joel Hawksley*
|
|
56
|
+
|
|
57
|
+
* Resolve symbolic translation defaults in sidecars, restore request URL state in tests, and refresh inherited templates whenever template reloading is enabled.
|
|
58
|
+
|
|
59
|
+
*Joel Hawksley*
|
|
60
|
+
|
|
61
|
+
* Reuse existing GitHub releases when retrying a failed gem publish.
|
|
62
|
+
|
|
63
|
+
*Joel Hawksley*
|
|
64
|
+
|
|
65
|
+
* Prevent self-cache key collisions and track component references in views and format-specific partial dependencies.
|
|
66
|
+
|
|
67
|
+
*Joel Hawksley*
|
|
68
|
+
|
|
69
|
+
* Isolate preview and request parameters, honor preview locale callbacks, restore controller view contexts, and accept nil translation keys.
|
|
70
|
+
|
|
71
|
+
*Joel Hawksley*
|
|
72
|
+
|
|
73
|
+
* Honor negative generator flags and preserve pre-release versions throughout release automation. Report gem publishing failures.
|
|
74
|
+
|
|
75
|
+
*Joel Hawksley*
|
|
76
|
+
|
|
77
|
+
* 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.
|
|
78
|
+
|
|
79
|
+
*Joel Hawksley*
|
|
80
|
+
|
|
81
|
+
* Fix template method collisions between formats and variants, preserve default slot state, and copy collection spacer slots independently.
|
|
82
|
+
|
|
83
|
+
*Joel Hawksley*
|
|
84
|
+
|
|
85
|
+
* Apply `--skip-suffix` to all generated component files and restore full request URLs after `with_request_url` blocks.
|
|
86
|
+
|
|
87
|
+
*Joel Hawksley*
|
|
88
|
+
|
|
89
|
+
* Reset the assertion page when rendering a preview so assertions inspect the latest output.
|
|
90
|
+
|
|
91
|
+
*Joel Hawksley*
|
|
92
|
+
|
|
93
|
+
* Rediscover templates after development changes, including added or removed variants and parent templates.
|
|
94
|
+
|
|
95
|
+
*Joel Hawksley*
|
|
96
|
+
|
|
97
|
+
* Include all requested variants in output cache keys, preserving fallback order.
|
|
98
|
+
|
|
99
|
+
*Joel Hawksley*
|
|
100
|
+
|
|
101
|
+
* Resolve cache dependencies in their Ruby lexical namespaces and component template scopes.
|
|
102
|
+
|
|
103
|
+
*Joel Hawksley*
|
|
104
|
+
|
|
105
|
+
* Keep default slot configuration isolated between parent components and subclasses.
|
|
106
|
+
|
|
107
|
+
*Joel Hawksley*
|
|
108
|
+
|
|
109
|
+
* Preserve the calling view's translation scope when a component returns cached output or rejects content.
|
|
110
|
+
|
|
111
|
+
*Joel Hawksley*
|
|
112
|
+
|
|
113
|
+
* Reduce rendering and collection overhead, and speed up eager loading by sharing template-path parsing and avoiding redundant template and ancestor checks.
|
|
114
|
+
|
|
115
|
+
*Joel Hawksley*
|
|
116
|
+
|
|
117
|
+
* 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.
|
|
118
|
+
|
|
119
|
+
*Joel Hawksley*
|
|
120
|
+
|
|
121
|
+
* Speed up eager loading by sharing sidecar directory listings during compilation, and reduce per-render state reset overhead.
|
|
122
|
+
|
|
123
|
+
*Joel Hawksley*
|
|
124
|
+
|
|
125
|
+
* 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.
|
|
126
|
+
|
|
127
|
+
*Joel Hawksley*
|
|
128
|
+
|
|
129
|
+
* 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`.
|
|
130
|
+
|
|
131
|
+
*Fiona Burcombe*
|
|
132
|
+
|
|
13
133
|
## 4.20.0
|
|
14
134
|
|
|
15
135
|
* Fix `invalid byte sequence in UTF-8` errors when precomputing cache digests for components loaded from encrypted or binary source files.
|
|
@@ -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
|