-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add content_from
to let partials relay contents
#53
Merged
Conversation
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 comment was marked as resolved.
This comment was marked as resolved.
kaspth
commented
Aug 21, 2022
kaspth
force-pushed
the
relay-partial-contents-with-extract-from
branch
2 times, most recently
from
August 22, 2022 17:25
5570e73
to
2c32681
Compare
kaspth
changed the title
Add
Add Aug 22, 2022
extract_from
to let partials relay contentscontent_from
to let partials relay contents
kaspth
force-pushed
the
relay-partial-contents-with-extract-from
branch
from
August 22, 2022 17:26
2c32681
to
b6e25c2
Compare
Ok, got my naming concerns resolved and went with |
If we're starting to layer on more complex behavior to Section and exposing them, it's nice to have an alternate implementation that's easier to maintain for our content_for inter-op with Rails.
It's possible we may want a general method_missing hook that delegates to @view_context and concatenates the result and returns self for chaining. Would allow for something like this too: ```ruby <% partial.title.link_to(@document.name, @document) %> ```
This lets you generate different elements with overrides without appending to the content/options for the next invocation. Additionally, `tag#method_missing` responds to everything so we'll never reach super.
Various explicit nil returns were inserted to prevent things like <%= partial.title.t ".title" %> # <% %> should have been used here. But the more extensions we add the more we have to be careful of it, and it prevents other potentially interesting directions like chaining.
…and then we can expose `write`, with some potential for chaining.
Removes need for the old test task in the Rakefile.
When we fixed the view context stubbing, `capture` didn't just `yield` anymore but also processed the returned value as a string https://github.com/rails/rails/blob/06e9fbd954ab113108a7982357553fdef285bff1/actionview/lib/action_view/helpers/capture_helper.rb#L47 So our expectation that `partial.body { NameComponent.new(:plain) }` works, won't work in practice. But `partial.body { render NameComponent.new(:plain) }` is what's needed.
…if they want an object
Sometimes there's a partial that'd like the named contents of another. `content_from` lets a partial sift the content, and pass a hash to rename sections, from the outer partial: ```erb <% partial.title "Hello there" %> <% partial.byline "Somebody" %> <%= render "shared/title" do |cp| %> <% cp.content_from partial, :title, byline: :name %> <% end %> ```
kaspth
force-pushed
the
relay-partial-contents-with-extract-from
branch
from
September 5, 2022 07:43
b6e25c2
to
051647a
Compare
Closed
kaspth
added a commit
that referenced
this pull request
Sep 6, 2022
* main: Ignore /tmp if you're running BT in tmp/starter like CI does Fix some CHANGELOG issues and refit some examples + words Skip needless CI steps (#60) We don't need to depend on sqlite3 that was for an earlier version of the ViewComponent integration Fix #54 to use new section yield syntax Mixing `yield` call styles (#54) Expose Sections as an alternative to `content_for` (#57) Introduce Capybara to the test suite (#55) Add `content_from` to let partials relay contents (#53) v0.1.9 v0.1.8 Document release 🎉 (#52) Rename `Partial#output_buffer` to `Partial#yield` (#41) Allow outer partial access when capturing (#49) Fix accessing `partial` before rendering leaks state (#47) Use load hooks for monkey_patch loading (#48)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #11
Sometimes there's a partial that'd like the named contents of another.
content_from
lets a partial sift the content, and pass a hash to rename sections,from the outer partial:
Sprung out of the discussion in #38, though I didn't feel the need to add
parent
tracking and flipped the call order, so the inner partial extracts from the outer and that feels clearer what context we're currently in.