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

No use for output of parse #258

Closed
thedufer opened this issue Sep 19, 2012 · 2 comments
Closed

No use for output of parse #258

thedufer opened this issue Sep 19, 2012 · 2 comments

Comments

@thedufer
Copy link

I can parse a template, but there is no corresponding function for rendering and/or compiling the parsed template. It would be nice to have compile skip parsing if the template argument is an array (presumably of tokens).

@thedufer
Copy link
Author

thedufer commented Oct 2, 2012

Feels a little silly that compiling tokens still requires the original template. Unfortunately, the tokens don't contain enough information to avoid this, so this is not a minor change.

For now, it appears that it does not require the template if you don't render with functions in the data, so its enough for my uses.

@mjackson
Copy link
Contributor

mjackson commented Oct 9, 2012

Yes, I agree. This is because the parsing function is destructive, atm. The most common example of this is when "unintended" whitespace is stripped from tokens. For example, when compiling the following template:

{{#foo}}
<li>A {{name}}.</li>
{{/foo}}

We strip the trailing \n character after the {{#foo}} tag. This makes it easy for users to get the output they expect without putting things on separate lines. Thus, if at render time we discover that foo is actually a higher order function we have no way of getting back the original text that was used in that section.

To work around this problem we pass the original template all the way through to the compiled rendering function so that it can slice on that string if it needs to get the original text between the bounds that indicate the beginning/end of that section. But I realize this is a bit messy, and I'm totally open to a better solution here. :)

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

No branches or pull requests

2 participants