view_component 4.2.0 → 4.3.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 +18 -0
- data/lib/view_component/base.rb +3 -2
- data/lib/view_component/compiler.rb +8 -8
- data/lib/view_component/slotable.rb +1 -1
- data/lib/view_component/template.rb +31 -5
- 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: 7cc3bb1d940451beebb05d7424ae9fe3124ddbfd2acc21e407c0b3c4964c7570
|
|
4
|
+
data.tar.gz: 2db13b63611d87477814e3567e2aca332879a50e1a500ecc560b8a9d0537c411
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8dd9367ebb7c528a5a89d0a76d1294a0fa0276eed80b8c819d338c82d86c131386851903fb3fe0c1be43416980ebf9cb4ca405599f4e58f73084b1d5aee8fa8d
|
|
7
|
+
data.tar.gz: 4cca85cd44103692aed7039a7c0b044d78adbff6bbc0e5d99be0fe72590dae160047cf34ce731ec079141cf2ed22485d32898ce5917ec225e637951151c9d544
|
data/docs/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,24 @@ nav_order: 6
|
|
|
10
10
|
|
|
11
11
|
## main
|
|
12
12
|
|
|
13
|
+
## 4.3.0
|
|
14
|
+
|
|
15
|
+
* Fix load order issues for 3rd-party template handlers.
|
|
16
|
+
|
|
17
|
+
*Cameron Dutro*
|
|
18
|
+
|
|
19
|
+
* Fix segfault when Ruby coverage is enabled with Rails 8.1 ERB templates.
|
|
20
|
+
|
|
21
|
+
*George Holborn*
|
|
22
|
+
|
|
23
|
+
* Automatically merge dependabot PRs.
|
|
24
|
+
|
|
25
|
+
*Joel Hawksley*
|
|
26
|
+
|
|
27
|
+
* Use Ruby 4.0.0 in CI and dev.
|
|
28
|
+
|
|
29
|
+
*Joel Hawksley*
|
|
30
|
+
|
|
13
31
|
## 4.2.0
|
|
14
32
|
|
|
15
33
|
* Fix translation scope resolution in deeply nested component blocks (3+ levels). Translations called inside deeply nested slot blocks using `renders_many`/`renders_one` were incorrectly resolving to an intermediate component's scope instead of the partial's scope where the block was defined. The fix captures the virtual path at block definition time and restores it during block execution, ensuring translations always resolve relative to where the block was created regardless of nesting depth.
|
data/lib/view_component/base.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "action_view"
|
|
4
|
+
require "action_view/base"
|
|
4
5
|
require "view_component/collection"
|
|
5
6
|
require "view_component/compile_cache"
|
|
6
7
|
require "view_component/compiler"
|
|
@@ -577,7 +578,7 @@ module ViewComponent
|
|
|
577
578
|
# eager loading is disabled and the parent component is rendered before the child. In
|
|
578
579
|
# such a scenario, the parent will override ViewComponent::Base#render_template_for,
|
|
579
580
|
# meaning it will not be called for any children and thus not compile their templates.
|
|
580
|
-
if !child.
|
|
581
|
+
if !child.method_defined?(:render_template_for, false) && !child.__vc_compiled?
|
|
581
582
|
child.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
582
583
|
def render_template_for(requested_details)
|
|
583
584
|
# Force compilation here so the compiler always redefines render_template_for.
|
|
@@ -600,7 +601,7 @@ module ViewComponent
|
|
|
600
601
|
# Set collection parameter to the extended component
|
|
601
602
|
child.with_collection_parameter(__vc_provided_collection_parameter)
|
|
602
603
|
|
|
603
|
-
if
|
|
604
|
+
if method_defined?(:render_template_for, false)
|
|
604
605
|
vc_ancestor_calls = defined?(@__vc_ancestor_calls) ? @__vc_ancestor_calls.dup : []
|
|
605
606
|
|
|
606
607
|
vc_ancestor_calls.unshift(instance_method(:render_template_for))
|
|
@@ -115,11 +115,11 @@ module ViewComponent
|
|
|
115
115
|
.tally
|
|
116
116
|
.select { |_, count| count > 1 }
|
|
117
117
|
.each do |tally|
|
|
118
|
-
|
|
118
|
+
variant, this_format = tally.first
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
variant_string = " for variant `#{variant}`" if variant.present?
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
errors << "More than one #{this_format.upcase} template found#{variant_string} for #{@component}. "
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
default_template_types = @templates.each_with_object(Set.new) do |template, memo|
|
|
@@ -190,11 +190,11 @@ module ViewComponent
|
|
|
190
190
|
).flat_map { |ancestor| ancestor.instance_methods(false).grep(/^call(_|$)/) }
|
|
191
191
|
.uniq
|
|
192
192
|
.each do |method_name|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
193
|
+
templates << Template::InlineCall.new(
|
|
194
|
+
component: @component,
|
|
195
|
+
method_name: method_name,
|
|
196
|
+
defined_on_self: component_instance_methods_on_self.include?(method_name)
|
|
197
|
+
)
|
|
198
198
|
end
|
|
199
199
|
|
|
200
200
|
templates
|
|
@@ -259,7 +259,7 @@ module ViewComponent
|
|
|
259
259
|
|
|
260
260
|
setter_method_name = :"with_#{poly_slot_name}"
|
|
261
261
|
|
|
262
|
-
if
|
|
262
|
+
if method_defined?(setter_method_name)
|
|
263
263
|
raise AlreadyDefinedPolymorphicSlotSetterError.new(setter_method_name, poly_slot_name)
|
|
264
264
|
end
|
|
265
265
|
|
|
@@ -21,11 +21,21 @@ module ViewComponent
|
|
|
21
21
|
|
|
22
22
|
class File < Template
|
|
23
23
|
def initialize(component:, details:, path:)
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
@strip_annotation_line = false
|
|
25
|
+
|
|
26
|
+
# Rails 8.1 added a newline to compiled ERB output (rails/rails#53731).
|
|
27
|
+
# Use -1 to compensate for correct line numbers in stack traces.
|
|
28
|
+
# However, negative line numbers cause segfaults when Ruby's coverage
|
|
29
|
+
# is enabled (bugs.ruby-lang.org/issues/19363). In that case, strip the
|
|
30
|
+
# annotation line from compiled source instead.
|
|
26
31
|
lineno =
|
|
27
32
|
if Rails::VERSION::MAJOR >= 8 && Rails::VERSION::MINOR > 0 && details.handler == :erb
|
|
28
|
-
|
|
33
|
+
if coverage_running? && ActionView::Base.annotate_rendered_view_with_filenames
|
|
34
|
+
@strip_annotation_line = true
|
|
35
|
+
0
|
|
36
|
+
else
|
|
37
|
+
-1
|
|
38
|
+
end
|
|
29
39
|
else
|
|
30
40
|
0
|
|
31
41
|
end
|
|
@@ -46,6 +56,16 @@ module ViewComponent
|
|
|
46
56
|
def source
|
|
47
57
|
::File.read(@path)
|
|
48
58
|
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
def compiled_source
|
|
63
|
+
result = super
|
|
64
|
+
# Strip the annotation line to maintain correct line numbers when coverage
|
|
65
|
+
# is running (avoids segfault from negative lineno)
|
|
66
|
+
result = result.sub(/\A[^\n]*\n/, "") if @strip_annotation_line
|
|
67
|
+
result
|
|
68
|
+
end
|
|
49
69
|
end
|
|
50
70
|
|
|
51
71
|
class Inline < Template
|
|
@@ -54,8 +74,10 @@ module ViewComponent
|
|
|
54
74
|
def initialize(component:, inline_template:)
|
|
55
75
|
details = ActionView::TemplateDetails.new(nil, inline_template.language.to_sym, nil, nil)
|
|
56
76
|
|
|
57
|
-
# Rails 8.1 added a newline to
|
|
58
|
-
#
|
|
77
|
+
# Rails 8.1 added a newline to compiled ERB output (rails/rails#53731).
|
|
78
|
+
# Subtract 1 to compensate for correct line numbers in stack traces.
|
|
79
|
+
# Inline templates start at line 2+ (defined inside a class), so this
|
|
80
|
+
# won't result in negative line numbers that cause segfaults with coverage.
|
|
59
81
|
lineno =
|
|
60
82
|
if Rails::VERSION::MAJOR >= 8 && Rails::VERSION::MINOR > 0 && details.handler == :erb
|
|
61
83
|
inline_template.lineno - 1
|
|
@@ -126,6 +148,10 @@ module ViewComponent
|
|
|
126
148
|
@component.define_method(safe_method_name, @component.instance_method(@call_method_name))
|
|
127
149
|
end
|
|
128
150
|
|
|
151
|
+
def coverage_running?
|
|
152
|
+
defined?(Coverage) && Coverage.running?
|
|
153
|
+
end
|
|
154
|
+
|
|
129
155
|
def safe_method_name_call
|
|
130
156
|
m = safe_method_name
|
|
131
157
|
proc { send(m) }
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: view_component
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ViewComponent Team
|
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
135
135
|
- !ruby/object:Gem::Version
|
|
136
136
|
version: '0'
|
|
137
137
|
requirements: []
|
|
138
|
-
rubygems_version:
|
|
138
|
+
rubygems_version: 4.0.3
|
|
139
139
|
specification_version: 4
|
|
140
140
|
summary: A framework for building reusable, testable & encapsulated view components
|
|
141
141
|
in Ruby on Rails.
|