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 mkende force-pushed the mojo_js_inline_layout branch from 2c65608 to 2d74508 Compare December 5, 2021 22:36
@mkende mkende requested a review from kraih December 5, 2021 22:38
@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
@mergify mergify bot dismissed kraih’s stale review December 20, 2021 22:51

Pull request has been modified.

@mkende mkende force-pushed the mojo_js_inline_layout branch from f387dc2 to 77c1cab Compare December 20, 2021 22:52
@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 mkende requested a review from kraih December 20, 2021 22:57
@mkende mkende requested a review from marcusramberg January 18, 2022 21:45
@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 mkende force-pushed the mojo_js_inline_layout branch from 77c1cab to 9578a17 Compare January 31, 2022 22:20
@mkende mkende requested a review from kraih January 31, 2022 22:21
@mkende mkende force-pushed the mojo_js_inline_layout branch from 9578a17 to d7eb0a7 Compare January 31, 2022 22:23
@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.

@marcusramberg marcusramberg marked this pull request as draft August 26, 2023 08:11
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.

3 participants