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

Whitespace management #1072

Closed
pizzafroide opened this issue Aug 5, 2015 · 1 comment
Closed

Whitespace management #1072

pizzafroide opened this issue Aug 5, 2015 · 1 comment
Labels
Milestone

Comments

@pizzafroide
Copy link

New line characters after the start tag of a section, or after a comment, are discarded. I may be wrong but I think they shouldn't be.

Here is the example from the doc with a little modification (the ~ at the of the {{#each}} expression was removed):

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

with:

{
  nav: [
    {url: 'foo', test: true, title: 'bar'},
    {url: 'bar'}
  ]
}

results in:

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

Instead of:

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

Edit: When rereading the documentation, I see that:

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

So I guess this post is most likely an enhancement request: would it be possible to disable this default behavior?

@kpdecker
Copy link
Collaborator

It shouldn't be that hard to add a flag to disable this behavior, but I looking at your template, your issue is not due to the standalone behavior, but due to the use of whitespace control, as those will consume newlines (standalone does not for lines that aren't removed, i.e. </a>\n will be rendered vs. </a>). Removing the last ~, along with some stylistic cleanup that isn't substantial to the behavior seems to fix the issue:

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

    let hash = {
      nav: [
        {url: 'foo', test: true, title: 'bar'},
        {url: 'bar'}
      ]
    };

    shouldCompileTo(string, hash, '  <a href="foo">bar</a>\n  <a href="bar">Empty</a>\n');

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

No branches or pull requests

2 participants