Skip to content

Fix indent v2#654

Merged
sunng87 merged 10 commits into
sunng87:masterfrom
cmrschwarz:fix_indent_v2
Jul 7, 2024
Merged

Fix indent v2#654
sunng87 merged 10 commits into
sunng87:masterfrom
cmrschwarz:fix_indent_v2

Conversation

@cmrschwarz

@cmrschwarz cmrschwarz commented Jun 30, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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
Copy Markdown

Coverage Status

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

@sunng87 sunng87 left a comment

Copy link
Copy Markdown
Owner

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.

Comment thread src/template.rs Outdated
pub inverse: Option<Template>,
pub block: bool,
pub chain: bool,
pub indent_before_write: bool,

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

Coverage Status

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

@cmrschwarz

cmrschwarz commented Jul 1, 2024

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown

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
Copy Markdown

Coverage Status

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

@sunng87

sunng87 commented Jul 7, 2024

Copy link
Copy Markdown
Owner

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
@sunng87

sunng87 commented Jul 9, 2024

Copy link
Copy Markdown
Owner

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

@cmrschwarz

Copy link
Copy Markdown
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

sunng87 commented Jul 9, 2024

Copy link
Copy Markdown
Owner

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