Hi, I'll try to clarify/help-out on the velocity usage for your 
requested examples.

[EMAIL PROTECTED] wrote:
>[snip]
> #table($title, $data):
>   #columns
>      <TH>$row.one</TH> <TD>$row.two</TD>
>   #end
> #end
> 
> where table might be defined as
> 
> #vmmacro(table, $title, $data, $columns)
>     <TABLE>
>     #foreach ($row in $data)
>         <TR>
>      #parse($columns)
>         </TR>
>     #end
>    </TABLE>
> #end
>[snip]

The #parse above needs to be done using a context tool (we had some
discussions of providing an #eval directive... But now with the
methods velocity.app.Velocity.java class, this is easy to create.
The just turn the #table macro call around and bingo:
#set( $columns = '<TH>$row.one</TH> <TD>$row.two</TD>' )
#table($title, $data, $columns)

The second example is just as easy turing your suggestion
inside-out:

[EMAIL PROTECTED] wrote in a latter mail:
>[snip]
> I don't know if a different example will help or not. Here the idea has
> nothing to do with tables or row. Here the idea is to reuse the HTML layout
> needed to throw box around some element.
> 
> #vmacro(boxIt, $width, $body)
> <table width=$width cellpadding=1 cellspacing=0 border=0><tr><td bgcolor="
> #000000">
>   <table cellpadding=5 cellspacing=0 border=0 width="100%">
>     <tr>
>       <td bgcolor="#f0f0f0">
>         $body
>       </td></tr></table>
>     </td></tr></table>
> #end
> 
> Now its arguable that there is enough layout there to make desire reuse.
> The normal macro system seems to handle this too, what I am suggesting is
> that when you call such a thing you can specify the body inline.
> 
> #boxit("90%")
>   #body
>      <p>This is the stuff that gets put inside a box</p>
>   #end
> #end
>[snip]
> Did I make things better or worse? :)
I've found velocity to be a great and simple language. Extensions
are made with context tools, and in some seldom cases with additional
user created directives (methodolgy to do so must be enhanced a bit
- e.g. the way of spcifying the valid directives...). 

If you change your point of view a bit, you will see things clearer
(and simpler... :)

In the boxit example above just do:
#set( $body = '<p>This is the stuff that gets put inside a box</p>' )
#boxit("90%" $body)


Ben, not some things on punctuation, you have some extra commas and
a stray colon in your examples. I guess the commas will make the
parser bark; whereas the extra colon will show up in the generated
output (velocity is gigo :). I used the single quote in my 
#set( $columns = '...' ) recommendation to keep the parser from
interpreting the code within; the macro body of #table must use
a context tool to merge the content. Also note that velocity is
not yet 100% consistent to whitespace handling, indented directives
make ugly output, I currently use a trick to overcome this, e.g.:
---
#vmmacro(table $title $data $columns)
  <TABLE>#* a line-spanning coment here gobbles the next indent spaces
   *##foreach ($row in $data)#* this comment makes the next a new line *#
    <TR>
      $merger.render($columns, "      ")
    </TR>#* ... same as the comments above (you can leave the texts away) ...
   *##end#**#
 </TABLE>
#end
---
And the above will produce nicely created output from your (nicely 
formatted) input! I have posted a suggestion on whitespace handling
on standalone directives to avoid the need of extra #*comments*#
to achieve ones needs... and will follow this up now that the initial
release has been completed (it requires an overhaul that was to risky 
for a pre 1.0 change).

Hope this helped,
:) Christoph

Reply via email to