Seems like a useful approach. Thanks for sharing. WILL
On 12/18/06, James Wilson <[EMAIL PROTECTED]> wrote:
Marc Novakowski wrote: > Yeah, we use the ## trick in a few macros where removal of whitespace is > critical. In most templates, extra whitespace isn't a big deal since, > in the end, it's all gobbled into a single whitespace character by the > HTML parser. It's just when you look at the HTML source, it's ugly! > > Also, the "##" trick only works to remove newlines, but the indentation > whitespace (i.e. tabs or spaces) before the velocity statement on the > line will still be there. > > In (my) ideal world, the following: > > <table> > <tr> > #if ($foo == "bar") > <td>Fred</td> > #else > <td>Bob</td> > #end > </tr> > </table> > > > Would result in: > > <table> > <tr> > <td>Fred</td> > </tr> > </table> But what is wrong with just providing a custom filter writer to the mergeTemplate method? It seems to me that you can create any whitespace policy you want this way. Or better yet -- a chained filter writer. One that deals with spaces and maybe another that deals with eols. I put an example of this on this list a long time ago -- here it is again. These writers can be greatly improved but they worked for us. James > Marc > > > On 21-Nov-06, at 9:56 AM, Will Glass-Husain wrote: > >> Hi Marc, >> >> Thanks for the input. There seems to be widespread dissatisfaction >> with the status quo on this issue, yet it's a tricky issue to change >> while maintaining backwards compatibility (involves fundamental >> changes to the parser). Currently thinking about this as part of some >> future 2.0 version. >> >> Incidentally, the best solution for leaving out extra newlines is to >> put "##" at the end of each line. This kills the newline. Doesn't >> help the issue of extra spaces before indented statements, though. >> >> WILL >> >> On 11/21/06, Marc Novakowski <[EMAIL PROTECTED]> wrote: >>> I've been meaning to add my vote to this page, so I finally did it. >>> +1 for gobbling structured templates. >>> >>> We use velocity for most of the "backstage" area at Pandora. It's >>> made development so much easier! However, the final HTML looks quite >>> messy due to all of the extra whitespace introduced by the velocity >>> templates. >>> >>> Marc >>> >>> On 14-Nov-06, at 8:18 AM, [EMAIL PROTECTED] wrote: >>> >>> > See the Wiki on this issue: >>> > http://wiki.apache.org/jakarta-velocity/VelocityWhitespaceGobbling >>> > >>> > Please add your opinion (well thought out) or vote for one of the >>> > presented approaches. >>> > >>> > Cheers, >>> > Christoph >>> > >>> > Paul Loy wrote: >>> >> I would be very interested in a solution to this problem. From a code >>> >> layout point of view this would be an important feature. Consider: >>> >> >>> >> <div> >>> >> " >>> >> >>> >> #if ($somevar) >>> >> $somevar >>> >> #else >>> >> nothing here >>> >> #end >>> >> >>> >> " >>> >> </div> >>> >> >>> >> This nicely formatted code makes it easy to see what's going on >>> >> but will >>> >> make the html render with spaces in it like so (if $somevar is >>> >> false or >>> >> null): >>> >> >>> >> ' nothing here ' >>> >> >>> >> Now this is a silly example and in this case it would be much >>> >> easier to >>> >> simply do this to eliminate the problem: >>> >> >>> >> >>> >> <div> >>> >> >>> >> #if ($somevar) >>> >> "$somevar" >>> >> #else >>> >> "nothing here" >>> >> #end >>> >> >>> >> </div> >>> >> >>> >> but in more complex examples you'd either have a great amount of >>> >> duplicated HTML, which makes it bad to maintain and update, or you'd >>> >> have to make unreadable code (everything on one line with no white >>> >> spaces). >>> >> >>> >> I converted an old nasty taglibbed jsp into velocity and although I >>> >> cleaned up the html (removing 20+ unnecessary nested tables) the >>> >> filesize of the velocity version was actually slightly bigger than >>> >> the >>> >> old version because of all the whitespace. >>> >> >>> >> So... I would very much like velocity to perhaps remove whitespace >>> >> between a directive (i.e. a # statement) and any other code. >>> >> >>> >> Paul. >>> >> >>> >> Timothy Stone wrote: >>> >>> List, >>> >>> >>> >>> We noticed in #parse'ing an .vm file, excess whitespace, or >>> >>> linefeeds, >>> >>> are appearing in our templates after merge. >>> >>> >>> >>> For example, where a '+' indicates a line feed or carriage return: >>> >>> >>> >>> [mystyles.vm] >>> >>> + >>> >>> #set( $foo = "Copyright (c)") >>> >>> + >>> >>> #set( $bar = "2006" ) >>> >>> + >>> >>> >>> >>> >>> >>> [myemail.txt] >>> >>> #parse("mystyles.vm") >>> >>> + >>> >>> Dear bloated warthog, >>> >>> blah >>> >>> + >>> >>> blah >>> >>> + >>> >>> blah >>> >>> + >>> >>> Regards, >>> >>> Man in Black >>> >>> + >>> >>> ${foo} ${bar} >>> >>> >>> >>> [The final output] >>> >>> + >>> >>> + >>> >>> + >>> >>> + >>> >>> Dear bloated warthog, >>> >>> blah >>> >>> + >>> >>> blah >>> >>> + >>> >>> blah >>> >>> + >>> >>> Regards, >>> >>> Man in Black >>> >>> + >>> >>> Copyright (c) 2006 >>> >>> >>> >>> Can these extra lines be managed in some way? >>> >>> >>> >>> Thanks, >>> >>> Tim -- James Wilson Developer U.S. District Court District of New Mexico 333 Lomas Blvd., NW Albuquerque, NM 87102 Phone: (505) 348-2081 Fax: (505) 348-2028 [EMAIL PROTECTED] -- --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- Forio Business Simulations Will Glass-Husain [EMAIL PROTECTED] www.forio.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
