-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration to treat content as a slot
Like discussed many times before, this finally adds content as a slot to ViewComponent so that we can begin separating the block provided when rendering from content for performance and ergonomic reasons. This adds two new methods: * `content_is_a_slot!` - This makes the component _and its descendants_ treat `content` as a slot, and the block provided to render calls _is always executed_. * `do_not_use_content_as_a_slot!` - This keeps the existing behavior where `content` is lazily evaluated and is used to return content. There's likely more implications from this change that need to be walked through (like how slots are used, and easily setting content) before this can be merged.
- Loading branch information
1 parent
451543a
commit 5abc33b
Showing
6 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
test/sandbox/app/components/content_as_slot_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div> | ||
<% if content? %> | ||
<%= content %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class ContentAsSlotComponent < ViewComponent::Base | ||
content_is_a_slot! | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class ContentNotASlotComponent < ViewComponent::Base | ||
do_not_use_content_as_a_slot! | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters