Skip to content

Commit 3487283

Browse files
authored
release 3.5.0 (#1808)
* release 3.5.0 * Fix inline render_parent tests
1 parent 425338f commit 3487283

File tree

9 files changed

+28
-37
lines changed

9 files changed

+28
-37
lines changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
view_component (3.4.0)
4+
view_component (3.5.0)
55
activesupport (>= 5.2.0, < 8.0)
66
concurrent-ruby (~> 1.0)
77
method_source (~> 1.0)

docs/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ nav_order: 5
1010

1111
## main
1212

13+
## 3.5.0
14+
1315
* Add Skroutz to users list.
1416

1517
*Chris Nitsas*

docs/_data/library.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version: 3.4.0
1+
version: 3.5.0

docs/guide/templates.md

+2-15
Original file line numberDiff line numberDiff line change
@@ -143,26 +143,13 @@ class MyComponent < ViewComponent::Base
143143
end
144144
```
145145

146-
Finally, `#render_parent` also works inside `#call` methods:
146+
Keep in mind that `#render_parent` doesn't return a string. If a string is desired, eg. inside a `#call` method, call `#render_parent_to_string` instead. For example:
147147

148148
```ruby
149149
class MyComponent < ViewComponent::Base
150150
def call
151151
content_tag("div") do
152-
render_parent
153-
end
154-
end
155-
end
156-
```
157-
158-
When composing `#call` methods, keep in mind that `#render_parent` does not return a string. If a string is desired, call `#render_parent_to_string` instead. For example:
159-
160-
```ruby
161-
class MyComponent < ViewComponent::Base
162-
# "phone" variant
163-
def call_phone
164-
content_tag("div") do
165-
"<div>#{render_parent_to_string}</div>"
152+
render_parent_to_string
166153
end
167154
end
168155
end

lib/view_component/base.rb

+12-12
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,8 @@ def render_in(view_context, &block)
127127
# parent template considering the current variant and emits the result without
128128
# double-rendering.
129129
def render_parent
130-
@__vc_parent_render_level ||= 0 # ensure a good starting value
131-
132-
begin
133-
target_render = self.class.instance_variable_get(:@__vc_ancestor_calls)[@__vc_parent_render_level]
134-
@__vc_parent_render_level += 1
135-
136-
target_render.bind_call(self, @__vc_variant)
137-
nil
138-
ensure
139-
@__vc_parent_render_level -= 1
140-
end
130+
render_parent_to_string
131+
nil
141132
end
142133

143134
# Renders the parent component to a string and returns it. This method is meant
@@ -151,7 +142,16 @@ def render_parent
151142
#
152143
# When rendering the parent inside an .erb template, use `#render_parent` instead.
153144
def render_parent_to_string
154-
capture { render_parent }
145+
@__vc_parent_render_level ||= 0 # ensure a good starting value
146+
147+
begin
148+
target_render = self.class.instance_variable_get(:@__vc_ancestor_calls)[@__vc_parent_render_level]
149+
@__vc_parent_render_level += 1
150+
151+
target_render.bind_call(self, @__vc_variant)
152+
ensure
153+
@__vc_parent_render_level -= 1
154+
end
155155
end
156156

157157
# Optional content to be returned after the rendered template.

lib/view_component/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module ViewComponent
44
module VERSION
55
MAJOR = 3
6-
MINOR = 4
6+
MINOR = 5
77
PATCH = 0
88
PRE = nil
99

test/sandbox/app/components/inline_level1_component.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
class InlineLevel1Component < ViewComponent::Base
44
def call
5-
content_tag(:div, class: "level1-component")
5+
content_tag(:div, class: "level1-component") do
6+
"Level 1 component"
7+
end
68
end
79
end
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# frozen_string_literal: true
22

3-
class InlineLevel2Component < Level2Component
3+
class InlineLevel2Component < InlineLevel1Component
44
def call
5-
"<div level2-component base>#{render_parent_to_string}</div>"
5+
"<div class='level2-component base'>#{render_parent_to_string}</div>".html_safe
66
end
77

88
def call_variant
9-
"<div level2-component variant>#{render_parent_to_string}</div>"
9+
"<div class='level2-component variant'>#{render_parent_to_string}</div>".html_safe
1010
end
1111
end
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# frozen_string_literal: true
22

3-
class InlineLevel3Component < Level2Component
3+
class InlineLevel3Component < InlineLevel2Component
44
def call
55
content_tag(:div, class: "level3-component base") do
6-
render_parent
6+
render_parent_to_string
77
end
88
end
99

1010
def call_variant
1111
content_tag(:div, class: "level3-component variant") do
12-
render_parent
12+
render_parent_to_string
1313
end
1414
end
1515
end

0 commit comments

Comments
 (0)