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

stripping lines that are "standalone" helpers #258

Closed
robinvd opened this issue Apr 3, 2019 · 9 comments · Fixed by #404
Closed

stripping lines that are "standalone" helpers #258

robinvd opened this issue Apr 3, 2019 · 9 comments · Fixed by #404

Comments

@robinvd
Copy link

robinvd commented Apr 3, 2019

In the handlebars.js docs the following is described (https://handlebarsjs.com/expressions.html):

This expands the default behavior of stripping lines that are "standalone" helpers (only a block helper, comment, or partial and whitespace).

They give the example:

{{#each nav}}
  <a href="{{url}}">
    {{#if test}}
      {{title}}
    {{^}}
      Empty
    {{/if}}
  </a>
{{~/each}}

That will render as

<a href="foo">
    bar
</a>
<a href="bar">
    Empty
</a>

Thus rendering the line {{#if test}} as nothing. Currenly on handlebars.rs:

----------
{{#if body}}
{{ body }}
{{/if}}

renders as

----------

body here

(notice the newline between '---' and 'body here'.) Is it possible to ignore those lines?

@sunng87
Copy link
Owner

sunng87 commented Apr 4, 2019

Good catch. This is what we should support.

@zuobaoquan
Copy link

Any plan on this? It is very annoying, especially when generating code.
P.S. Partial templates should be supported either.

@sunng87
Copy link
Owner

sunng87 commented Feb 1, 2020

This is blocked by an issue with pest parser. I'm waiting for pest 3.0 to see if it will be resolved.

@zuobaoquan
Copy link

This is blocked by an issue with pest parser. I'm waiting for pest 3.0 to see if it will be resolved.

Any issue reference? or could you create the issue on that repository? Thanks

@sunng87
Copy link
Owner

sunng87 commented Feb 4, 2020

IIRC this was the issue:

pest-parser/pest#396

@shawntabrizi
Copy link

+1 for running into this issue

@sunng87
Copy link
Owner

sunng87 commented Oct 29, 2020

I'm adding helper wanted label for this so anyone interested in could pick this up. I can offer help as much as I can.

@SuperCuber
Copy link

Currently, in my usage of handlebars, I use the rule of thumb of appending ~ to every part of conditional syntax.
For example:

-----
{{#if body~}}
{{body}}
{{else~}}
No body
{{/if~}}
More text

Will render as either

-----
Body here
More text

Or

-----
No Body
More Text

If I do want an empty line after the if-else block, I put it in both branches, and this of course works with no else block as well.

@shawntabrizi
Copy link

Yeah I was able to work around this too by actually prepending ~ everywhere:

https://github.com/paritytech/substrate/pull/7447/files

None the less, I still believe (although not 100% sure now) that the handlebars rendering by default would not need such stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants