-
Notifications
You must be signed in to change notification settings - Fork 444
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
Allow arguments to be passed to content areas #285 #323
Allow arguments to be passed to content areas #285 #323
Conversation
ping @andrewmcodes @rosendi @thomasbrus |
97d3e51
to
b1bcb89
Compare
assert_selector(".title strong", text: "Hello!") | ||
assert_selector(".body", text: "Have a nice day.") | ||
assert_selector(".footer", text: "Bye!") | ||
end |
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.
With this change "wrapping" the render arguments results in a stack overflow. Its a weird use case anyway and not one that I'm that bothered about supporting. Seems like anyone rendering the component can choose one mechanism or the other.
content = view_context.capture(&block) | ||
define_singleton_method(area) do |*args| | ||
block = ->() { content } unless block_given? | ||
view_context.capture(*args, &block) |
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.
This is the key change. Rather than capturing the block immediately and storing the result in the attr_reader instance variable we redefine the method and capture the block when its called passing the arguments.
@jonspalmer thanks for putting this together. I vote that we let #325 play out before moving forward with any further changes to content areas ❤️ |
@joelhawksley Agreed. We're getting there on #325 I think the answer will be clear out of that |
Closing as stale, feel free to reopen if you'd like ❤️ |
Summary
Alternative solution than #322 for passing arguments to content areas as requested in #285
Other Information
I'm not 100% convinced we need this complexity. I'd love more example use cases. But assuming an agreed need I think this is the way we'd do it