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

Support for whitespace control (~) #52

Closed
rexm opened this issue Apr 30, 2015 · 9 comments
Closed

Support for whitespace control (~) #52

rexm opened this issue Apr 30, 2015 · 9 comments

Comments

@rexm
Copy link
Collaborator

@rexm rexm commented Apr 30, 2015

See the Whitespace Control section in the [http://handlebarsjs.com/expressions.html](handlebarsjs documentation):

Template whitespace may be omitted from either side of any mustache statement by adding a ~ character by the braces. When applied all whitespace on that side will be removed up to the first handlebars expression or non-whitespace character on that side.

{{#each nav ~}}
  <a href="{{url}}">
    {{~#if test}}
      {{~title}}
    {{~^~}}
      Empty
    {{~/if~}}
  </a>
{{~/each}}
@danielmarbach
Copy link
Contributor

@danielmarbach danielmarbach commented Apr 30, 2015

I cannot promise you anything but I might be able to help out. Can you add pointers to this issue where I should look for to get a headstart?

@rexm
Copy link
Collaborator Author

@rexm rexm commented Apr 30, 2015

The parser/lexer analyzes the template character-by-character and creates a sequence of tokens. Those token objects can have any number of properties on them that describe them, so we could indicate on the token whether it's a white space-removing token. However, this situation is a little tricky because we assume from the start that all text in the template is a static string of text (in fact that's the type of token it creates, static) and it's essentially hard-coded into the resulting compiled function. So we'd need to be able to seek "around" the token to look for white space and remove it, but that kind of logic happens further down at the expression conversion layer, after we've already set our static strings...

Sounds like an interesting project!

@BenSwayne
Copy link

@BenSwayne BenSwayne commented May 8, 2015

Hi Rex/Daniel,

If this requires a lot of reworking behind the scenes, why don't we implement a custom TextReader that removes white space from the template itself before the template even gets to the Handlebars.net parser/lexer?

Perhaps this goes against the idea of this library or academic best way of doing it, but I think it could be written in a half day without knowing too much about the underpinnings of this library.

Thoughts? Comments?

@rexm
Copy link
Collaborator Author

@rexm rexm commented May 8, 2015

That could maybe be an extension that lives in another project and allow for a pluggable TextReader in this one. The intent of this core is to provide parity with the original handlebarsjs library.

@rexm
Copy link
Collaborator Author

@rexm rexm commented Jul 21, 2015

FYI, I've implemented this in main, but the Travis build is failing for reasons still being investigated...

@rexm
Copy link
Collaborator Author

@rexm rexm commented Aug 3, 2015

This is implemented and currently available in the 1.5.0-beta version on NuGet. @danielmarbach @BenSwayne if convenient for you to test this updated package and feedback here, it would be appreciated!

@rexm
Copy link
Collaborator Author

@rexm rexm commented Aug 4, 2015

Now available in 1.4.2

@rexm rexm closed this Aug 4, 2015
@danielmarbach
Copy link
Contributor

@danielmarbach danielmarbach commented Aug 5, 2015

Amazing! Going to update my site soon. Thx again!

Am 04.08.2015 um 22:52 schrieb Rex Morgan notifications@github.com:

Now available in 1.4.2


Reply to this email directly or view it on GitHub.

@BenSwayne
Copy link

@BenSwayne BenSwayne commented Aug 5, 2015

Awesome @rexm! Sorry I didn't get a chance to test it in beta, but I will test within the next 10 days and likely have it in production on a few websites right away if testing goes well.

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

Successfully merging a pull request may close this issue.

None yet
3 participants