diff --git a/Gemfile.lock b/Gemfile.lock
index 82a702316..0754ea03e 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- view_component (3.4.0)
+ view_component (3.5.0)
activesupport (>= 5.2.0, < 8.0)
concurrent-ruby (~> 1.0)
method_source (~> 1.0)
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 599b1f823..493e13fa0 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -10,6 +10,8 @@ nav_order: 5
## main
+## 3.5.0
+
* Add Skroutz to users list.
*Chris Nitsas*
diff --git a/docs/_data/library.yml b/docs/_data/library.yml
index ef3f3ccdb..a99e3342c 100644
--- a/docs/_data/library.yml
+++ b/docs/_data/library.yml
@@ -1 +1 @@
-version: 3.4.0
+version: 3.5.0
diff --git a/docs/guide/templates.md b/docs/guide/templates.md
index 312d192cf..1f11bdb3d 100644
--- a/docs/guide/templates.md
+++ b/docs/guide/templates.md
@@ -143,26 +143,13 @@ class MyComponent < ViewComponent::Base
end
```
-Finally, `#render_parent` also works inside `#call` methods:
+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:
```ruby
class MyComponent < ViewComponent::Base
def call
content_tag("div") do
- render_parent
- end
- end
-end
-```
-
-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:
-
-```ruby
-class MyComponent < ViewComponent::Base
- # "phone" variant
- def call_phone
- content_tag("div") do
- "
#{render_parent_to_string}
"
+ render_parent_to_string
end
end
end
diff --git a/lib/view_component/base.rb b/lib/view_component/base.rb
index ac3256a3c..9efc78738 100644
--- a/lib/view_component/base.rb
+++ b/lib/view_component/base.rb
@@ -127,17 +127,8 @@ def render_in(view_context, &block)
# parent template considering the current variant and emits the result without
# double-rendering.
def render_parent
- @__vc_parent_render_level ||= 0 # ensure a good starting value
-
- begin
- target_render = self.class.instance_variable_get(:@__vc_ancestor_calls)[@__vc_parent_render_level]
- @__vc_parent_render_level += 1
-
- target_render.bind_call(self, @__vc_variant)
- nil
- ensure
- @__vc_parent_render_level -= 1
- end
+ render_parent_to_string
+ nil
end
# Renders the parent component to a string and returns it. This method is meant
@@ -151,7 +142,16 @@ def render_parent
#
# When rendering the parent inside an .erb template, use `#render_parent` instead.
def render_parent_to_string
- capture { render_parent }
+ @__vc_parent_render_level ||= 0 # ensure a good starting value
+
+ begin
+ target_render = self.class.instance_variable_get(:@__vc_ancestor_calls)[@__vc_parent_render_level]
+ @__vc_parent_render_level += 1
+
+ target_render.bind_call(self, @__vc_variant)
+ ensure
+ @__vc_parent_render_level -= 1
+ end
end
# Optional content to be returned after the rendered template.
diff --git a/lib/view_component/version.rb b/lib/view_component/version.rb
index 8cbaadcc4..cc0c9e583 100644
--- a/lib/view_component/version.rb
+++ b/lib/view_component/version.rb
@@ -3,7 +3,7 @@
module ViewComponent
module VERSION
MAJOR = 3
- MINOR = 4
+ MINOR = 5
PATCH = 0
PRE = nil
diff --git a/test/sandbox/app/components/inline_level1_component.rb b/test/sandbox/app/components/inline_level1_component.rb
index bbc996d85..a55e51eaf 100644
--- a/test/sandbox/app/components/inline_level1_component.rb
+++ b/test/sandbox/app/components/inline_level1_component.rb
@@ -2,6 +2,8 @@
class InlineLevel1Component < ViewComponent::Base
def call
- content_tag(:div, class: "level1-component")
+ content_tag(:div, class: "level1-component") do
+ "Level 1 component"
+ end
end
end
diff --git a/test/sandbox/app/components/inline_level2_component.rb b/test/sandbox/app/components/inline_level2_component.rb
index bb6378589..3a67b20e8 100644
--- a/test/sandbox/app/components/inline_level2_component.rb
+++ b/test/sandbox/app/components/inline_level2_component.rb
@@ -1,11 +1,11 @@
# frozen_string_literal: true
-class InlineLevel2Component < Level2Component
+class InlineLevel2Component < InlineLevel1Component
def call
- "#{render_parent_to_string}
"
+ "#{render_parent_to_string}
".html_safe
end
def call_variant
- "#{render_parent_to_string}
"
+ "#{render_parent_to_string}
".html_safe
end
end
diff --git a/test/sandbox/app/components/inline_level3_component.rb b/test/sandbox/app/components/inline_level3_component.rb
index 99e0c4aff..1e31bbaa3 100644
--- a/test/sandbox/app/components/inline_level3_component.rb
+++ b/test/sandbox/app/components/inline_level3_component.rb
@@ -1,15 +1,15 @@
# frozen_string_literal: true
-class InlineLevel3Component < Level2Component
+class InlineLevel3Component < InlineLevel2Component
def call
content_tag(:div, class: "level3-component base") do
- render_parent
+ render_parent_to_string
end
end
def call_variant
content_tag(:div, class: "level3-component variant") do
- render_parent
+ render_parent_to_string
end
end
end