view_component 3.17.0 → 3.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/CHANGELOG.md +28 -2
- data/lib/view_component/base.rb +12 -5
- data/lib/view_component/compiler.rb +31 -29
- data/lib/view_component/config.rb +1 -1
- data/lib/view_component/engine.rb +8 -2
- data/lib/view_component/rails/tasks/view_component.rake +8 -2
- data/lib/view_component/version.rb +1 -1
- 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: 0be77c737ede73cbe4b576fe19f6d4afd6f1c1cc61cea7a1f61f1a18e98f83a3
|
4
|
+
data.tar.gz: 1b97ac4a9b78e0784e9258f8104cea39b25e12533cb9037c451cacb545da85ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 504c9c261f6921980feae7a7d2ec2cfb7676fca87800113d33eac5a2bdf4c4e12e82002144880270118f77eb30853a7d328a171a37ffdcf0efb706eda554bf33
|
7
|
+
data.tar.gz: 751f433ec0bf34e9737b70a6e3394d5e24e869781c5aa104921d4635467281d3ac33bcfeb8c40280a19873f897fda6a074a8842edfb4798a926fbe4a2e00851b
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,6 +10,32 @@ nav_order: 5
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## 3.18.0
|
14
|
+
|
15
|
+
* Enable components to use `@request` and `request` methods/ivars.
|
16
|
+
|
17
|
+
*Blake Williams*
|
18
|
+
|
19
|
+
* Fix bug where implicit locales in component filenames threw a `NameError`.
|
20
|
+
|
21
|
+
*Chloe Fons*
|
22
|
+
|
23
|
+
* Register ViewComponent tests directory for `rails stats`.
|
24
|
+
|
25
|
+
*Javier Aranda*
|
26
|
+
|
27
|
+
* Wrap entire compile step in a mutex to make it more resilient to race conditions.
|
28
|
+
|
29
|
+
*Blake Williams*
|
30
|
+
|
31
|
+
* Add [Niva]([niva.co](https://www.niva.co/)) to companies who use `ViewComponent`.
|
32
|
+
|
33
|
+
*Daniel Vu Dao*
|
34
|
+
|
35
|
+
* Fix `preview_paths` in docs.
|
36
|
+
|
37
|
+
*Javier Aranda*
|
38
|
+
|
13
39
|
## 3.17.0
|
14
40
|
|
15
41
|
* Use struct instead openstruct in lib code.
|
@@ -28,12 +54,12 @@ nav_order: 5
|
|
28
54
|
|
29
55
|
*Alberto Rocha*
|
30
56
|
|
31
|
-
## 3.16.0
|
32
|
-
|
33
57
|
* Fix development mode race condition that caused an invalid duplicate template error.
|
34
58
|
|
35
59
|
*Blake Williams*
|
36
60
|
|
61
|
+
## 3.16.0
|
62
|
+
|
37
63
|
* Add template information to multiple template error messages.
|
38
64
|
|
39
65
|
*Joel Hawksley*
|
data/lib/view_component/base.rb
CHANGED
@@ -109,10 +109,10 @@ module ViewComponent
|
|
109
109
|
|
110
110
|
if render?
|
111
111
|
rendered_template =
|
112
|
-
if compiler.renders_template_for?(@__vc_variant,
|
113
|
-
render_template_for(@__vc_variant,
|
112
|
+
if compiler.renders_template_for?(@__vc_variant, __vc_request&.format&.to_sym)
|
113
|
+
render_template_for(@__vc_variant, __vc_request&.format&.to_sym)
|
114
114
|
else
|
115
|
-
maybe_escape_html(render_template_for(@__vc_variant,
|
115
|
+
maybe_escape_html(render_template_for(@__vc_variant, __vc_request&.format&.to_sym)) do
|
116
116
|
Kernel.warn("WARNING: The #{self.class} component rendered HTML-unsafe output. The output will be automatically escaped, but you may want to investigate.")
|
117
117
|
end
|
118
118
|
end.to_s
|
@@ -286,7 +286,14 @@ module ViewComponent
|
|
286
286
|
#
|
287
287
|
# @return [ActionDispatch::Request]
|
288
288
|
def request
|
289
|
-
|
289
|
+
__vc_request
|
290
|
+
end
|
291
|
+
|
292
|
+
# Enables consumers to override request/@request
|
293
|
+
#
|
294
|
+
# @private
|
295
|
+
def __vc_request
|
296
|
+
@__vc_request ||= controller.request if controller.respond_to?(:request)
|
290
297
|
end
|
291
298
|
|
292
299
|
# The content passed to the component instance as a block.
|
@@ -328,7 +335,7 @@ module ViewComponent
|
|
328
335
|
end
|
329
336
|
|
330
337
|
def maybe_escape_html(text)
|
331
|
-
return text if
|
338
|
+
return text if __vc_request && !__vc_request.format.html?
|
332
339
|
return text if text.blank?
|
333
340
|
|
334
341
|
if text.html_safe?
|
@@ -12,7 +12,7 @@ module ViewComponent
|
|
12
12
|
|
13
13
|
def initialize(component)
|
14
14
|
@component = component
|
15
|
-
@
|
15
|
+
@lock = Mutex.new
|
16
16
|
@rendered_templates = Set.new
|
17
17
|
end
|
18
18
|
|
@@ -24,30 +24,36 @@ module ViewComponent
|
|
24
24
|
return if compiled? && !force
|
25
25
|
return if @component == ViewComponent::Base
|
26
26
|
|
27
|
-
|
27
|
+
@lock.synchronize do
|
28
|
+
# this check is duplicated so that concurrent compile calls can still
|
29
|
+
# early exit
|
30
|
+
return if compiled? && !force
|
28
31
|
|
29
|
-
|
30
|
-
@component.superclass.compile(raise_errors: raise_errors)
|
31
|
-
end
|
32
|
+
gather_templates
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
if self.class.development_mode && @templates.any?(&:requires_compiled_superclass?)
|
35
|
+
@component.superclass.compile(raise_errors: raise_errors)
|
36
|
+
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
end
|
38
|
+
if template_errors.present?
|
39
|
+
raise TemplateError.new(template_errors) if raise_errors
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
41
|
+
# this return is load bearing, and prevents the component from being considered "compiled?"
|
42
|
+
return false
|
43
|
+
end
|
44
44
|
|
45
|
-
|
45
|
+
if raise_errors
|
46
|
+
@component.validate_initialization_parameters!
|
47
|
+
@component.validate_collection_parameter!
|
48
|
+
end
|
49
|
+
|
50
|
+
define_render_template_for
|
46
51
|
|
47
|
-
|
48
|
-
|
52
|
+
@component.register_default_slots
|
53
|
+
@component.build_i18n_backend
|
49
54
|
|
50
|
-
|
55
|
+
CompileCache.register(@component)
|
56
|
+
end
|
51
57
|
end
|
52
58
|
|
53
59
|
def renders_template_for?(variant, format)
|
@@ -60,9 +66,7 @@ module ViewComponent
|
|
60
66
|
|
61
67
|
def define_render_template_for
|
62
68
|
@templates.each do |template|
|
63
|
-
|
64
|
-
template.compile_to_component
|
65
|
-
end
|
69
|
+
template.compile_to_component
|
66
70
|
end
|
67
71
|
|
68
72
|
method_body =
|
@@ -93,14 +97,12 @@ module ViewComponent
|
|
93
97
|
out << "else\n #{templates.find { _1.variant.nil? && _1.default_format? }.safe_method_name}\nend"
|
94
98
|
end
|
95
99
|
|
96
|
-
@
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
#{method_body}
|
101
|
-
end
|
102
|
-
RUBY
|
100
|
+
@component.silence_redefinition_of_method(:render_template_for)
|
101
|
+
@component.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
102
|
+
def render_template_for(variant = nil, format = nil)
|
103
|
+
#{method_body}
|
103
104
|
end
|
105
|
+
RUBY
|
104
106
|
end
|
105
107
|
|
106
108
|
def template_errors
|
@@ -190,7 +192,7 @@ module ViewComponent
|
|
190
192
|
path: path,
|
191
193
|
lineno: 0,
|
192
194
|
extension: path.split(".").last,
|
193
|
-
this_format: this_format,
|
195
|
+
this_format: this_format.to_s.split(".").last&.to_sym, # strip locale from this_format, see #2113
|
194
196
|
variant: variant
|
195
197
|
)
|
196
198
|
|
@@ -152,7 +152,7 @@ module ViewComponent
|
|
152
152
|
# @!attribute preview_paths
|
153
153
|
# @return [Array<String>]
|
154
154
|
# The locations in which component previews will be looked up.
|
155
|
-
# Defaults to `['test/
|
155
|
+
# Defaults to `['test/components/previews']` relative to your Rails root.
|
156
156
|
|
157
157
|
# @!attribute test_controller
|
158
158
|
# @return [String]
|
@@ -15,8 +15,14 @@ module ViewComponent
|
|
15
15
|
else
|
16
16
|
initializer "view_component.stats_directories" do |app|
|
17
17
|
require "rails/code_statistics"
|
18
|
-
|
19
|
-
Rails::
|
18
|
+
|
19
|
+
if Rails.root.join(ViewComponent::Base.view_component_path).directory?
|
20
|
+
Rails::CodeStatistics.register_directory("ViewComponents", ViewComponent::Base.view_component_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
if Rails.root.join("test/components").directory?
|
24
|
+
Rails::CodeStatistics.register_directory("ViewComponent tests", "test/components", test_directory: true)
|
25
|
+
end
|
20
26
|
end
|
21
27
|
end
|
22
28
|
|
@@ -7,8 +7,14 @@ namespace :view_component do
|
|
7
7
|
# :nocov:
|
8
8
|
require "rails/code_statistics"
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
if Rails.root.join(ViewComponent::Base.view_component_path).directory?
|
11
|
+
::STATS_DIRECTORIES << ["ViewComponents", ViewComponent::Base.view_component_path]
|
12
|
+
end
|
13
|
+
|
14
|
+
if Rails.root.join("test/components").directory?
|
15
|
+
::STATS_DIRECTORIES << ["ViewComponent tests", "test/components"]
|
16
|
+
CodeStatistics::TEST_TYPES << "ViewComponent tests"
|
17
|
+
end
|
12
18
|
# :nocov:
|
13
19
|
end
|
14
20
|
end
|
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: 3.
|
4
|
+
version: 3.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ViewComponent Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|