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

Unwanted newline #81

Open
zorbash opened this issue Aug 16, 2013 · 6 comments
Open

Unwanted newline #81

zorbash opened this issue Aug 16, 2013 · 6 comments

Comments

@zorbash
Copy link
Contributor

zorbash commented Aug 16, 2013

When using the require directive to embed a template file in another file the initial template source is altered (a newline is appended).

It may seem harmless but it may cause undesired and visible effects.

Example.

# base.js.coffee
#= require templates/foo

text = document.createTextNode(JST['foo']())
el = document.getElementById('container')
el.appendChild(text)
# templates/foo
no newline after this phrase

In the example above the text node will be

"no newline after this phrase
"

instead of "no newline after this phrase"

We have currently decided to trim the compiled template output before using it with text nodes. But is there another way around?

@zorbash
Copy link
Contributor Author

zorbash commented Aug 16, 2013

@AlexRiedler
Copy link
Collaborator

I suppose you could trim it in handlebars_assets as well, but that might also cause unexpected results (in certain cases). This is probably a really rare case though.

why not just do <p>no new line after this phrase</p> ; which fixes it for your example I believe ? potentially?
but maybe your toy example does not actually fully clarify the issue.

@zorbash
Copy link
Contributor Author

zorbash commented Aug 19, 2013

I agree that adding specific markup in a template may bypass the problem. But the thing here is that the template source is altered in a way that the same template source would yield different output when compiled in the browser.

@AlexRiedler
Copy link
Collaborator

So... I would love to just strip the whitespace, however in the case that someone ACTUALLY wants the whitespace then it would break that case... I also do not want to re-grab the body that tilt has already grabbed... hmmm this will plague all template compilers.

However there is a simple work-around in the case the user wants the whitespace (add two-newlines).

@zorbash, Agree with the trim at most one new-line approach?

@zorbash
Copy link
Contributor Author

zorbash commented Sep 25, 2013

@AlexRiedler Yes, if someone (for compatibility reasons perhaps) still wants the extra newline, two newlines should be inserted for this newline to be appended. Are you on it?

@AlexRiedler
Copy link
Collaborator

Yup, on it! (I think it may already be done on my branch; but still needs some verification with how HAML and SLIM works in this case).

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

No branches or pull requests

2 participants