You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Thomas Åhlen <th...@obidobi.net> on 2001/11/26 22:37:40 UTC

requesting some visual improvment to parsing output

I really want my html code to look nice after the velocity has had it's go
at it.

Example:

[test.html]
text before parse
     #parse( "test2.html" )
text after parse

[test2.html]
text inside parse

[output]
text before parse
                               text inside parsetext after parse

[wanted output]
text before parse
    text inside parse
text after parse

It seems like this line
(4 spaces)(parse directive)(newline)
    #parse( "...")

always are replaced by this
(24 spaces)(parse output)

I want velocity to remember (4 spaces) and (newline) by default. Is this to
much to ask? :)

Thomas




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: requesting some visual improvment to parsing output

Posted by James Cook <ji...@iname.com>.
I've also noticed that comments sometimes remove whitespace. If I have the
following in a <script> tag:

<script>
	// ## Some comment
	function someMethod() {
	}
</script>

I end up with:

<script>
	// function someMethod() {
	}
</script>

Which can really make debugging a pain. I have to remember to keep a blank
space after all comments.

-jim

> -----Original Message-----
> From: Tim Colson [mailto:tcolson@cisco.com]
> Sent: Tuesday, November 27, 2001 10:46 AM
> To: Velocity Users List
> Subject: RE: requesting some visual improvment to parsing output
>
>
> With apologies to Christoph as I can't recall the exact details of his
> previous proposal (and I'm too lazy/busy to search right now), I'd like to
> just mention an alternative used in another system that I thought
> worked ok.
> This isn't meant to be a recommendation or proposal - just one more way it
> could be done. ;-)
>
> Newlines/spaces were included in the parsed template output.
> (If you typed it, the engine expected that meant you wanted it.)
>
> For sections where extra whitespace is not desired (for example,
> a chunk of
> commands like in Christoph's dump.vm) a directive is inserted to turn off
> extraneous output.
>
> Pseudo Example: space.vm
> --
> <pre>
>      This line
>      has  #if($foo)$foo#end
>      important whitespace.
> </pre>
> #space_off
> ## Stuff happens here and we want to gobble all whitespace
>   #if( $type.startsWith("java.lang.") )
>      #if( $type == "java.lang.String" )
>          #set( $out = "String Thingy" )
>          #out ("Thing is of type $out.<BR>")
>      #end
>   #end
> #space_on
> <PRE>  $type   =$out</PRE>
> #space_off
> etc...
> --
> Note how an explicit output directive also exists so that chunks of
> formatted code can still print output.
>
> As I said, this is just a different option - not an endorsement.
>
> Timo
> BTW - didn't want to tell above, lest some of you might ignore on
> principle,
> but the 'system' was Cold Fusion. ;-)
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: requesting some visual improvment to parsing output

Posted by Tim Colson <tc...@cisco.com>.
With apologies to Christoph as I can't recall the exact details of his
previous proposal (and I'm too lazy/busy to search right now), I'd like to
just mention an alternative used in another system that I thought worked ok.
This isn't meant to be a recommendation or proposal - just one more way it
could be done. ;-)

Newlines/spaces were included in the parsed template output.
(If you typed it, the engine expected that meant you wanted it.)

For sections where extra whitespace is not desired (for example, a chunk of
commands like in Christoph's dump.vm) a directive is inserted to turn off
extraneous output.

Pseudo Example: space.vm
--
<pre>
     This line
     has  #if($foo)$foo#end
     important whitespace.
</pre>
#space_off
## Stuff happens here and we want to gobble all whitespace
  #if( $type.startsWith("java.lang.") )
     #if( $type == "java.lang.String" )
         #set( $out = "String Thingy" )
         #out ("Thing is of type $out.<BR>")
     #end
  #end
#space_on
<PRE>  $type   =$out</PRE>
#space_off
etc...
--
Note how an explicit output directive also exists so that chunks of
formatted code can still print output.

As I said, this is just a different option - not an endorsement.

Timo
BTW - didn't want to tell above, lest some of you might ignore on principle,
but the 'system' was Cold Fusion. ;-)


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: requesting some visual improvment to parsing output

Posted by Christoph Reck <Ch...@dlr.de>.
The whitespace handling has been an issue since beginning of Velocity.
I have posted a suggestion on how IMHO it should be. Please look for the 
thread on whitespace handling.

The essence is that standalone directives should not output
any whitespaces (including EOL) around it. We could make an
exception for #macro calls, #parse and #include, since these 
insert code at the given location.

Please let me know if I should resubmit my proposal.

:) Christoph

P.S. Look at the Anakia generated docs on how strangely formatted 
the output looks.


Thomas Åhlen wrote:
> 
> I really want my html code to look nice after the velocity has had it's go
> at it.

Fully agree with this!
Currently I use EOL escaping (with a ## at line end) and /*
    space esacaping */ for indented directives to have
somewhat formatted input templates that generate nice output.

> 
> Example:
> 
> [test.html]
> text before parse
>      #parse( "test2.html" )
> text after parse
> 
> [test2.html]
> text inside parse
> 
> [output]
> text before parse
>                                text inside parsetext after parse
> 
> [wanted output]
> text before parse
>     text inside parse
> text after parse
> 
> It seems like this line
> (4 spaces)(parse directive)(newline)
>     #parse( "...")
> 
> always are replaced by this
> (24 spaces)(parse output)
> 
> I want velocity to remember (4 spaces) and (newline) by default. Is this to
> much to ask? :)
> 
> Thomas
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: requesting some visual improvment to parsing output

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 11/26/01 4:37 PM, "Thomas Åhlen" <th...@obidobi.net> wrote:

> I really want my html code to look nice after the velocity has had it's go
> at it.
> 
> Example:
> 
> [test.html]
> text before parse
>    #parse( "test2.html" )
> text after parse
> 
> [test2.html]
> text inside parse
> 
> [output]
> text before parse
>                              text inside parsetext after parse
> 
> [wanted output]
> text before parse
>   text inside parse
> text after parse
> 
> It seems like this line
> (4 spaces)(parse directive)(newline)
>   #parse( "...")
> 
> always are replaced by this
> (24 spaces)(parse output)
> 
> I want velocity to remember (4 spaces) and (newline) by default. Is this to
> much to ask? :)
> 

There does seem to be a problem there with the extra spaces.

The newline though is by design - we eat newlines on single-line directives
- which may not be right, as you point out.

Will look at the space issue first...

> Thomas
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>