-
Notifications
You must be signed in to change notification settings - Fork 583
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 an inline_layout stash keyword, based on the mojo.js inlineLayout one. #1887
base: main
Are you sure you want to change the base?
Conversation
2c65608
to
2d74508
Compare
This shoud be ready for another round of review at your convenience (I’m not sure what notification is sent by Github). |
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 looks like an useful addition to me 👍🏻
f387dc2
to
77c1cab
Compare
Thanks, please take another look. (I’m not sure why the CI is failing, the messages seem unrelated to the change as they are about some docker initialisation error) |
Any chance to get a new review? I believe that I have addressed all your comment and that this might be ready to be merged. |
lib/Mojolicious/Renderer.pm
Outdated
@@ -108,6 +108,10 @@ sub render { | |||
# Inheritance | |||
my $content = $stash->{'mojo.content'} //= {}; | |||
local $content->{content} = $output =~ /\S/ ? $output : undef if $stash->{extends} || $stash->{layout}; | |||
if ($stash->{inline_layout}) { | |||
@$options{inline} = delete $stash->{inline_layout}; |
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.
@$options
doesn't make sense here.
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 can't quite say what yet, but something about the logic seems wrong too. 🤔
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.
Maybe that inline
value needs to be local
-ised to avoid side effects?
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.
You’re right that it should be possible to execute another layout defined in the inline layout (if we started from a non-inline template).
I localized the inline value and fixed another bug (a layout and inline_layout defined initially could have both been executed), and I observed that it prevented entering the second loop. However, I was not able to get it to work in the correct case (template => inline_layout => other layout defined in the inline_layout), so I was not able either to write a good test case for the fixed part.
lib/Mojolicious/Renderer.pm
Outdated
@@ -108,6 +108,10 @@ sub render { | |||
# Inheritance | |||
my $content = $stash->{'mojo.content'} //= {}; | |||
local $content->{content} = $output =~ /\S/ ? $output : undef if $stash->{extends} || $stash->{layout}; | |||
if ($stash->{inline_layout}) { |
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.
if (defined...
.
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.
Done.
77c1cab
to
9578a17
Compare
9578a17
to
d7eb0a7
Compare
Let me know if there are still issues to address here. |
If there are no more comments on this PR, could it be merged? |
if $stash->{extends} || $stash->{layout} || $stash->{inline_layout}; | ||
if (defined $stash->{inline_layout}) { | ||
local $options->{inline} = delete $stash->{inline_layout}; | ||
delete $stash->{layout}; |
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.
Do the tests still pass if this line is removed?
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.
They do. I tried to write something to test this line but did not succeed (setting layout
and inline_layout
together in a call to render results in an error 500 but I’m not sure why). I still have the impression that this line should stay.
Do you have an idea of how to test it? Or do you think that it should be removed?
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.
Code that does nothing should not be present.
Too bad this PR is not ready, i would have liked to ship it in the next release. |
Summary
This adds a way to pass an inline layout in calls to render() using a new
inline_layout
keyword.Motivation
Using the mojo.js semantics to allow inline layout seems to be the safest way.
References
See the discussion in #1780.