4 ms·
This change simply draws from Jinja, which has had this feature for nearly 10 years[0]. It's a simple and efficient solution to the problem of trimming whitespa
by masklinn 11y ago
This change simply draws from Jinja, which has had this feature for nearly 10 years[0]. It's a simple and efficient solution to the problem of trimming whitespace on either side of a template tag, I fail to see what is kludgy about it (and intuitiveness is in the eye of the beholder). In my experience it's clear, simple and doesn't make the template less readable.
> Sure, it's terse and being terse can be nice, but terseness to me probably doesn't even make it into my top 10 concerns when designing a language or library.
The whole point of this feature is to be terse, otherwise you could already use template comment to trim formatting whitespace.
[0] http://jinja.pocoo.org/docs/dev/templates/#whitespace-control http://jinja.pocoo.org/docs/dev/templates/#whitespace-contro...
- zimpenfish 11y agoPerl's Template Toolkit has had this feature since at least 2001 (and I remember it being available before that but my googlefu is failing me right now.) cf http://www.perl.com/pub/2001/01/tt2.html http://www.perl.com/pub/2001/01/tt2.html > If these tags are replaced with [%- -%] then the preceding or following linefeed is suppressed.
- masklinn 11y agoNice, thanks for the history lesson. Now I wonder whether Armin Ronacher got it from there or independently reinvented it.
- ebbv 11y ago> The whole point of this feature is to be terse... I get that. I don't think you understood my objection, which was that being terse is not as important to me as being elegant and easily understood. {{foo -}} is not clear looking at it what that - is gonna do. You have to already know, or look it up. There is basically no way to know from context what the desired behavior is. That's bad design IMHO.
- freyr 11y agoHow much programming language syntax is really intuitive, as compared to what you've grown familiar with over time? Once you use the Go(/Jinja/Perl) syntax once or twice, then putting a minus sign to remove whitespace will be easily understood. I am interested in an alternative that you find more elegant.
- cyphar 11y ago> I am interested in an alternative that you find more elegant. Why not make it a filter/pipeline (I haven't used template/text in ages, does it support this?), like in Django {{ thing|trimleft }}.
- yrro 11y ago{{ foo -}} does not strip white space from the output of foo. It eats up the following white space. So "{{ foo -}} bar" renders the same as "{{ foo }}bar".