You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Vincent Faidherbe <vf...@icogs.com> on 2001/07/26 01:20:49 UTC

plug-in directives

I've two questions :
- What are the difference beetween macro and plug-in directives ?
- How to create plug-in directives ?

Vincent Faidherbe.



Re: plug-in directives

Posted by Nick Bauman <ni...@cortexity.com>.
> 
> 1  If you can, use a VM.
> 2) If you can't use a VM, use a context tool.
> 3) If you can't use a context tool, rethink the problem.
> 
> :)

Absolutely. I'm posting this to emphasize the wisdom in this line of 
thinking. Cool Geir.

> The real use for a directive is a place where you need to be involved
> with the structure of the template itself...
> 
> geir
> 

-- 
Nick Bauman



Re: plug-in directives

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Vincent Faidherbe wrote:
> 
> >
> >
> >
> >Ah!  Now I get it :)
> >
> >There are two solutions (this is an academic discussion as you appear
> >happy with #generate()) :
> >
> >1) When your java code makes the new Generator(), pass to it the
> >context.  I don't like this, but it would work.
> >
> >2) Just do
> >   $generate.doIt( $story, $template )
> >
> 
> The first solution wouldn't work because the story variable isn't
> declared in the context but in the first template with the statement
> #foreach ($story in $weblog.stories). It isn't in the context.

Yes, #foreach($story...) will place $story in the context...

> 
> The second solution can't work in the case of my project.  There are no
> rules which allows me to know what variables will be refered in the
> generated template.  if the user wants to refer to 5 or more variables
> in the template given to the doIt() method, he can do that. User are
> completely free to do anything he wants ! Users must use this generate
> method like he uses the parse directive !

Ah.  I see.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Be well, do good work, and keep in touch.

Re: plug-in directives

Posted by Vincent Faidherbe <vf...@icogs.com>.
>
>
>
>Ah!  Now I get it :)
>
>There are two solutions (this is an academic discussion as you appear
>happy with #generate()) :
>
>1) When your java code makes the new Generator(), pass to it the
>context.  I don't like this, but it would work.
>
>2) Just do 
>   $generate.doIt( $story, $template )
>

The first solution wouldn't work because the story variable isn't 
declared in the context but in the first template with the statement 
#foreach ($story in $weblog.stories). It isn't in the context.

The second solution can't work in the case of my project.  There are no 
rules which allows me to know what variables will be refered in the 
generated template.  if the user wants to refer to 5 or more variables 
in the template given to the doIt() method, he can do that. User are 
completely free to do anything he wants ! Users must use this generate 
method like he uses the parse directive !


Vincent Faidherbe.





Re: plug-in directives

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Vincent Faidherbe wrote:
> 
> >
> >
> >
> >I have to admit I still don't get it :)  I mean, if you want to trap the
> >output, why not have something like
> >
> >$generate.doIt( "Case_2_Story.vm" )
> >
> >which would do the same thing?
> >
> Yes but if i proceed with a variable generate, the template which will
> be "generated" can't have //statements referring to templates which has
> called the specific method on the variable generate. Maybe i've wrong ?
> I want that the generate method have the same advantages of the parse
> directive.
> I take my example again :
> 
> <!-- set the corresponding HTML filename -->
> <HTML>
> ....
>      #foreach ($story in $weblog.stories)
>           <H2>$story.title <H2>
>           <I>$story.summary</I><BR>
>           $generate.doIt("Case_2_Story.vm")
>      #end
> ....
> </HTML>
> 
> Here's the code of the Case_2_Story.vm.
> 
> <HTML>
> ...
>       <TITLE>$story.title</TITLE>
> .....
> </HTML>
> 
> The statement $story.title won't have an effect beause it can't refer to
> variable which has been declared in the first template.
> 

Ah!  Now I get it :)

There are two solutions (this is an academic discussion as you appear
happy with #generate()) :

1) When your java code makes the new Generator(), pass to it the
context.  I don't like this, but it would work.

2) Just do 
   $generate.doIt( $story, $template )

so it's clear what's going on and doesn't depend on 'side effects' of
having something set in the context with a specific name.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Be well, do good work, and keep in touch.

Re: plug-in directives

Posted by Vincent Faidherbe <vf...@icogs.com>.
>
>
>
>I have to admit I still don't get it :)  I mean, if you want to trap the
>output, why not have something like
>
>$generate.doIt( "Case_2_Story.vm" )
>
>which would do the same thing?
>
Yes but if i proceed with a variable generate, the template which will 
be "generated" can't have //statements referring to templates which has 
called the specific method on the variable generate. Maybe i've wrong ?
I want that the generate method have the same advantages of the parse 
directive.
I take my example again :


<!-- set the corresponding HTML filename -->
<HTML>
....
     #foreach ($story in $weblog.stories)
          <H2>$story.title <H2>
          <I>$story.summary</I><BR>
          $generate.doIt("Case_2_Story.vm")
     #end
....
</HTML>

Here's the code of the Case_2_Story.vm.

<HTML>
...
      <TITLE>$story.title</TITLE>
.....
</HTML>

The statement $story.title won't have an effect beause it can't refer to 
variable which has been declared in the first template.


Vincent Faidherbe






Re: plug-in directives

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Vincent Faidherbe wrote:
> >
> Ok, i know that but the problem, here, is that people which will write
> templates are the men in street. Template must be the less
> difficult as possible ! Here, templates are just used  for querying the
> content of existing variables. Our user  just need to use :
> - variable references,
> - and foreach statement to loop through the content of a variable.
> We try to avoid the usage of variable creation and so on ...
> 
> Now i've written a plug-in directive to do job. It's totally transparent
> for the end-user and it works fine.

Great.

I have to admit I still don't get it :)  I mean, if you want to trap the
output, why not have something like

$generate.doIt( "Case_2_Story.vm" )

which would do the same thing?

The advantage is that you could extend the $generate object quite
easily, adding new methods that people could use, w/o having to add more
directives...

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Be well, do good work, and keep in touch.

Re: plug-in directives

Posted by Vincent Faidherbe <vf...@icogs.com>.
>
>
>
>There are many existing ways to do this - 
>
>1) You can trap the output of parse into a string like so :L
>
>  #set($output = "#parse('mystory.vm')" )
>
>then the calling program can take the value of $output and write into a
>file.
>
>2) You can wrap the mergeTemplate() method of Velocity class and drop
>that as a tool into the context
>
>3) If you can control it w/o a template, why not just use the Velocity
>class mergeTemplate() or evaluate() methods?
>
Ok, i know that but the problem, here, is that people which will write 
templates are the men in street. Template must be the less
difficult as possible ! Here, templates are just used  for querying the 
content of existing variables. Our user  just need to use :
- variable references,
- and foreach statement to loop through the content of a variable.
We try to avoid the usage of variable creation and so on ...

Now i've written a plug-in directive to do job. It's totally transparent 
for the end-user and it works fine.

Vincent Faidherbe.



Re: plug-in directives

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
I have to admit I don't get it.  What's the point?

There are many existing ways to do this - 

1) You can trap the output of parse into a string like so :L

  #set($output = "#parse('mystory.vm')" )

then the calling program can take the value of $output and write into a
file.

2) You can wrap the mergeTemplate() method of Velocity class and drop
that as a tool into the context

3) If you can control it w/o a template, why not just use the Velocity
class mergeTemplate() or evaluate() methods?

To answer the question, you should be able to specify your plugin via

Velocity.setProperty()

or if you have a velocity.properties file, do it there...

geir

Vincent Faidherbe wrote:
> 
> Actually, i'm working on a Blogger-like project (http://www.blogger.com).
> Users write velocity template which integrate user-defined weblog. These
> templates are converted to static HTML files which are then
> tranfered to a remote website.
> So, i've needed a kind of parse directive i've called generate which
> allows to process templates which are referenced in a other template.
> Unlike the parse directive, the content of the referenced template can't
> be integrated in the parent template because each template corresponds
> to one HTML file.
> 
> I give you an example :
> Here's the code which produces an index of all the story of the weblog.
> It displays only the summary field.
> 
> <!-- set the corresponding HTML filename -->
> $icogs.pushPageName("myWeblog.html")
> #set($weblog = $icogs.loadWeblogSitem("MyWeblog"))
> <HTML>
> <HEAD>
> <TITLE>$beethlog.title</TITLE>
> </HEAD>
> <BODY>
> <H1>$weblog.title</H1>
> <P><I>$weblog.description</I></P>
> 
> #foreach ($story in $weblog.stories)
> <!-- the link point to an html file which will be generated from another
> velocity template -->
> <A HREF="story/story${story.id}.html">
> $story.title
> </A>
> <I>$story.summary</I><BR>
> 
> <!-- parse the referenced template which correspond to the
> story/story${story.id}.html file .
> I can't use the parse directive because the content of the parsed
> template must be put in another file -->
> #generate("Case_2_Story.vm")
> #end
> </BODY>
> </HTML>
> 
> Here's the code of the Case_2_Story.vm which produces a page which
> contains the full story.
> 
> <!-- set the corresponding HTML filename -->
> $icogs.pushPageName("story/story${story.id}.html")
> <HTML>
> <HEAD>
> <TITLE>$story.title</TITLE>
> </HEAD>
> <BODY>
> <H2>$story.title</H2>
> #if ($story.subtitle)
> <H3>$story.subtitle</H3>
> #end
> <I>posted by <A HREF="mailto:$story.authorAddress">$story.author</A> on
> $story.date</I>
> $story.content
> </BODY>
> </HTML>
> 
> So, finally, i've written a new directive called generate which has the
> same code that the parse directive except that it doesn't use the given
> Writer but it creates a new one which is chained to a modified version
> of StringWriter which allows to chain other StringWriter.
> 
> Here's some lines of the code :
> 
> public class Generate extends Directive {
> ....
> public boolean render( InternalContextAdapter context,
> Writer writer, Node node )
> throws IOException, MethodInvocationException {
> ...
> try
> {
> context.pushCurrentTemplateName(arg);
> 
> if (writer instanceof com.icogs.io.ChainableStringWriter) {
> // create a new write to store the fresh subcontent
> ChainableStringWriter newWriter = ((ChainableStringWriter)
> writer).createNewWriter();
> ((ChainableStringWriter) writer).chainWriter(newWriter);
> ((SimpleNode) t.getData()).render( context, newWriter );
> } else {
> ((SimpleNode) t.getData()).render( context, writer );
> }
> ....
> }
> }
> 
> Now, i've one question : How can i load this plug-in directive without
> modifying the org.apache.velocity.runtime.defaults.directive.properties ?
> 
> Vincent Faidherbe

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Be well, do good work, and keep in touch.

Re: Velocity error mesage

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
piero de salvia wrote:
> 
> Hi Geir,
> 
> I don´t have the code right now, I´m on vacation and I
> was not even supposed to look at a computer...

My wife tries that on me.  She solves it by making me leave laptops at
home, and going places where 'internet cafe' don't exist...

> 
> But just before leaving, I took a look at my ISP´s
> directory structure, and it seems that the Avalon
> logger cannot open a log file for writing, (the file I
> specified in velocity´s config), for lack of
> permission, but it fails silently then, and when
> trying to serve a request (so I suppose when trying to
> log the "template found..." message and so on), the
> whole thing crashes and burns. So maybe an exception
> should be thrown at either moment, instead of having
> to deal with a mysterious Null Pointer.

Yep.  Tossing a panic exception on logger failure is prollie the right
way to go. I am going to try to switch to the log4j ME as the embedded
file logger, after I get the instance changes in, so we can do it
then...

Enjoy the vacation.

geir
 
> bye bye
> 
> piero de salvia
> 
> --- "Geir Magnusson Jr." <ge...@optonline.net> wrote:
> > piero de salvia wrote:
> > >
> > > yessir,
> > >
> > > I am calling init, and in fact, this is also part
> > of
> > > the error message:
> > >
> > > Runtime properties:
> > > file.resource.loader.path =>
> > > /home/sites/web/WEB-INF/template
> > > runtime.log =>
> > > /home/sites/web/WEB-INF/logs/manager/velocity.log
> > > velocimacro.library => [/macros/head.vm,
> > > /macros/altbgcolor.vm]
> > >
> >
> > Huh?
> >
> > > problem is, it works on my machine and it doesn't
> > work
> > > on my ISP.
> >
> > Double 'huh?'  The only things that would be
> > different are classpath and
> > JVM...
> >
> > Can you send me your code?
> >
> > geir
> >
> >
> > --
> > Geir Magnusson Jr.
> > geirm@optonline.net
> > System and Software Consulting
> > Developing for the web?  See
> > http://jakarta.apache.org/velocity/
> > Be well, do good work, and keep in touch.
> 
> __________________________________________________
> Do You Yahoo!?
> Make international calls for as low as $.04/minute with Yahoo! Messenger
> http://phonecard.yahoo.com/

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Well done is better than well said - New England Proverb

Re: Velocity error mesage

Posted by piero de salvia <pi...@yahoo.com>.
Hi Geir,

I don�t have the code right now, I�m on vacation and I
was not even supposed to look at a computer...

But just before leaving, I took a look at my ISP�s
directory structure, and it seems that the Avalon
logger cannot open a log file for writing, (the file I
specified in velocity�s config), for lack of
permission, but it fails silently then, and when
trying to serve a request (so I suppose when trying to
log the "template found..." message and so on), the
whole thing crashes and burns. So maybe an exception
should be thrown at either moment, instead of having
to deal with a mysterious Null Pointer.

bye bye 

piero de salvia


--- "Geir Magnusson Jr." <ge...@optonline.net> wrote:
> piero de salvia wrote:
> > 
> > yessir,
> > 
> > I am calling init, and in fact, this is also part
> of
> > the error message:
> > 
> > Runtime properties:
> > file.resource.loader.path =>
> > /home/sites/web/WEB-INF/template
> > runtime.log =>
> > /home/sites/web/WEB-INF/logs/manager/velocity.log
> > velocimacro.library => [/macros/head.vm,
> > /macros/altbgcolor.vm]
> > 
> 
> Huh?
> 
> > problem is, it works on my machine and it doesn't
> work
> > on my ISP.
> 
> Double 'huh?'  The only things that would be
> different are classpath and
> JVM...
>  
> Can you send me your code?
> 
> geir
> 
> 
> -- 
> Geir Magnusson Jr.                          
> geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See
> http://jakarta.apache.org/velocity/
> Be well, do good work, and keep in touch.


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Re: Velocity error mesage

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
piero de salvia wrote:
> 
> yessir,
> 
> I am calling init, and in fact, this is also part of
> the error message:
> 
> Runtime properties:
> file.resource.loader.path =>
> /home/sites/web/WEB-INF/template
> runtime.log =>
> /home/sites/web/WEB-INF/logs/manager/velocity.log
> velocimacro.library => [/macros/head.vm,
> /macros/altbgcolor.vm]
> 

Huh?

> problem is, it works on my machine and it doesn't work
> on my ISP.

Double 'huh?'  The only things that would be different are classpath and
JVM...
 
Can you send me your code?

geir


-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Be well, do good work, and keep in touch.

Re: Velocity error mesage

Posted by piero de salvia <pi...@yahoo.com>.
yessir,

I am calling init, and in fact, this is also part of
the error message:

Runtime properties:
file.resource.loader.path =>
/home/sites/web/WEB-INF/template
runtime.log =>
/home/sites/web/WEB-INF/logs/manager/velocity.log
velocimacro.library => [/macros/head.vm,
/macros/altbgcolor.vm]

problem is, it works on my machine and it doesn't work
on my ISP.

piero
--- "Geir Magnusson Jr." <ge...@optonline.net> wrote:
> piero de salvia wrote:
> > 
> > hi fellas,
> > 
> > would anybody have a clue about where this is
> coming
> > from, and what it means?
> > 
> > java.lang.NullPointerException at
> >
>
org.apache.velocity.runtime.log.AvalonLogSystem.logVelocityMessage(AvalonLogSystem.java:172)
> > at
> >
>
org.apache.velocity.runtime.RuntimeInstance.log(RuntimeInstance.java:858)
> > at
> >
>
org.apache.velocity.runtime.RuntimeInstance.error(RuntimeInstance.java:897)
> > at
> >
>
org.apache.velocity.runtime.resource.ResourceManager.getResource(ResourceManager.java:461)
> > at
> >
>
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:734)
> > at
> >
>
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:716)
> > at
> >
>
org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:550)
> 
> It's a NullPointerException :)
> 
> I can tell from the trace that you are using my new
> version that
> provides separate runtime instances.
> 
> Did you call init?
> 
> 
> -- 
> Geir Magnusson Jr.                          
> geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See
> http://jakarta.apache.org/velocity/
> Be well, do good work, and keep in touch.


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Re: Velocity error mesage

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
piero de salvia wrote:
> 
> hi fellas,
> 
> would anybody have a clue about where this is coming
> from, and what it means?
> 
> java.lang.NullPointerException at
> org.apache.velocity.runtime.log.AvalonLogSystem.logVelocityMessage(AvalonLogSystem.java:172)
> at
> org.apache.velocity.runtime.RuntimeInstance.log(RuntimeInstance.java:858)
> at
> org.apache.velocity.runtime.RuntimeInstance.error(RuntimeInstance.java:897)
> at
> org.apache.velocity.runtime.resource.ResourceManager.getResource(ResourceManager.java:461)
> at
> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:734)
> at
> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:716)
> at
> org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:550)

It's a NullPointerException :)

I can tell from the trace that you are using my new version that
provides separate runtime instances.

Did you call init?


-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Be well, do good work, and keep in touch.

Velocity error mesage

Posted by piero de salvia <pi...@yahoo.com>.
hi fellas,

would anybody have a clue about where this is coming
from, and what it means?

java.lang.NullPointerException at
org.apache.velocity.runtime.log.AvalonLogSystem.logVelocityMessage(AvalonLogSystem.java:172)
at
org.apache.velocity.runtime.RuntimeInstance.log(RuntimeInstance.java:858)
at
org.apache.velocity.runtime.RuntimeInstance.error(RuntimeInstance.java:897)
at
org.apache.velocity.runtime.resource.ResourceManager.getResource(ResourceManager.java:461)
at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:734)
at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:716)
at
org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:550)



piero de salvia

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Re: plug-in directives

Posted by Vincent Faidherbe <vf...@icogs.com>.
Actually, i'm working on a Blogger-like project (http://www.blogger.com).
Users write velocity template which integrate user-defined weblog. These 
templates are converted to static HTML files which are then
tranfered to a remote website.
So, i've needed a kind of parse directive i've called generate which 
allows to process templates which are referenced in a other template. 
Unlike the parse directive, the content of the referenced template can't 
be integrated in the parent template because each template corresponds 
to one HTML file.

I give you an example :
Here's the code which produces an index of all the story of the weblog. 
It displays only the summary field.

<!-- set the corresponding HTML filename -->
$icogs.pushPageName("myWeblog.html")
#set($weblog = $icogs.loadWeblogSitem("MyWeblog"))
<HTML>
<HEAD>
<TITLE>$beethlog.title</TITLE>
</HEAD>
<BODY>
<H1>$weblog.title</H1>
<P><I>$weblog.description</I></P>

#foreach ($story in $weblog.stories)
<!-- the link point to an html file which will be generated from another 
velocity template -->
<A HREF="story/story${story.id}.html">
$story.title
</A>
<I>$story.summary</I><BR>

<!-- parse the referenced template which correspond to the 
story/story${story.id}.html file .
I can't use the parse directive because the content of the parsed 
template must be put in another file -->
#generate("Case_2_Story.vm")
#end
</BODY>
</HTML>

Here's the code of the Case_2_Story.vm which produces a page which 
contains the full story.

<!-- set the corresponding HTML filename -->
$icogs.pushPageName("story/story${story.id}.html")
<HTML>
<HEAD>
<TITLE>$story.title</TITLE>
</HEAD>
<BODY>
<H2>$story.title</H2>
#if ($story.subtitle)
<H3>$story.subtitle</H3>
#end
<I>posted by <A HREF="mailto:$story.authorAddress">$story.author</A> on 
$story.date</I>
$story.content
</BODY>
</HTML>

So, finally, i've written a new directive called generate which has the 
same code that the parse directive except that it doesn't use the given 
Writer but it creates a new one which is chained to a modified version 
of StringWriter which allows to chain other StringWriter.

Here's some lines of the code :

public class Generate extends Directive {
....
public boolean render( InternalContextAdapter context,
Writer writer, Node node )
throws IOException, MethodInvocationException {
...
try
{
context.pushCurrentTemplateName(arg);

if (writer instanceof com.icogs.io.ChainableStringWriter) {
// create a new write to store the fresh subcontent
ChainableStringWriter newWriter = ((ChainableStringWriter) 
writer).createNewWriter();
((ChainableStringWriter) writer).chainWriter(newWriter);
((SimpleNode) t.getData()).render( context, newWriter );
} else {
((SimpleNode) t.getData()).render( context, writer );
}
....
}
}

Now, i've one question : How can i load this plug-in directive without 
modifying the org.apache.velocity.runtime.defaults.directive.properties ?

Vincent Faidherbe




Re: plug-in directives

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Vincent Faidherbe wrote:
> 
> I've two questions :
> - What are the difference beetween macro and plug-in directives ?
> - How to create plug-in directives ?
> 
> Vincent Faidherbe.

(Ducking the whole whitespace thread until after a glass of wine...)

The fundamental difference is that a macro (formally 'Velocimacro') is
entirely a template-side / designer-side facility, meant to allow
'functionalizing' things in the template for convenience, control and
repeatability.

A directive, while of course used in the template, is something that is
written in Java and made available as part of the parser/runtime
infrastructure to the templates.

Generally, it is recommended to use either a VM or a 'context tool' (an
object that you drop into the context for use by the template) before
resorting to a directive, as the directive makes your templates
non-portable, and it's a lot more complicated than just doing a simple
java class or a VM.

1  If you can, use a VM.
2) If you can't use a VM, use a context tool.
3) If you can't use a context too, rethink the problem.

:)

The real use for a directive is a place where you need to be involved
with the structure of the template itself...

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Be well, do good work, and keep in touch.

Re: VTL question

Posted by Richard Neish <ri...@rmp.com.jm>.
Dan,

I guess your suggestion below could work for substitutions made
by Velocity, but to my mind this is NOT a Velocity problem.  In
the same way that I like to format VTL for readability, I like to
put whitespace and indentation in HTML.  What would solve my
problems is an inline version of HTML tidy by the W3 group which
removes whitespace from HTML to reduce its size.

Maybe a concrete example would be useful here.  If I write a
template like this:
<HTML>
  <HEAD>
    <TITLE>
      $title
    </TITLE>
  </HEAD>
  <BODY #if ($bgcolor)
          BGCOLOR="$bgcolor"
        #end
  >
    schmoo, schmoo, schmoo
    #if ($a)
      $object.method()
    #end
  </BODY>
</HTML>

And call it with a context that has
$title == "Test page", $bgcolor == "#FFFFFF",
$a = true and $object.method() == "result"

then I expect Velocity to produce the following HTML:
<HTML>
  <HEAD>
    <TITLE>
      Test page
    </TITLE>
  </HEAD>
  <BODY
          BGCOLOR="#FFFFFF"

  >
    schmoo, schmoo, schmoo

      result

  </BODY>
</HTML>

This is fine.  That's Velocity's job.  What I want now is another
tool that sits between Velocity and the user and converts the
above HTML into the following (equivalent) HTML:
<HTML><HEAD><TITLE>Test page</TITLE></HEAD><BODY
BGCOLOR="#FFFFFF">schmoo, schmoo, schmoo result</BODY></HTML>

This is a separate process from the whole Velocity template
system -- I would actually love to have this work for static (non
Velocity) HTML as well.  In an extreme example that actually
happened I have been able to reduce a static HTML file from
~130KB to ~35KB using this technique.

Thinking about this more, maybe I should be looking for an Apache
module that does this instead...

So as far as I can tell it's not a Velocity issue, but does
anyone know of a tool that will do this and that plays nice with
Velocity?

Thanks.  I'll shut up now.

Richard Neish

----- Original Message -----
From: "Dan Finkelstein" <da...@emind.com>
To: <ve...@jakarta.apache.org>
Sent: Wednesday, July 25, 2001 12:31 PM
Subject: Re: VTL question


> I've been following the whitespace discussion for a while and
wanted to put
> my two cents in:
>
> I think that whitespace handling is part of the processing
cycle, as
> templates are processed, our job is to provide directives on
how we wish
> the output to look.  I think of the template system as a
processing pass,
> and controlling any and all output is important.
>
> Also, I don't think a "post-processing" filter is sufficient to
do that job
> -- it would be very complex and remove control that a
processing system
> should have as part of it.  It's true that a filter will "help"
and address
> my people's concern's, but I don't think of it as a generalized
solution.
>
> I suggest the addition of a directive to the velocity VTL,
which allows us
> template writers to control whitespace on a line-by-line basis.
Of course,
> we'd be able to set an overall default value.
>
> Here's how it might be used:
>
> #whitespace(compressionOn)
> #macro( altbgcolor $RowCount)
>          #if ( ($RowCount%2) == 1 )
>                  #ffffff
>          #else
>                  #d3d3d3
>          #end
> #end
> #whitespace(default)            // revert to previous setting
>
> The above directive would remove all spaces,tabs and NLs as
though the
> macro had been squeezed.
>
> In a similar way, these directives would control how whitespace
is handled
> throughout the template -- in general, I think that a
reasonable default
> will suffice, say (compressionOn) for html projects.  The
shipped with
> default could be as now, say (compressionOff).
>
> Of course, the parameters to #whitespace could be enhanced to
allow a much
> finer level of control, such as only removing spaces and tabs,
or a special
> debug mode...
>
> Just my 2 cents worth,
> Dan


Re: VTL question

Posted by Nick Bauman <ni...@cortexity.com>.
> OK Brian,
> 
> your 
> 
> #macro( getAlternateBGColor $rowCount )
> 
> is elegant and fixes it.

Agreed. I think you could stop right there, IMO. 

> 
> But Velocity should be able to control its output. The

It does.

> time will come when somebody will generate output for
> a language where whitespace and NLs make a difference,
> and he/she will have to go through this again.

True, but you can solve it with a macro. And when someone does, we will all 
hunt them down and kill them. =)

> 
> Plus, in big projects, developers are horribly busy.
> So they will have to take care of business logic AND
> presentation logic. And even if they do,
> testing/debugging a macro is way lighter than
> testing/debugging a class.

Which makes me think you are contradicting yourself here? I'm sorry, people 
have said I'm as thick as a whale omlette before, but if that's true then 
why do we need a #whitespace directive, for instance?

> So, IMHO, for Velocity to be industrial-strength, it
>should have a non-whitespace, non-NL directive, like
> ^(#fffff)
> 
> G'night
> 
> piero

And while I'm at it, I do not believe Velocity needs float support, but 
that's just me.

-- 
Nick Bauman
Software Engineer
3600 Dupont
Minneapolis, MN
55412
Mobile Phone: (612) 810-7406
Home Phone: (612) 522-0165


Re: VTL question

Posted by piero de salvia <pi...@yahoo.com>.
OK Brian,

your 

#macro( getAlternateBGColor $rowCount )

is elegant and fixes it.

But Velocity should be able to control its output. The
time will come when somebody will generate output for
a language where whitespace and NLs make a difference,
and he/she will have to go through this again.

Plus, in big projects, developers are horribly busy.
So they will have to take care of business logic AND
presentation logic. And even if they do,
testing/debugging a macro is way lighter than
testing/debugging a class.

So, IMHO, for Velocity to be industrial-strength, it
should have a non-whitespace, non-NL directive, like
^(#fffff)

G'night

piero

--- Brian Lloyd-Newberry <ne...@yahoo.com> wrote:
>    Ok... This really scares me...
> 
>    I see the ability to suppress newlines as a
> potential benefit to
> readability of the templates. As for suppression of
> all whitespace I am
> not so sure. I think it is a slippery slope that is
> going to probably
> make writing velocity templates more "complicated"
> and "messy" which in
> my opinion is bad. A directive to change parsing
> behavior at parse time
> seems nice at first thought but I am not so sure it
> will be the panacea
> that it appears to be.
> 
>    A macro that wraps a java call seems like a good
> option here. I
> would do something like:
> 
> #macro( getAlternateBGColor $rowCount )
> $UTILS.coloration.getAlternatingColor( $rowCount )
> #end
> 
.....

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Re: VTL question

Posted by Brian Lloyd-Newberry <ne...@yahoo.com>.
   Ok... This really scares me...

   I see the ability to suppress newlines as a potential benefit to
readability of the templates. As for suppression of all whitespace I am
not so sure. I think it is a slippery slope that is going to probably
make writing velocity templates more "complicated" and "messy" which in
my opinion is bad. A directive to change parsing behavior at parse time
seems nice at first thought but I am not so sure it will be the panacea
that it appears to be.

   A macro that wraps a java call seems like a good option here. I
would do something like:

#macro( getAlternateBGColor $rowCount )
$UTILS.coloration.getAlternatingColor( $rowCount )
#end

for a more "flexible" implementation you could wrap a macro around a
method that would populate the color alternator with a list of colors
to be alternated

#macro( setBGColorAlternatives $colorList )
$UTILS.coloration.setAlternatingColors( $colorList )
#end

Then you could do a:
#setBGColorAlternatives( '#ffffff', '#d3d3d3', '#a4a4a4' )

and embed a:
#getAlternateBGColor( 5 )

This appears to be cleaner than the below snippet and avoids whitespace
concerns altogether. It does of course mean that you will have to write
Java code as opposed to velocity code and find some way to get the
UTILS stuff into the context.

> #whitespace(compressionOn)
> #macro( altbgcolor $RowCount)
>          #if ( ($RowCount%2) == 1 )
>                  #ffffff
>          #else
>                  #d3d3d3
>          #end
> #end
> #whitespace(default)            // revert to previous setting

Of course this is just my 2c (now we collectively have 4c) as a
relative newcomer that is really enjoying the Velocity experience. 

-Brian
   

--- Dan Finkelstein <da...@emind.com> wrote:
> I've been following the whitespace discussion for a while and wanted
> to put 
> my two cents in:
> 
> I think that whitespace handling is part of the processing cycle, as 
> templates are processed, our job is to provide directives on how we
> wish 
> the output to look.  I think of the template system as a processing
> pass, 
> and controlling any and all output is important.
> 
> Also, I don't think a "post-processing" filter is sufficient to do
> that job 
> -- it would be very complex and remove control that a processing
> system 
> should have as part of it.  It's true that a filter will "help" and
> address 
> my people's concern's, but I don't think of it as a generalized
> solution.
> 
> I suggest the addition of a directive to the velocity VTL, which
> allows us 
> template writers to control whitespace on a line-by-line basis.  Of
> course, 
> we'd be able to set an overall default value.
> 
> Here's how it might be used:
> 
> #whitespace(compressionOn)
> #macro( altbgcolor $RowCount)
>          #if ( ($RowCount%2) == 1 )
>                  #ffffff
>          #else
>                  #d3d3d3
>          #end
> #end
> #whitespace(default)            // revert to previous setting
> 
> The above directive would remove all spaces,tabs and NLs as though
> the 
> macro had been squeezed.
> 
> In a similar way, these directives would control how whitespace is
> handled 
> throughout the template -- in general, I think that a reasonable
> default 
> will suffice, say (compressionOn) for html projects.  The shipped
> with 
> default could be as now, say (compressionOff).
> 
> Of course, the parameters to #whitespace could be enhanced to allow a
> much 
> finer level of control, such as only removing spaces and tabs, or a
> special 
> debug mode...
> 
> Just my 2 cents worth,
> Dan
> 
> 


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Re: VTL question

Posted by Dan Finkelstein <da...@emind.com>.
I've been following the whitespace discussion for a while and wanted to put 
my two cents in:

I think that whitespace handling is part of the processing cycle, as 
templates are processed, our job is to provide directives on how we wish 
the output to look.  I think of the template system as a processing pass, 
and controlling any and all output is important.

Also, I don't think a "post-processing" filter is sufficient to do that job 
-- it would be very complex and remove control that a processing system 
should have as part of it.  It's true that a filter will "help" and address 
my people's concern's, but I don't think of it as a generalized solution.

I suggest the addition of a directive to the velocity VTL, which allows us 
template writers to control whitespace on a line-by-line basis.  Of course, 
we'd be able to set an overall default value.

Here's how it might be used:

#whitespace(compressionOn)
#macro( altbgcolor $RowCount)
         #if ( ($RowCount%2) == 1 )
                 #ffffff
         #else
                 #d3d3d3
         #end
#end
#whitespace(default)            // revert to previous setting

The above directive would remove all spaces,tabs and NLs as though the 
macro had been squeezed.

In a similar way, these directives would control how whitespace is handled 
throughout the template -- in general, I think that a reasonable default 
will suffice, say (compressionOn) for html projects.  The shipped with 
default could be as now, say (compressionOff).

Of course, the parameters to #whitespace could be enhanced to allow a much 
finer level of control, such as only removing spaces and tabs, or a special 
debug mode...

Just my 2 cents worth,
Dan



At 10:08 AM 7/25/01 -0700, you wrote:
>Thanks to Brian and Richard for the suggestions.
>
>As usual,
>
>thinking about it, I found what seems to be the
>solution.
>
>as the old timers often suggest, 'drop a tool in the
>context'. So, I'll create a tool called Compactor,
>i'll make sure it is always in context, and i will
>
><td bgcolor="$compactor(#mymacro($velocityCount))">
>
>Now, I will comment that this is a hack to me.
>
>I was reading in an old post that since Velocity is a
>general template processor, it doesn't matter if the
>output contains whitespace, newlines and stuff like
>that.
>
>Well, being a template processor, it does matter,
>because it should provide, natively, tools to have
>exact control over its output.
>
>I do understand that things like DateFormat,
>MoneyFormat etc. belong to the context.
>
>But, the same way the silent operator, !, is
>considered something essential enough to be included
>in VTL, being able to control whitespace/newline
>outputting seems to me just as basic.
>
>we are not at a higher abstraction level than the
>silent operator.
>
>Another issue rather essential to me, brought up some
>time ago, is that you cannot break up a list with
>newlines for readability.
>
>It is really strange to me that it's not feasible,
>also given the fact that the parser is written by
>JavaCC, which is supposed to be superpowerful.
>
>We want to use Velocity for super-industrial strength
>apps, so these things appear important to me.
>
>A GIGANTIC step in this direction is VelocityEngine. I
>think that because of how democratically Velocity is
>developed, we will get there.
>
>cheers
>
>piero de salvia
>
>__________________________________________________
>Do You Yahoo!?
>Make international calls for as low as $.04/minute with Yahoo! Messenger
>http://phonecard.yahoo.com/

Dan Finkelstein
Senior Architect, Instructional Tools & Technology
eMind LLC
Northern California Annex
1250 Addison St, Suite #210
Berkeley, CA 94702-1700
Tel: (510) 486-2740
Fax: (510)486-2843

Visit us at <http://www.emind.com/>

This email message is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized review,
use, disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender by reply email and destroy all copies
of the original message.


Re: VTL question

Posted by piero de salvia <pi...@yahoo.com>.
Thanks to Brian and Richard for the suggestions.

As usual,

thinking about it, I found what seems to be the
solution.

as the old timers often suggest, 'drop a tool in the
context'. So, I'll create a tool called Compactor,
i'll make sure it is always in context, and i will

<td bgcolor="$compactor(#mymacro($velocityCount))">

Now, I will comment that this is a hack to me. 

I was reading in an old post that since Velocity is a
general template processor, it doesn't matter if the
output contains whitespace, newlines and stuff like
that. 

Well, being a template processor, it does matter,
because it should provide, natively, tools to have
exact control over its output. 

I do understand that things like DateFormat,
MoneyFormat etc. belong to the context. 

But, the same way the silent operator, !, is
considered something essential enough to be included
in VTL, being able to control whitespace/newline
outputting seems to me just as basic.

we are not at a higher abstraction level than the
silent operator.

Another issue rather essential to me, brought up some
time ago, is that you cannot break up a list with
newlines for readability.

It is really strange to me that it's not feasible,
also given the fact that the parser is written by
JavaCC, which is supposed to be superpowerful.

We want to use Velocity for super-industrial strength
apps, so these things appear important to me.

A GIGANTIC step in this direction is VelocityEngine. I
think that because of how democratically Velocity is
developed, we will get there.

cheers 

piero de salvia

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Re: VTL question

Posted by Richard Neish <ri...@rmp.com.jm>.
This is my first post to the list, so I'd like to say thanks to
the Velocity developers (Geir) for a great product.  Having said
that, I think this problem here is indicative of a problem not
with Velocity, but with the whole approach of template-driven
content in general.

We all want to make our templates easy to read and modify by
using blank spaces, indents, comments etc, but we want the
template output to be as lean as possible for quick downloads,
small file sizes, etc.  Velocity takes what I think is the right
approach and doesn't attempt this output post-processing, but I
would love to find a product that does.

So here's the question:  Does anyone know of a product that works
well with Velocity that will do this kind of output processing?
If a stable product isn't out there, I might take a stab at
writing one for my own purposes, but that would probably end up
being web-centric, at least in it's first incarnation.  I haven't
thought about it a whole lot, but I would probably subclass
VelocityServlet and put output processing code after the call to
merge().

Comments?

Thanks,

Richard Neish

----- Original Message -----
From: "piero de salvia" <pi...@yahoo.com>
To: <ve...@jakarta.apache.org>
Sent: Wednesday, July 25, 2001 10:10 AM
Subject: VTL question


> Hi all,
>
> I was trying to implement the ever present altbgcolor
> macro, to make my table rows white and grey, so i
> wrote this:
>
> #macro( altbgcolor $RowCount)
> #if ( ($RowCount%2) == 1 )
> #ffffff
> #else
> #d3d3d3
> #end
> #end
>
> and I called it from a loop as
> #altbgcolor(velocityCount)
>
> surprise!
> a nice /n is output after the color, and, after having
> gone through the archives, it seems to me that my only
> choice is this:
> #macro( altbgcolor $RowCount)
> #if ( ($RowCount%2) == 1 ) #ffffff #else #d3d3d3 #end
> #end
>
> rather ugly, plus if the macro is complicated, this is
> tantamount to writing it in bytecode...
>
> how did you guys do (or hack)  it ?
>
> piero de salvia
>
> __________________________________________________
> Do You Yahoo!?
> Make international calls for as low as $.04/minute with Yahoo!
Messenger
> http://phonecard.yahoo.com/
>


Re: VTL question

Posted by Christoph Reck <Ch...@dlr.de>.
The whitespace is an issue I have been addressing since
early ages of Velocity. I've been doing a lot of hacks
to have nice VTL and nice output, e.g.:

#macro( altbgcolor $RowCount)#*
  *##if ( ($RowCount%2) == 1 )#*
    *##ffffff#*
  *##else#*
    *##d3d3d3#*
  *##end##
#end

or even

#macro( altbgcolor $RowCount)##
#*  *##if ( ($RowCount%2) == 1 )##
#*    *##ffffff##
#*  *##else##
#*    *##d3d3d3##
#*  *##end##
#end

Which really look yucky but work fine.

I'm strongly against a #whitespace directive (Nick - and also support 
of floats! - just use $number.getFloat("123.456") ).

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
The simple solution is to update velocity to just ignore leading/trailing
whitespaces for standalone directives.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

The *big* gain is that line oriented output (as is HTML, SQL, XML, etc...)
can be easily encapsulated by indented VTL.

Sorry, but even then the above macro would not change much, since you're
trywing to output a word. It would gain a wee little:
#macro( altbgcolor $RowCount)
  #if( ($RowCount%2) == 1 )
#*  *##d3d3d3##
  #else 
#*  *##d3d3d3##
  #end
#end

See my other mails on whitespace handling proposal for advantages 
and drawbacks of the propesed enhancement.

:) Christoph


piero de salvia wrote:
> 
> Hi all,
> 
> I was trying to implement the ever present altbgcolor
> macro, to make my table rows white and grey, so i
> wrote this:
> 
> #macro( altbgcolor $RowCount)
>         #if ( ($RowCount%2) == 1 )
>                 #ffffff
>         #else
>                 #d3d3d3
>         #end
> #end
> 
> and I called it from a loop as
> #altbgcolor(velocityCount)
> 
> surprise!
> a nice /n is output after the color, and, after having
> gone through the archives, it seems to me that my only
> choice is this:
> #macro( altbgcolor $RowCount)
> #if ( ($RowCount%2) == 1 ) #ffffff #else #d3d3d3 #end
> #end
> 
> rather ugly, plus if the macro is complicated, this is
> tantamount to writing it in bytecode...
> 
> how did you guys do (or hack)  it ?
> 
> piero de salvia

Velocity mini case study

Posted by Nick Bauman <ni...@cortexity.com>.
I just wanted to share my findings on Velocity. I use velocity as an
embedded mail templating system in our application server.

When I began this subproject, I was using JSP as the language for generating
template output for our application server. It was horrible. There were many
problems, not to mention the difficulty of embedding a servlet engine in the
app server that I could communicate with through direct method calls instead
of over a socket. Specific to the Velocity argument was the JSP template
versus the VTL template. I'd like to show you what my JSP template looked
like. Package names have been changed to protect the innocent. Here is an
example:

----------------8<---------------

<%@ page session="false"
        import="java.util.*,
        foo.events.*,
        foo.emeeting.*,
        foo.validation.*,
        foo.util.actionevent.ActionEvent,
        java.util.Date"%>

<jsp:useBean id="meeting" scope="request" type="foo.IMeeting"
class="foo.Meeting"/>

<html>

<!-- etc -->

<table width="600" border="0" cellspacing="0" cellpadding="4" bgcolor="white">
<tr>
<td>
<%
Iterator            events = meeting.getStoredEventsIterator();
int                 repId = 0;

%>
<i><b>Topic: <%= meeting.getTopic()%></b></i>
<p>
<%
while (events.hasNext()) {
  Object event = events.next();
  Participation yapper =
meeting.getParticipation(((MeetingEvent)event).getFromId());
  if(event instanceof ChatEvent) {
    if("R".equals(yapper.getRole()) ) {
%>
<font color="#000000"><b><%=yapper.getName()%>:</b></font>
<%
      repId = yapper.getParticipantId();
    } else {
%>
<font color="#0000f0"><b><%=yapper.getName()%>:</b></font>
<%
    }
    ChatEvent ce = (ChatEvent) event;
%>
<br>
<%
  } else if(event instanceof URLPushedEvent) {
    if("R".equals(yapper.getRole()) ) {
%>
<font color="#000000"><b><%=yapper.getName()%>:</b></font>
<%
    } else {
%>
<font color="#0000f0"><b><%=yapper.getName()%>:</b></font>
<%
    }
    URLPushedEvent pe = (URLPushedEvent) event;
%>
<a href="<%=pe.getStoredData()%>">"<%=pe.getStoredData()%>"</a> <br>
<%
  }
}
%>
<hr>
<br><%=meeting.getMeetingId()%>:<%=repId%><br>
</td>
</tr>
</table>
</div>
</body>
</html>

----------------8<---------------

Seasick yet? Now here is the Velocity template accomplishing the same thing
as above:

----------------8<---------------

<html>

<!-- etc -->

<table width="600" border="0" cellspacing="0" cellpadding="4" bgcolor="white">
<tr>
<td>
<i><b>Topic: $meeting.getTopic()</b></i><p>

#foreach( $event in $meeting.getStoredEventsIterator() )
  #set( $yapper = $meeting.getParticipation($event.getFromId()) )
  #if( $event.getClass().getName().equals($urlEvent) )
    #if( $repRole.equals($yapper.getRole()) )
      #set( $repId = $yapper.getParticipantId() )
      <font color="$blk"><b>$yapper.getName()</b></font>
    #else
      <font color="$blu"><b>$yapper.getName()</b></font>
    #end
    <a href="$event.getStoredData()">$event.getStoredData()</a> <br>
  #elseif( $event.getClass().getName().equals($chatEvent) )
    #if($repRole.equals($yapper.getRole()) )
      #set( $repId = $yapper.getParticipantId() )
      <font color="$blk"><b>$yapper.getName()</b></font>
    #else
      <font color="$blu"><b>$yapper.getName()</b></font>
    #end
    $event.getStoredData() <br>
  #end
#end
<hr>
<br>$meeting.getMeetingId():$repId<br>
</td>
</tr>
</table>
</div>
</body>
</html>

----------------8<---------------

I was subsequently able to define that largish foreach loop into a macro and
shrink it even more, using Velocity's #macro function, so I could do this:

#drawStandardHtmlTranscript ( $meeting )

removing 20 lines of code from each template whilst only adding 2 lines (one
for #parse and the other for the #drawStandardHtmlTranscript.

The call to the Velocity runtime to finally merge the template consumes
about 20-50 milleseconds (on a 400 mHz PII Linux system) when I pool the
contexts (time doubles when I do not). This is great performance, too!

Last but not least, teaching the web design team to write a template took
literally 10 minutes from start to finish. They haven't asked me a single
question since.

-- 
Nick Bauman
Software Engineer
3600 Dupont
Minneapolis, MN
55412
Mobile Phone: (612) 810-7406
Home Phone: (612) 522-0165


Re: VTL question

Posted by Brian Lloyd-Newberry <ne...@yahoo.com>.
Piero,

  I have velocity like that all over my code generator. It sure would
be nice to be able to swallow end of lines like you can in C with a /
as the last character (before the newline or /r/n or /r). I had
considered the idea of adding a directive bt that seemed hackish... For
now things just end up looking a little ugly on the template side to
make things look nice on the generated code side.

-Brian

--- piero de salvia <pi...@yahoo.com> wrote:
> Hi all,
> 
> I was trying to implement the ever present altbgcolor
> macro, to make my table rows white and grey, so i
> wrote this:
> 
> #macro( altbgcolor $RowCount)
> 	#if ( ($RowCount%2) == 1 )
> 		#ffffff
> 	#else
> 		#d3d3d3
> 	#end
> #end
> 
> and I called it from a loop as 
> #altbgcolor(velocityCount)
> 
> surprise!
> a nice /n is output after the color, and, after having
> gone through the archives, it seems to me that my only
> choice is this:
> #macro( altbgcolor $RowCount)
> #if ( ($RowCount%2) == 1 ) #ffffff #else #d3d3d3 #end
> #end
> 
> rather ugly, plus if the macro is complicated, this is
> tantamount to writing it in bytecode...
> 
> how did you guys do (or hack)  it ?
> 
> piero de salvia
> 
> __________________________________________________
> Do You Yahoo!?
> Make international calls for as low as $.04/minute with Yahoo!
> Messenger
> http://phonecard.yahoo.com/


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

VTL question

Posted by piero de salvia <pi...@yahoo.com>.
Hi all,

I was trying to implement the ever present altbgcolor
macro, to make my table rows white and grey, so i
wrote this:

#macro( altbgcolor $RowCount)
	#if ( ($RowCount%2) == 1 )
		#ffffff
	#else
		#d3d3d3
	#end
#end

and I called it from a loop as 
#altbgcolor(velocityCount)

surprise!
a nice /n is output after the color, and, after having
gone through the archives, it seems to me that my only
choice is this:
#macro( altbgcolor $RowCount)
#if ( ($RowCount%2) == 1 ) #ffffff #else #d3d3d3 #end
#end

rather ugly, plus if the macro is complicated, this is
tantamount to writing it in bytecode...

how did you guys do (or hack)  it ?

piero de salvia

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/