view_component 2.72.0 → 2.74.1
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 +66 -0
- data/lib/view_component/base.rb +5 -15
- data/lib/view_component/compiler.rb +36 -69
- data/lib/view_component/engine.rb +1 -2
- data/lib/view_component/test_helpers.rb +1 -1
- data/lib/view_component/translatable.rb +1 -1
- data/lib/view_component/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 64dcea99274ed75352d28004634307fa7db193aa5bf8bf57dd0c9d5c5c241308
|
|
4
|
+
data.tar.gz: c097b1034bc3df6216117fc0b32df26a8b02c0922c7e7399b254a6606aa46c31
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: efe5f3a05e157482eec4426ae05eef96345da9aa3ae0865c2ce7bc1755e08ae07405ee648923fe84165eca989a87b53f015012f13002202e809c12819c552a5b
|
|
7
|
+
data.tar.gz: 7b8bb21b81a1da222b47dd8c8c12cf2c0f7f5e2bd1e74d80ebfc8bf7e1cbe5c54eeab46c80395d3c8bb28809caac8be07ce833e1530af3b982d153d44398fba2
|
data/docs/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,72 @@ nav_order: 5
|
|
|
10
10
|
|
|
11
11
|
## main
|
|
12
12
|
|
|
13
|
+
## 2.74.1
|
|
14
|
+
|
|
15
|
+
* Add more users of ViewComponent to docs.
|
|
16
|
+
|
|
17
|
+
*Joel Hawksley*
|
|
18
|
+
|
|
19
|
+
* Add a known issue for usage with `turbo_frame_tag` to the documentation.
|
|
20
|
+
|
|
21
|
+
*Vlad Radulescu*
|
|
22
|
+
|
|
23
|
+
* Add note about system testing components with previews.
|
|
24
|
+
|
|
25
|
+
*Joel Hawksley*
|
|
26
|
+
|
|
27
|
+
* Remove locking mechanisms from the compiler.
|
|
28
|
+
|
|
29
|
+
*Cameron Dutro*
|
|
30
|
+
|
|
31
|
+
## 2.74.0
|
|
32
|
+
|
|
33
|
+
* Add Avo to list of companies using ViewComponent.
|
|
34
|
+
|
|
35
|
+
*Adrian Marin*
|
|
36
|
+
|
|
37
|
+
* Promote experimental `_output_postamble` method to public API as `output_postamble`.
|
|
38
|
+
|
|
39
|
+
*Joel Hawksley*
|
|
40
|
+
|
|
41
|
+
* Promote experimental `_sidecar_files` method to public API as `sidecar_files`.
|
|
42
|
+
|
|
43
|
+
*Joel Hawksley*
|
|
44
|
+
|
|
45
|
+
* Fix `show_previews` regression introduced in 2.73.0.
|
|
46
|
+
|
|
47
|
+
*Andy Baranov*
|
|
48
|
+
|
|
49
|
+
* `with_request_url` test helper supports router constraints (such as Devise).
|
|
50
|
+
|
|
51
|
+
*Aotokitsuruya*
|
|
52
|
+
|
|
53
|
+
## 2.73.0
|
|
54
|
+
|
|
55
|
+
* Remove experimental `_after_compile` lifecycle method.
|
|
56
|
+
|
|
57
|
+
*Joel Hawksley*
|
|
58
|
+
|
|
59
|
+
* Fix capitalization of JavaScript in docs.
|
|
60
|
+
|
|
61
|
+
*Erinna Chen*
|
|
62
|
+
|
|
63
|
+
* Add PrintReleaf to list of companies using ViewComponent.
|
|
64
|
+
|
|
65
|
+
*Ry Kulp*
|
|
66
|
+
|
|
67
|
+
* Simplify CI configuration to a single build per Ruby/Rails version.
|
|
68
|
+
|
|
69
|
+
*Joel Hawksley*
|
|
70
|
+
|
|
71
|
+
* Correctly document `generate.sidecar` config option.
|
|
72
|
+
|
|
73
|
+
*Ruben Smit*
|
|
74
|
+
|
|
75
|
+
* Add Yobbers to list of companies using ViewComponent.
|
|
76
|
+
|
|
77
|
+
*Anton Prins*
|
|
78
|
+
|
|
13
79
|
## 2.72.0
|
|
14
80
|
|
|
15
81
|
* Deprecate support for Ruby < 2.7 for removal in v3.0.0.
|
data/lib/view_component/base.rb
CHANGED
|
@@ -59,15 +59,6 @@ module ViewComponent
|
|
|
59
59
|
self.__vc_original_view_context = view_context
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
# EXPERIMENTAL: This API is experimental and may be removed at any time.
|
|
63
|
-
# Hook for allowing components to do work as part of the compilation process.
|
|
64
|
-
#
|
|
65
|
-
# For example, one might compile component-specific assets at this point.
|
|
66
|
-
# @private TODO: add documentation
|
|
67
|
-
def self._after_compile
|
|
68
|
-
# noop
|
|
69
|
-
end
|
|
70
|
-
|
|
71
62
|
# @!macro [attach] deprecated_generate_mattr_accessor
|
|
72
63
|
# @method generate_$1
|
|
73
64
|
# @deprecated Use `#generate.$1` instead. Will be removed in v3.0.0.
|
|
@@ -137,7 +128,7 @@ module ViewComponent
|
|
|
137
128
|
# component template is evaluated.
|
|
138
129
|
content if self.class.use_consistent_rendering_lifecycle
|
|
139
130
|
|
|
140
|
-
render_template_for(@__vc_variant).to_s +
|
|
131
|
+
render_template_for(@__vc_variant).to_s + output_postamble
|
|
141
132
|
else
|
|
142
133
|
""
|
|
143
134
|
end
|
|
@@ -160,10 +151,10 @@ module ViewComponent
|
|
|
160
151
|
nil
|
|
161
152
|
end
|
|
162
153
|
|
|
163
|
-
#
|
|
154
|
+
# Optional content to be returned after the rendered template.
|
|
164
155
|
#
|
|
165
156
|
# @return [String]
|
|
166
|
-
def
|
|
157
|
+
def output_postamble
|
|
167
158
|
""
|
|
168
159
|
end
|
|
169
160
|
|
|
@@ -418,15 +409,14 @@ module ViewComponent
|
|
|
418
409
|
# @private
|
|
419
410
|
attr_accessor :source_location, :virtual_path
|
|
420
411
|
|
|
421
|
-
# EXPERIMENTAL: This API is experimental and may be removed at any time.
|
|
422
412
|
# Find sidecar files for the given extensions.
|
|
423
413
|
#
|
|
424
414
|
# The provided array of extensions is expected to contain
|
|
425
415
|
# strings starting without the "dot", example: `["erb", "haml"]`.
|
|
426
416
|
#
|
|
427
417
|
# For example, one might collect sidecar CSS files that need to be compiled.
|
|
428
|
-
# @
|
|
429
|
-
def
|
|
418
|
+
# @param extensions [Array<String>] Extensions of which to return matching sidecar files.
|
|
419
|
+
def sidecar_files(extensions)
|
|
430
420
|
return [] unless source_location
|
|
431
421
|
|
|
432
422
|
extensions = extensions.join(",")
|
|
@@ -4,9 +4,6 @@ require "concurrent-ruby"
|
|
|
4
4
|
|
|
5
5
|
module ViewComponent
|
|
6
6
|
class Compiler
|
|
7
|
-
# Lock required to be obtained before compiling the component
|
|
8
|
-
attr_reader :__vc_compiler_lock
|
|
9
|
-
|
|
10
7
|
# Compiler mode. Can be either:
|
|
11
8
|
# * development (a blocking mode which ensures thread safety when redefining the `call` method for components,
|
|
12
9
|
# default in Rails development and test mode)
|
|
@@ -18,7 +15,7 @@ module ViewComponent
|
|
|
18
15
|
|
|
19
16
|
def initialize(component_class)
|
|
20
17
|
@component_class = component_class
|
|
21
|
-
@
|
|
18
|
+
@redefinition_lock = Mutex.new
|
|
22
19
|
end
|
|
23
20
|
|
|
24
21
|
def compiled?
|
|
@@ -38,46 +35,40 @@ module ViewComponent
|
|
|
38
35
|
end
|
|
39
36
|
|
|
40
37
|
component_class.superclass.compile(raise_errors: raise_errors) if should_compile_superclass?
|
|
38
|
+
subclass_instance_methods = component_class.instance_methods(false)
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
raise ViewComponent::ComponentError.new(
|
|
49
|
-
"#{component_class} implements a reserved method, `#with_content`.\n\n" \
|
|
50
|
-
"To fix this issue, change the name of the method."
|
|
51
|
-
)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
if template_errors.present?
|
|
55
|
-
raise ViewComponent::TemplateError.new(template_errors) if raise_errors
|
|
40
|
+
if subclass_instance_methods.include?(:with_content) && raise_errors
|
|
41
|
+
raise ViewComponent::ComponentError.new(
|
|
42
|
+
"#{component_class} implements a reserved method, `#with_content`.\n\n" \
|
|
43
|
+
"To fix this issue, change the name of the method."
|
|
44
|
+
)
|
|
45
|
+
end
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
if template_errors.present?
|
|
48
|
+
raise ViewComponent::TemplateError.new(template_errors) if raise_errors
|
|
59
49
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"`#before_render_check` will be removed in v3.0.0.\n\n" \
|
|
63
|
-
"To fix this issue, use `#before_render` instead."
|
|
64
|
-
)
|
|
65
|
-
end
|
|
50
|
+
return false
|
|
51
|
+
end
|
|
66
52
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
53
|
+
if subclass_instance_methods.include?(:before_render_check)
|
|
54
|
+
ViewComponent::Deprecation.warn(
|
|
55
|
+
"`#before_render_check` will be removed in v3.0.0.\n\n" \
|
|
56
|
+
"To fix this issue, use `#before_render` instead."
|
|
57
|
+
)
|
|
58
|
+
end
|
|
71
59
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
60
|
+
if raise_errors
|
|
61
|
+
component_class.validate_initialization_parameters!
|
|
62
|
+
component_class.validate_collection_parameter!
|
|
63
|
+
end
|
|
76
64
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
65
|
+
templates.each do |template|
|
|
66
|
+
# Remove existing compiled template methods,
|
|
67
|
+
# as Ruby warns when redefining a method.
|
|
68
|
+
method_name = call_method_name(template[:variant])
|
|
80
69
|
|
|
70
|
+
redefinition_lock.synchronize do
|
|
71
|
+
component_class.silence_redefinition_of_method(method_name)
|
|
81
72
|
# rubocop:disable Style/EvalWithLocation
|
|
82
73
|
component_class.class_eval <<-RUBY, template[:path], 0
|
|
83
74
|
def #{method_name}
|
|
@@ -86,37 +77,20 @@ module ViewComponent
|
|
|
86
77
|
RUBY
|
|
87
78
|
# rubocop:enable Style/EvalWithLocation
|
|
88
79
|
end
|
|
89
|
-
|
|
90
|
-
define_render_template_for
|
|
91
|
-
|
|
92
|
-
component_class.build_i18n_backend
|
|
93
|
-
component_class._after_compile
|
|
94
|
-
|
|
95
|
-
CompileCache.register(component_class)
|
|
96
80
|
end
|
|
97
|
-
end
|
|
98
81
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
else
|
|
103
|
-
block.call
|
|
104
|
-
end
|
|
105
|
-
end
|
|
82
|
+
define_render_template_for
|
|
83
|
+
|
|
84
|
+
component_class.build_i18n_backend
|
|
106
85
|
|
|
107
|
-
|
|
108
|
-
__vc_compiler_lock.with_read_lock(&block)
|
|
86
|
+
CompileCache.register(component_class)
|
|
109
87
|
end
|
|
110
88
|
|
|
111
89
|
private
|
|
112
90
|
|
|
113
|
-
attr_reader :component_class
|
|
91
|
+
attr_reader :component_class, :redefinition_lock
|
|
114
92
|
|
|
115
93
|
def define_render_template_for
|
|
116
|
-
if component_class.instance_methods.include?(:render_template_for)
|
|
117
|
-
component_class.send(:undef_method, :render_template_for)
|
|
118
|
-
end
|
|
119
|
-
|
|
120
94
|
variant_elsifs = variants.compact.uniq.map do |variant|
|
|
121
95
|
"elsif variant.to_sym == :#{variant}\n #{call_method_name(variant)}"
|
|
122
96
|
end.join("\n")
|
|
@@ -130,15 +104,8 @@ module ViewComponent
|
|
|
130
104
|
end
|
|
131
105
|
RUBY
|
|
132
106
|
|
|
133
|
-
|
|
134
|
-
component_class.
|
|
135
|
-
def render_template_for(variant = nil)
|
|
136
|
-
self.class.compiler.with_read_lock do
|
|
137
|
-
#{body}
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
RUBY
|
|
141
|
-
else
|
|
107
|
+
redefinition_lock.synchronize do
|
|
108
|
+
component_class.silence_redefinition_of_method(:render_template_for)
|
|
142
109
|
component_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
143
110
|
def render_template_for(variant = nil)
|
|
144
111
|
#{body}
|
|
@@ -205,7 +172,7 @@ module ViewComponent
|
|
|
205
172
|
begin
|
|
206
173
|
extensions = ActionView::Template.template_handler_extensions
|
|
207
174
|
|
|
208
|
-
component_class.
|
|
175
|
+
component_class.sidecar_files(extensions).each_with_object([]) do |path, memo|
|
|
209
176
|
pieces = File.basename(path).split(".")
|
|
210
177
|
memo << {
|
|
211
178
|
path: path,
|
|
@@ -19,8 +19,7 @@ module ViewComponent
|
|
|
19
19
|
end
|
|
20
20
|
options.instrumentation_enabled = false if options.instrumentation_enabled.nil?
|
|
21
21
|
options.render_monkey_patch_enabled = true if options.render_monkey_patch_enabled.nil?
|
|
22
|
-
options.show_previews = Rails.env.development? || Rails.env.test? if options.show_previews.nil?
|
|
23
|
-
options.instrumentation_enabled = false if options.instrumentation_enabled.nil?
|
|
22
|
+
options.show_previews = (Rails.env.development? || Rails.env.test?) if options.show_previews.nil?
|
|
24
23
|
|
|
25
24
|
if options.show_previews
|
|
26
25
|
# This is still necessary because when `config.view_component` is declared, `Rails.root` is unspecified.
|
|
@@ -200,7 +200,7 @@ module ViewComponent
|
|
|
200
200
|
|
|
201
201
|
path, query = path.split("?", 2)
|
|
202
202
|
request.path_info = path
|
|
203
|
-
request.path_parameters = Rails.application.routes.
|
|
203
|
+
request.path_parameters = Rails.application.routes.recognize_path_with_request(request, path, {})
|
|
204
204
|
request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_nested_query(query))
|
|
205
205
|
request.set_header(Rack::QUERY_STRING, query)
|
|
206
206
|
yield
|
|
@@ -23,7 +23,7 @@ module ViewComponent
|
|
|
23
23
|
def build_i18n_backend
|
|
24
24
|
return if CompileCache.compiled? self
|
|
25
25
|
|
|
26
|
-
self.i18n_backend = if (translation_files =
|
|
26
|
+
self.i18n_backend = if (translation_files = sidecar_files(%w[yml yaml])).any?
|
|
27
27
|
# Returning nil cleans up if translations file has been removed since the last compilation
|
|
28
28
|
|
|
29
29
|
I18nBackend.new(
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: view_component
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.74.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ViewComponent Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-10-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|