Skip to content
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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mkende
Copy link
Contributor

@mkende mkende commented Dec 5, 2021

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.

lib/Mojolicious/Renderer.pm Outdated Show resolved Hide resolved
@mkende
Copy link
Contributor Author

mkende commented Dec 11, 2021

This shoud be ready for another round of review at your convenience (I’m not sure what notification is sent by Github).

marcusramberg
marcusramberg previously approved these changes Dec 19, 2021
Copy link
Member

@marcusramberg marcusramberg left a 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 👍🏻

kraih
kraih previously requested changes Dec 19, 2021
lib/Mojolicious/Renderer.pm Outdated Show resolved Hide resolved
lib/Mojolicious/Renderer.pm Outdated Show resolved Hide resolved
lib/Mojolicious/Renderer.pm Outdated Show resolved Hide resolved
@mkende
Copy link
Contributor Author

mkende commented Dec 20, 2021

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)

@mkende
Copy link
Contributor Author

mkende commented Jan 24, 2022

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.

@@ -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};
Copy link
Member

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.

Copy link
Member

@kraih kraih Jan 25, 2022

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. 🤔

Copy link
Member

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?

Copy link
Contributor Author

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.

@@ -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}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (defined....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@mkende
Copy link
Contributor Author

mkende commented Mar 27, 2022

Let me know if there are still issues to address here.

@mkende
Copy link
Contributor Author

mkende commented Aug 23, 2022

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};
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

@kraih
Copy link
Member

kraih commented Sep 10, 2022

Too bad this PR is not ready, i would have liked to ship it in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants