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
Include Hanami::Action::Response#exposures
in view rendering context
#319
Conversation
@jodosha nice addition! I've left a comment with a suggestion that I think should improve the clarity of handling clashing exposures/view render options. If you agree on that, it'd be nice to get this in. Longer term, I think we want to have a good think/discussion about the approach we recommend for application authors to follow re: passing objects to views and make sure that's well reflected in our future documentation. With both response exposures and view exposures existing, I can see things getting pretty confusing. |
After merging #345, I realized this PR might provide the same functionality. It does it in a different place and higher up the call stack. Which way is better @jodosha? Happy to use this one and revert #345. My understanding is that this PR would handle cases of people using |
@cllns @timriley Two things. ✌️ Please let me know if you agree. One: I would say it's better to push down to generic Action, even outside of Two: We should consider the following usages: Response exposures We set an exposure in the response, which should be available to the corresponding view/template. This is what #345 is taking care of. class MyAction < Hanami::Action
def handle(*, res)
res[:foo] = "bar"
end
end Rendering exposures We explicitly set an exposure while invoking class MyAction < Hanami::Action
def handle(*, res)
res.render(view, foo: "bar")
end
end A mix of the previous use cases Both class MyAction < Hanami::Action
def handle(*, res)
res[:color] = "red"
res.render(view, foo: "bar")
end
end |
We don't need to send the exposures twice. We first implemented this in #345 but Hanami::Action::Response.render handles sending the exposures to the view now (and ApplicationAction uses that)
6c53dd9
to
e1918d8
Compare
Rebased this branch, removed the change from #345 and all the tests still pass 🙌 . So this original change to |
@cllns LGTM 👍 I'm the original author of the PR, so I can't approve it 😉 |
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 great 👍🏼
Syntax preview
The
:users
exposure is added to the view args for rendering.In case of overlapping names between inline options passed to
Hanami::Action::Response#render
andHanami::Action::Response#exposures
, inline options will take the precedence.In the example above the view will receive
"Y"
as value for:foo
.