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

Fix indent v2 #654

Merged
merged 10 commits into from
Jul 7, 2024
Merged

Fix indent v2 #654

merged 10 commits into from
Jul 7, 2024

Conversation

cmrschwarz
Copy link
Contributor

@cmrschwarz cmrschwarz commented Jun 30, 2024

This is my second attempt at fixing the more involved indenting issues first brought up in #650 .

It turns out that the Indent node is simply not powerful enough to handle all cases :(.

We will unfortunately have to dynamically track whether a partial ended on a newline or not.
This PR does exactly that.

Here are some of the more difficult edge cases that this solves:

Input

{{#*inline "empty_partial"}}{{/inline}}
<div>
    {{> empty_partial}}
</div>

Output

<div>
</div>

Input

{{#*inline "partial"}}foo{{/inline}}
<div>
    {{> partial}}
</div>

Output

<div>
    foo</div>

(yes, this is indeed correct according to handlebars js)


Input

Json Input: {"a": "line\ndynamic_trailing_newline\n"}

{{#*inline "dynamic_partial"}}{{a}}{{/inline}}
<div>
    {{> dynamic_partial}}
</div>

Output

<div>
    line
    dynamic_trailing_newline
</div>

@cmrschwarz cmrschwarz mentioned this pull request Jun 30, 2024
@coveralls
Copy link

Coverage Status

coverage: 81.605% (+0.1%) from 81.461%
when pulling bc67e05 on cmrschwarz:fix_indent_v2
into 3504412 on sunng87:master.

@coveralls
Copy link

Coverage Status

coverage: 81.625% (+0.2%) from 81.461%
when pulling 16109f6 on cmrschwarz:fix_indent_v2
into 3504412 on sunng87:master.

Copy link
Owner

@sunng87 sunng87 left a comment

Choose a reason for hiding this comment

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

I have been super busy these days. Really need some time to deep dive into this. But the test cases look good. I think this approach is more promising.

src/template.rs Outdated
@@ -143,10 +144,11 @@ pub struct HelperTemplate {
pub inverse: Option<Template>,
pub block: bool,
pub chain: bool,
pub indent_before_write: bool,
Copy link
Owner

Choose a reason for hiding this comment

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

I think we can make this field private, as well as the one for DecoratorTemplate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! I need them in render_helper, so I guess pub(crate) it is.

@coveralls
Copy link

Coverage Status

coverage: 81.625% (+0.2%) from 81.461%
when pulling 91579a4 on cmrschwarz:fix_indent_v2
into 3504412 on sunng87:master.

@cmrschwarz
Copy link
Contributor Author

cmrschwarz commented Jul 1, 2024

I've been using this in practice for a bit more now and found two minor issues with it.
The commits just now fixed those and added regression tests.
Otherwise this has worked nicely, indenting seems just about perfect now.

Edit: Well ok, you always miss something I guess :). Similar fix for partials below.

@coveralls
Copy link

Coverage Status

coverage: 81.714% (+0.3%) from 81.461%
when pulling a165d99 on cmrschwarz:fix_indent_v2
into 3504412 on sunng87:master.

@cmrschwarz cmrschwarz requested a review from sunng87 July 1, 2024 00:35
@coveralls
Copy link

Coverage Status

coverage: 81.724% (+0.3%) from 81.461%
when pulling 0af5ab5 on cmrschwarz:fix_indent_v2
into 3504412 on sunng87:master.

@sunng87
Copy link
Owner

sunng87 commented Jul 7, 2024

This looks good to me. Thank you for the fix! I have been struggling with those indent for quite a while. This approach seems practical and also keeps complexity at a acceptable level.

@sunng87 sunng87 merged commit dcb70c1 into sunng87:master Jul 7, 2024
9 checks passed
@sunng87
Copy link
Owner

sunng87 commented Jul 9, 2024

I just tried the case reported in #611, and it seems we still this corner case to cover.

@cmrschwarz
Copy link
Contributor Author

I just tried the case reported in #611, and it seems we still this corner case to cover.

I'm happy to look into that, though I'm quite busy this week so it might have to wait until the weekend.

@sunng87
Copy link
Owner

sunng87 commented Jul 9, 2024

Thank you and no rush @cmrschwarz . Just take your time.

@cmrschwarz cmrschwarz deleted the fix_indent_v2 branch July 13, 2024 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants