-
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
Auto-capture render blocks and expose context specific _p #35
Closed
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
In a template like this, we now infer that the block takes 1 parameter and automatically yield a `np` composable content section: ```ruby render "card" do |card| card.yield :title, t(".title") end ``` The rendered "card" partial would previously need to be annotated with `yield content = np` but that's no longer needed, and it can instead just access the yielded Partial instance that's exposed in `content`: ``` content.content_for :title ``` Note: it was custom to do `yield p = np` previously, but I've chosen `content` as slightly more descriptive now that we're automatic. This doesn't break compatibility, but does perform an extra yield until apps switch. We could put this behind a config flag.
… yield/content_for
…s into render extension
Ruby's numbered parameters lets you access via _<index> like this: ```ruby render "card" do _1.yield :title, t(".title") end ``` So as an experiment, I'm adding a `_p` alias to access the nice partial instance that plays on Ruby's numbered parameters convention. Here's how the card partial would use it: ```html+erb <%= _p.content_for :title %> ```
There's a bug where we're capturing twice… and it's not easily solvable 🤪 |
There's some interesting stuff in here, but I have some other ideas for changing the auto-capturing which I want to explore. |
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.
Ref: #32
This attempts expose a context specific
_p
, so the below would work and point to the right_p
instance:To do this, we're attempting to always auto-capture a block that's passed to render like the
render "card" do
case, e.g. the card partial doesn't have to insertyield _p
.