Fix indent v2
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>
coverage: 81.605% (+0.1%) from 81.461% when pulling bc67e0585adc0192d5a5ca017df0326b87abd6a4 on cmrschwarz:fix_indent_v2 into 3504412d70b2f7f3dc609a09e9333402429ab2b5 on sunng87:master.
coverage: 81.625% (+0.2%) from 81.461% when pulling 16109f659582510d2a46072933106b731332eec8 on cmrschwarz:fix_indent_v2 into 3504412d70b2f7f3dc609a09e9333402429ab2b5 on sunng87:master.
coverage: 81.625% (+0.2%) from 81.461% when pulling 91579a4caa92626a127fa46cfe1ebad4e29e366f on cmrschwarz:fix_indent_v2 into 3504412d70b2f7f3dc609a09e9333402429ab2b5 on sunng87:master.
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.
coverage: 81.714% (+0.3%) from 81.461% when pulling a165d99cdcf3bb99a04fc58e047fa027209b9f94 on cmrschwarz:fix_indent_v2 into 3504412d70b2f7f3dc609a09e9333402429ab2b5 on sunng87:master.
coverage: 81.724% (+0.3%) from 81.461% when pulling 0af5ab55a2427c4e090e2d63b053f1421e2635ce on cmrschwarz:fix_indent_v2 into 3504412d70b2f7f3dc609a09e9333402429ab2b5 on sunng87:master.
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.
I just tried the case reported in #611, and it seems we still this corner case to cover.
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.
Thank you and no rush @cmrschwarz . Just take your time.