Skip to content
This repository has been archived by the owner on Apr 4, 2019. It is now read-only.

Implement stripping #20

Merged
merged 1 commit into from
Apr 23, 2014
Merged

Implement stripping #20

merged 1 commit into from
Apr 23, 2014

Conversation

mmun
Copy link
Collaborator

@mmun mmun commented Apr 23, 2014

The parser now respects the handlebars whitespace control flags. Whitespace is removed from the AST at parse time. Any unnecessary text nodes are removed. This works nicely with single element programs. Instead of writing

{{#each}}<li>foo</li>{{/each}}

you can write

{{#each~}}
  <li>foo</li>
{{~/each}}

and still generate an optimized fragment

function build(dom) {
  var el0 = dom.createElement('li');
  dom.appendText(el0, 'foo');
  return el0;
}

@stefanpenner
Copy link
Collaborator

sometimes whitespace is important?

@mmun
Copy link
Collaborator Author

mmun commented Apr 23, 2014

@stefanpenner It only strips whitespace if you have added the ~ flags on the ends of the mustaches. If you haven't seen it before it's documented at the bottom of http://handlebarsjs.com/block_helpers.html.

@mmun
Copy link
Collaborator Author

mmun commented Apr 23, 2014

Oops, the PR text was a bit confusing. I clarified it.

@stefanpenner
Copy link
Collaborator

@mmun aaaa

krisselden added a commit that referenced this pull request Apr 23, 2014
@krisselden krisselden merged commit 5c787ab into tildeio:master Apr 23, 2014
@mmun mmun deleted the strippers branch April 23, 2014 08:01
@oligriffiths
Copy link

Hey, I see this works for {{#each~}}, however it doesn't seem to work for an if statement:

works as expected:

{{#each titleParts as |part|~}}
    {{part.value}}
{{~/each}}

spaces appear:

{{#each titleParts as |part|~}}
    {{#if part.highlight}}
        <span class="highlight">
            {{part.value}}
        </span>
    {{else}}
        {{part.value}}
    {{/if}}
{{~/each}}

Any advice?

Thanks

@Cheralyn
Copy link

Cheralyn commented Apr 4, 2016

This is an automatically generated message.

coferc@yahoo-inc.com is no longer with Yahoo! Inc.

Your message will not be forwarded.

If you have a sales inquiry, please email yahoosales@yahoo-inc.com and someone will follow up with you shortly.

If you require assistance with a legal matter, please send a message to legal-notices@yahoo-inc.com

Thank you!

@oligriffiths
Copy link

It appears that

{{#each titleParts as |part|~}}
    {{~#if part.highlight~}}
        <span class="highlight">{{part.value}}</span>
    {{~else~}}
        <span class="no-highlight">{{part.value}}</span>
    {{/if}}
{{~/each}}

does the trick

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

Successfully merging this pull request may close these issues.

5 participants