tests-always-included / mo

Mustache templates in pure bash
Other
563 stars 67 forks source link

Broken alignment for partials standing in the adjacent lines #16

Closed maslennikov closed 7 years ago

maslennikov commented 7 years ago

This can be reproduced by a test: tests/partial.template:

<h2>Alignment spaced</h2>
    {{> partial.partial2}}

    {{> partial.partial2}}

<h2>Alignment unspaced</h2>
    {{> partial.partial2}}
    {{> partial.partial2}}
    {{> partial.partial2}}
    {{> partial.partial2}}

<h2>Alignment mixed with text</h2>
    text
    {{> partial.partial2}}
    text
    {{> partial.partial2}}
    text
    {{> partial.partial2}}

tests/partial.partial2:

first line
second line
last line

output of ./mo tests/partial.template:

<h2>Alignment spaced</h2>
    first line
    second line
    last line

    first line
    second line
    last line

<h2>Alignment unspaced</h2>
    first line
    second line
    last line
    first line
second line
last line

    first line
    second line
    last line
    first line
second line
last line

<h2>Alignment mixed with text</h2>
    text
    first line
    second line
    last line
    text
    first line
    second line
    last line
    text
    first line
    second line
    last line

As it can be seen, when partials come line-by-line, every second partial gets messed up: alignment starting from the second line breaks and additional new line appears.

I tried to debug it, ended up figuring that moIsStandalone triggers false for every of these buggy cases. I didn't manage to understand from the first glance how to approach this function though, for that I apologize :)

I had a second thought that maybe the trailing newline in the partial file causes that behavior but this seems not to be true after some quick tries.

maslennikov commented 7 years ago

I also checked whether it could be a regression from the last --fail-not-set implementation, and it is not the case.

fidian commented 7 years ago

I've made a patch and fixed your use case. Would you confirm that it works for you?

maslennikov commented 7 years ago

Wow that was super fast! Many thanks Tyler! I've tested it additionaly with my yaml documents I am generating, they are perfectly fine now.

fidian commented 7 years ago

Thanks for checking it for me! Closing the issue.