-
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
Base auto-capture logic on yield calls in template source #45
Conversation
c877d3b
to
a929d2f
Compare
Currently, we're basing our auto-capture logic on whether there's a single argument passed to render, e.g.: ```ruby render "card" do |partial| partial.yield :title, t(".title") end ``` But if users want to pass extra content via an explicit `<%= yield something %>`, we don't support that. This changes our logic to look for `<%= yield something %>` calls in the template source and not auto-capture in that case. We will pass the partial on as an extra argument in case callers want to expose that as a named block argument. We'll still auto-capture in case a template has non-capturing yields like `<%= yield :title %>`.
a929d2f
to
942d4c3
Compare
Note: this also relies on some code structure in |
@kaspth No need to provide backward compatibility. Happy to support 6.1 and up. |
# Note: `<%= yield %>` becomes `yield :layout` with no `render` `block`, though this method assumes a block is passed. | ||
def has_capturing_yield? | ||
defined?(@has_capturing_yield) ? @has_capturing_yield : | ||
@has_capturing_yield = source.match?(/\byield[\(? ]+(%>|[^:])/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticing the %>
: does this work with HAML?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally I wanted to define this after template compilation, so we'd be Template Handler independent, but I just realized we'd need to trigger compilation for that to work (and that's why it didn't work).
I've never used anything besides ERB, how does HAML syntax go by the way? Like this?
%= yield
%= yield :title
Do you know what Slim looks like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a HAML/Slim user, but the %>
got me thinking.
I've never used anything besides ERB, how does HAML syntax go by the way? Like this?
Yep I think so.
Slim looks similar http://slim-lang.com/
Extracted from #44
Currently, we're basing our auto-capture logic on whether there's a
single argument passed to render, e.g.:
But if users want to pass extra content via an explicit
<%= yield something %>
,we don't support that.
This changes our logic to look for
<%= yield something %>
calls in thetemplate source and not auto-capture in that case. We will pass the partial
on as an extra argument in case callers want to expose that as a named block
argument.
We'll still auto-capture in case a template has non-capturing yields like
<%= yield :title %>
.