You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Christoph Reck <Ch...@dlr.de> on 2001/05/03 15:19:19 UTC

[PROPOSAL] Whitespace handling

The current whitespace handling seems to be as follows:
1. Any whitespace upto/including the EOL after a directive is gobbled.
2. Leading whitespaces are not touched.
   Up to some point it seemed to me that leading whitespaces where 
   swallowed only by the #set() directive (I guess as a compatiblity 
   result of the deprecated #set syntax).

My proposal for whitespace handling is the following:
A. Any directive standalone within one line like these
       #if(...)
         ## a comment
         #set(...)
         schmoo
       #else
         #foo(...)
         bark
       #end
   should gobble leading and trailing whitepaces including the EOL.
   This example should emit the indented "schmoo" or "bark" as is,
   with no whitespace from the directives.
B. As soon as something other is on the same line, it does not
   touch the leading whitespaces, keeping the effect of (1) above.
   This should keep the changes impact low. 
   Thus:
       #if(...)#* a comment *##set(...)  schmoo#else#foo(...)  bark#end#**#
   will emit just the same! Note the LF after the #end would have
   been gobbled by (1), so the gobbling has been escaped by the 
   embedded comment at the end.

One case it would affect existing code is where a #parse() was used 
indented (I normally added an empty line before the content to avoid 
making the extra indented whitespace visible). 

Whitespace gobbling can be inhibited transparently by adding a #**# 
before or after the directive.

EOL gobbling can already be induced by adding an ## to the end of 
the line.

Currently I need to do funny poor-man's-escaping to achieve the 
desired pretty output with the not-so-pretty VTL:
#*   *##if(...)
#*     *### a comment
#*     *##set(...)
         schmoo
#*   *##else
#*     *##foo(...)
         bark
#*   *##end
or
...#*
       *##if(...)#*
         *##* a comment *##*
         *##set(...)
         schmoo$LF#*
       *##else#*
         *##foo(...)
         bark$LF#*
       *##end
Does someone have a better suggestion to obtain the same results?

:) Chirstoph


"Geir Magnusson Jr." wrotein thread "Re: WM difference question":
> 
> David Rees wrote:
> >
> > :-)  You are correct.  However, there are cases when it'd be useful to turn
> > off whitespace, but I haven't thought of a good, clean way to do it.  I
> > don't know if there is, so it's better to just have to deal with the
> > whitespace in the normal manner.
> 
> I was thinking about this when wandering down my driveway to get the
> paper this morning and have a few ideas, so will try to find some
> freetime and play with them.
> 
> The issues that come up are 'accuracy' vs 'what you expect', as people
> doing HTML don't care most of the time about extra whitespace, where a
> person formatting a report would,  and 'pretty templates' vs 'pretty
> output' -> for example, when using Vel to generate code (Java, SQL,
> etc), what do you want to be pretty?  The template for you author, or
> the generated code, the output.  I think it depends on the specific
> context, as some people don't look at the generated code (but some do),
> and you can see how this contrasts with HTML output, which is tolerant
> of pretty much anything.
> 
> However, we already aren't pure : #<directive>() should automatically
> eat the newline right now :)
> 
> geir

RE: [PROPOSAL] Whitespace handling

Posted by Matt Quail <ma...@cortexebusiness.com.au>.
I've also been burnt by whitespace handling in Velocity.

This proposal seems good. It gets my vote :)

=Matt
Matt Quail -- Senior Software Engineer
http://www.cortexebusiness.com.au/
mailto:matt@cortexebusiness.com.au
+61 2 9901 6400
 
> -----Original Message-----
> From: Christoph.Reck@esrin.esa.it [mailto:Christoph.Reck@esrin.esa.it]On
> Behalf Of Christoph Reck
> Sent: Thursday, 3 May 2001 23:19 PM
> To: velocity-user@jakarta.apache.org
> Subject: [PROPOSAL] Whitespace handling
> 
> 
> The current whitespace handling seems to be as follows:
> 1. Any whitespace upto/including the EOL after a directive is gobbled.
> 2. Leading whitespaces are not touched.
>    Up to some point it seemed to me that leading whitespaces where 
>    swallowed only by the #set() directive (I guess as a compatiblity 
>    result of the deprecated #set syntax).
> 
> My proposal for whitespace handling is the following:
> A. Any directive standalone within one line like these
>        #if(...)
>          ## a comment
>          #set(...)
>          schmoo
>        #else
>          #foo(...)
>          bark
>        #end
>    should gobble leading and trailing whitepaces including the EOL.
>    This example should emit the indented "schmoo" or "bark" as is,
>    with no whitespace from the directives.
> B. As soon as something other is on the same line, it does not
>    touch the leading whitespaces, keeping the effect of (1) above.
>    This should keep the changes impact low. 
>    Thus:
>        #if(...)#* a comment *##set(...)  schmoo#else#foo(...)  
> bark#end#**#
>    will emit just the same! Note the LF after the #end would have
>    been gobbled by (1), so the gobbling has been escaped by the 
>    embedded comment at the end.
> 
> One case it would affect existing code is where a #parse() was used 
> indented (I normally added an empty line before the content to avoid 
> making the extra indented whitespace visible). 
> 
> Whitespace gobbling can be inhibited transparently by adding a #**# 
> before or after the directive.
> 
> EOL gobbling can already be induced by adding an ## to the end of 
> the line.
> 
> Currently I need to do funny poor-man's-escaping to achieve the 
> desired pretty output with the not-so-pretty VTL:
> #*   *##if(...)
> #*     *### a comment
> #*     *##set(...)
>          schmoo
> #*   *##else
> #*     *##foo(...)
>          bark
> #*   *##end
> or
> ...#*
>        *##if(...)#*
>          *##* a comment *##*
>          *##set(...)
>          schmoo$LF#*
>        *##else#*
>          *##foo(...)
>          bark$LF#*
>        *##end
> Does someone have a better suggestion to obtain the same results?
> 
> :) Chirstoph
> 
> 
> "Geir Magnusson Jr." wrotein thread "Re: WM difference question":
> > 
> > David Rees wrote:
> > >
> > > :-)  You are correct.  However, there are cases when it'd be 
> useful to turn
> > > off whitespace, but I haven't thought of a good, clean way to 
> do it.  I
> > > don't know if there is, so it's better to just have to deal with the
> > > whitespace in the normal manner.
> > 
> > I was thinking about this when wandering down my driveway to get the
> > paper this morning and have a few ideas, so will try to find some
> > freetime and play with them.
> > 
> > The issues that come up are 'accuracy' vs 'what you expect', as people
> > doing HTML don't care most of the time about extra whitespace, where a
> > person formatting a report would,  and 'pretty templates' vs 'pretty
> > output' -> for example, when using Vel to generate code (Java, SQL,
> > etc), what do you want to be pretty?  The template for you author, or
> > the generated code, the output.  I think it depends on the specific
> > context, as some people don't look at the generated code (but some do),
> > and you can see how this contrasts with HTML output, which is tolerant
> > of pretty much anything.
> > 
> > However, we already aren't pure : #<directive>() should automatically
> > eat the newline right now :)
> > 
> > geir
>