-
Notifications
You must be signed in to change notification settings - Fork 479
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
Add template trim of white space to dust.compile #166
Conversation
This change allows dust templates to be compiled in a minified way. Specifically, all leading whitespace is removed, then all newlines are removed. This can be beneficial because Dust currently writes all whitespace, which can result in HTML like this: <a href=" index.html ">My link</a>
@jairodemorais added as minifier with uglify ( would be good to integrate together ) |
@vybs does uglify minify our Dust templates? If not, what is uglify minifying? |
@jairodemorais knows more. I forget. |
I think uglify might be overkill for minifying templates on compile, when
|
it is not minify perse. the term is pretty misleading |
|
I agree. It's not minify in the same way that Uglify and Google Closure does minification. But, I still think it is useful. Any suggestions on better names? strip? trim? removeExcessWhitespace? |
Are we concerned about it removing new lines in templates that are intentional? |
New lines in templates that are intentional should use |
Can always ensure that is the case. Just be careful we dont break anything in use already |
It seems okay, since this is triggered with an option anyway. We can easily turn it off if it causes a problem. |
i would rather prefer, strip/trim ( newlines/spaces/tabs) add docs into what this does exactly. |
Update testcases and renderTestSpec.js with new name.
While we are talking about whitespace, is there any good way for someone to do the equivalent of writing a multi-line block where the alignment and whitespace are preserved? I don't know of one. Granted it is not a common need but it does come up. |
code example @rragan What I want to generate is: myvar=1; if (a === b) { a = b+1; } Adding <br/> will force one line per output line (like pre) but we still lack the indentation. Changing the leading spaces to would likely suffice to get the whitespace but the whole thing is very unpleasant for common genre's of documentation (e.g. writing about code). |
@rragan Preserving whitespace (but only in some places) definitely complicates this issue. Are you looking for what is offered by the |
I don't need the capability often unless I'm writing web pages about code (heaven forbid it's about Python where whitespace is signficant). When I need it, writing the page in dust will be a major pain to write and/or update. |
Is @rragan 's issues blocking this from being merged? |
I don't see that my comment has any impact on this proposed change. Any solution for a pre-like ability will have to be a very special case and likely not to interact with this change. I don't know that there are "backward compatibility" issues with this change but there could be. Browsers generally gobble up extra whitespace but still can do things that affect visual impact when tags have newline/extra blank floating around between them. What, if any, weight should this have? |
There shouldn't be any backwards compatibility issues because you have to opt in to make strip do anything. |
Add template strip of white space to dust.compile (optional defaults to not strip)
This change allows dust templates to be compiled in a minified way. Specifically, all leading whitespace is removed, then all newlines are removed. This can be beneficial because Dust currently writes all whitespace, which can result in HTML like this:
My link