You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Kevin Bolton <kb...@paychex.com> on 2003/05/30 17:06:50 UTC

html macro library

Has anyone developed a macro library for standard html items?  For
example:
 
#macro (html_href $link $text)

<a href='$link'>$text</a>

#end 

 
--------------------
Kevin Bolton
Paychex Inc 
(585) 216-0808
 <ma...@paychex>  
 



-----------------------------------------
The information contained in this message may be privileged, confidential, and protected from disclosure. If the reader of this message is not the intended recipient, or any employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. 

Thank you. Paychex, Inc.

Re: html macro library

Posted by Andrew Tetlaw <an...@bvn.com.au>.
I like this approach too. I did something that looks similar but uses a 
bunch of classes I wrote instead of an XML library.

In my version $utils refers to my tool loader class. Each tool has a 
hashmap of properties and implements a toString method so you do it 
similarly like this:

#set($checkfield = $tools.getElement('checkbox'))
$checkfield.setProperty('choices', '...')
$checkfield.setProperty('checked', '...')
$checkfield

You only need to put '$checkfield' at the end because all my tools have a 
toString method and Velocity calls this method for every $reference 
anyway.

Using a tool like this you can also put some smarts in it if you like.

I agree that this kind of thing is easier despite requiring more lines. I 
think it makes more sense (easier to read and write) when you're writing 
templates to see what you are setting.

Cheers,
Andrew Tetlaw

Bligh Voller Nield
http://www.bvn.com.au
p: (07) 3251 5778
f: (07) 3852 2544

"Rodrigo Reyes" <ro...@instaservi.com> wrote on 31/05/2003 03:49:47 AM:

> Hi
>     I have been using Velocity on a pretty complex website. One of the
> things I learned from this project is that maybe the easiest and most
> maintainable way to handle the creation of tags inside a template is 
using
> an XML library. For my specific needs, I use JDOM. So when I need to 
have a
> link created I do something like this:
> 
>     #set($a = $utils.getElement('a'))
>     $a.setAttributeValue('href', '...')
>     $a.setAttributeValue(target, '...')
>     $a.setAttributeValue('onClick', '...')
>     ....
>     $a.setText('This text is linked to ...')
>     $utils.toString($a)
> 
>     I know that those are many lines of code for a simple link, but from 
my
> experience, it's a lot easier to read and maintain. And an Element in 
JDOM
> could also contain other Elements, so I can have that as recursive as I
> need.
>     My 2 c...
> 
> Rodrigo
 


<font face="Arial, Helvetica, sans-serif" size="2">
<b>

Please Also Note
</b>This document, including attachments, is only intended for the addressees and may contain privileged or confidential information. Unauthorised use, copying or distribution of the document or any part of its contents, is prohibited. If you receive this Email in error please notify us by return Email or telephone. We will reimburse you for any reasonable expenses incurred in meeting this request.</font> 


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


RE: html macro library

Posted by Kevin Bolton <kb...@paychex.com>.
Thanks Rodrigo,

That's a great "macro" library idea.  It certainly would be
comprehensive and a heck of a lot better that writing one of my own!

Kevin


-----Original Message-----
From: Rodrigo Reyes [mailto:rodrigo@instaservi.com] 
Sent: Friday, May 30, 2003 1:50 PM
To: Velocity Users List
Subject: Re: html macro library


Hi
    I have been using Velocity on a pretty complex website. One of the
things I learned from this project is that maybe the easiest and most
maintainable way to handle the creation of tags inside a template is
using an XML library. For my specific needs, I use JDOM. So when I need
to have a link created I do something like this:

    #set($a = $utils.getElement('a'))
    $a.setAttributeValue('href', '...')
    $a.setAttributeValue(target, '...')
    $a.setAttributeValue('onClick', '...')
    ....
    $a.setText('This text is linked to ...')
    $utils.toString($a)

    I know that those are many lines of code for a simple link, but from
my experience, it's a lot easier to read and maintain. And an Element in
JDOM could also contain other Elements, so I can have that as recursive
as I need.
    My 2 c...

Rodrigo

----- Original Message -----
From: "Kevin Bolton" <kb...@paychex.com>
To: "'Velocity Users List'" <ve...@jakarta.apache.org>
Sent: Friday, May 30, 2003 11:38 AM
Subject: RE: html macro library


> Hey Jonathan,
>
> Thank you for your response and I'm with you on the need for 
> #directiveA(#directiveB)).  It'd also be mighty handy to be able to 
> overload methods.  That is have methods with the same name with 
> different arguments.
>
> I'll look into FreeMarker.
>
> Thanks,
> Kevin
>
> -----Original Message-----
> From: news [mailto:news@main.gmane.org] On Behalf Of Jonathan Revusky
> Sent: Friday, May 30, 2003 11:34 AM
> To: velocity-user@jakarta.apache.org
> Subject: Re: html macro library
>
>
> Kevin Bolton wrote:
> > Has anyone developed a macro library for standard html items?  For
> > example:
> >
> > #macro (html_href $link $text)
> >
> > <a href='$link'>$text</a>
>
> I don't know whether anybody has developed such a library for 
> Velocity, but it seems to me that, unless the macros could be applied 
> recursively,
>
> such a library would be of very limited use-value. Unfortunately, 
> Velocimacros have design problems or limitations that prevent this.
>
> You see, to be generally useful, a block-oriented HTML generating 
> macro would have to be able to take a block (containing potentially 
> other template directives) as its parameter. That is your $text 
> parameter in the above.
>
> FYI, at least one other template engine does afford this possibility. 
> FreeMarker has had the ability to define macros with associated blocks

> since version 2.2.
>
> If the Velocity community does resume active development of the 
> template
>
> engine, then the above kind of feature is probably well worth lobbying

> them for.
>
> Best Regards,
>
> Jonathan Revusky
> --
> lead developer, FreeMarker project, http://freemarker.org/ FreeMarker 
> vs. Velocity comparison page: http://freemarker.org/fmVsVel.html
>
> FreeMarker 2.3 preview 1 is out! :-)
>
>
>
> >
> > #end
> >
> >
> > --------------------
> > Kevin Bolton
> > Paychex Inc
> > (585) 216-0808
> >  <ma...@paychex>
> >
> >
> >
> >
> > -----------------------------------------
> > The information contained in this message may be privileged, 
> > confidential, and protected from disclosure. If the reader of this
> message is not the intended recipient, or any employee or agent 
> responsible for delivering this message to the intended recipient, you

> are hereby notified that any dissemination, distribution, or copying 
> of this communication is strictly prohibited. If you have received 
> this communication in error, please notify us immediately by replying 
> to the message and deleting it from your computer.
> >
> > Thank you. Paychex, Inc.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
> -----------------------------------------
> The information contained in this message may be privileged, 
> confidential,
and protected from disclosure. If the reader of this message is not the
intended recipient, or any employee or agent responsible for delivering
this message to the intended recipient, you are hereby notified that any
dissemination, distribution, or copying of this communication is
strictly prohibited. If you have received this communication in error,
please notify us immediately by replying to the message and deleting it
from your computer.
>
> Thank you. Paychex, Inc.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


-----------------------------------------
The information contained in this message may be privileged, confidential, and protected from disclosure. If the reader of this message is not the intended recipient, or any employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. 

Thank you. Paychex, Inc.


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: html macro library

Posted by Rodrigo Reyes <ro...@instaservi.com>.
Hi
    I have been using Velocity on a pretty complex website. One of the
things I learned from this project is that maybe the easiest and most
maintainable way to handle the creation of tags inside a template is using
an XML library. For my specific needs, I use JDOM. So when I need to have a
link created I do something like this:

    #set($a = $utils.getElement('a'))
    $a.setAttributeValue('href', '...')
    $a.setAttributeValue(target, '...')
    $a.setAttributeValue('onClick', '...')
    ....
    $a.setText('This text is linked to ...')
    $utils.toString($a)

    I know that those are many lines of code for a simple link, but from my
experience, it's a lot easier to read and maintain. And an Element in JDOM
could also contain other Elements, so I can have that as recursive as I
need.
    My 2 c...

Rodrigo

----- Original Message -----
From: "Kevin Bolton" <kb...@paychex.com>
To: "'Velocity Users List'" <ve...@jakarta.apache.org>
Sent: Friday, May 30, 2003 11:38 AM
Subject: RE: html macro library


> Hey Jonathan,
>
> Thank you for your response and I'm with you on the need for
> #directiveA(#directiveB)).  It'd also be mighty handy to be able to
> overload methods.  That is have methods with the same name with
> different arguments.
>
> I'll look into FreeMarker.
>
> Thanks,
> Kevin
>
> -----Original Message-----
> From: news [mailto:news@main.gmane.org] On Behalf Of Jonathan Revusky
> Sent: Friday, May 30, 2003 11:34 AM
> To: velocity-user@jakarta.apache.org
> Subject: Re: html macro library
>
>
> Kevin Bolton wrote:
> > Has anyone developed a macro library for standard html items?  For
> > example:
> >
> > #macro (html_href $link $text)
> >
> > <a href='$link'>$text</a>
>
> I don't know whether anybody has developed such a library for Velocity,
> but it seems to me that, unless the macros could be applied recursively,
>
> such a library would be of very limited use-value. Unfortunately,
> Velocimacros have design problems or limitations that prevent this.
>
> You see, to be generally useful, a block-oriented HTML generating macro
> would have to be able to take a block (containing potentially other
> template directives) as its parameter. That is your $text parameter in
> the above.
>
> FYI, at least one other template engine does afford this possibility.
> FreeMarker has had the ability to define macros with associated blocks
> since version 2.2.
>
> If the Velocity community does resume active development of the template
>
> engine, then the above kind of feature is probably well worth lobbying
> them for.
>
> Best Regards,
>
> Jonathan Revusky
> --
> lead developer, FreeMarker project, http://freemarker.org/ FreeMarker
> vs. Velocity comparison page: http://freemarker.org/fmVsVel.html
>
> FreeMarker 2.3 preview 1 is out! :-)
>
>
>
> >
> > #end
> >
> >
> > --------------------
> > Kevin Bolton
> > Paychex Inc
> > (585) 216-0808
> >  <ma...@paychex>
> >
> >
> >
> >
> > -----------------------------------------
> > The information contained in this message may be privileged,
> > confidential, and protected from disclosure. If the reader of this
> message is not the intended recipient, or any employee or agent
> responsible for delivering this message to the intended recipient, you
> are hereby notified that any dissemination, distribution, or copying of
> this communication is strictly prohibited. If you have received this
> communication in error, please notify us immediately by replying to the
> message and deleting it from your computer.
> >
> > Thank you. Paychex, Inc.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
> -----------------------------------------
> The information contained in this message may be privileged, confidential,
and protected from disclosure. If the reader of this message is not the
intended recipient, or any employee or agent responsible for delivering this
message to the intended recipient, you are hereby notified that any
dissemination, distribution, or copying of this communication is strictly
prohibited. If you have received this communication in error, please notify
us immediately by replying to the message and deleting it from your
computer.
>
> Thank you. Paychex, Inc.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: html macro library

Posted by Daniel Dekany <dd...@freemail.hu>.
Friday, May 30, 2003, 8:56:41 PM, Daniel Dekany wrote:

[snip]
> You would *use* it as (if we would not have the problem with the VTL
> syntax):
>
> #border(color="red")

Ops! I wanted to type:

#border("red")

(BTW, isn't #border(color="red") cool? :) Oh well...)

-- 
Best regards,
 Daniel Dekany



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: html macro library

Posted by Daniel Dekany <dd...@freemail.hu>.
Friday, May 30, 2003, 8:41:00 PM, Kevin Bolton wrote:

> Yes - but then I'd need to pass all of the args for directiveB through
> the call of directiveA, wouldn't I?
>
> For example...
>
> #(directiveA $argForA)
>         $argForA
> #end
>
> #(directiveB $argForB)
>         $argForB
> #end
>
> If directiveA calls directiveB, Wouldn't I need to redefine directiveA
> to be
> #(directiveA $argForA $argForB)
>         $argForA
>         #directiveB ($argForB)
> #end
> ?

Brrrr... what? :) No... So, assume I want create macro "border"
(just for the sake of example).

You would *use* it as (if we would not have the problem with the VTL
syntax):

#border(color="red")
  This is the any VTL.
  Even directives... anything.
#end

and you would *define* the border macro as, say:

#macro( border $color )
  <table border=1 color="$color"><tr><td>
  #body
  </tabe>
#end

So the output of the example macro call would be:

  <table border=1 color="$color"><tr><td>
  This is the any VTL.
  Even directives... anything.
  </tabe>

It most probably can be implemented by the Vel. core developers. Except
that #border(color="red") should somehow indicate that it has an end
#end /-:. Maybe:

#begin border(color="red")
...
#end

)-| ... I'm stuck with VTL syntax, it seems... :)
  
-- 
Best regards,
 Daniel Dekany



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


RE: html macro library

Posted by Kevin Bolton <kb...@paychex.com>.
Yes - but then I'd need to pass all of the args for directiveB through
the call of directiveA, wouldn't I?

For example...

#(directiveA $argForA)
	$argForA
#end

#(directiveB $argForB)
	$argForB
#end

If directiveA calls directiveB, Wouldn't I need to redefine directiveA
to be
#(directiveA $argForA $argForB)
	$argForA
	#directiveB ($argForB)
#end
?
-----Original Message-----
From: Daniel Dekany [mailto:ddekany@freemail.hu] 
Sent: Friday, May 30, 2003 1:55 PM
To: Velocity Users List
Subject: Re: html macro library


Friday, May 30, 2003, 6:38:52 PM, Kevin Bolton wrote:

> Hey Jonathan,
>
> Thank you for your response and I'm with you on the need for 
> #directiveA(#directiveB)).  It'd also be mighty handy to be able to 
> overload methods.  That is have methods with the same name with 
> different arguments.

That should not look like that. That should be:

#directiveA()
  #directiveB
#end

but the parser will not know that directiveA supports body, so it has a
corresponding #end... a trap of the VTL syntax.

-- 
Best regards,
 Daniel Dekany



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


-----------------------------------------
The information contained in this message may be privileged, confidential, and protected from disclosure. If the reader of this message is not the intended recipient, or any employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. 

Thank you. Paychex, Inc.


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: html macro library

Posted by Daniel Dekany <dd...@freemail.hu>.
Friday, May 30, 2003, 6:38:52 PM, Kevin Bolton wrote:

> Hey Jonathan,
>
> Thank you for your response and I'm with you on the need for
> #directiveA(#directiveB)).  It'd also be mighty handy to be able to
> overload methods.  That is have methods with the same name with
> different arguments.  

That should not look like that. That should be:

#directiveA()
  #directiveB
#end

but the parser will not know that directiveA supports body, so it has a
corresponding #end... a trap of the VTL syntax.

-- 
Best regards,
 Daniel Dekany



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


RE: html macro library

Posted by Kevin Bolton <kb...@paychex.com>.
Hey Jonathan,

Thank you for your response and I'm with you on the need for
#directiveA(#directiveB)).  It'd also be mighty handy to be able to
overload methods.  That is have methods with the same name with
different arguments.  

I'll look into FreeMarker.

Thanks,
Kevin

-----Original Message-----
From: news [mailto:news@main.gmane.org] On Behalf Of Jonathan Revusky
Sent: Friday, May 30, 2003 11:34 AM
To: velocity-user@jakarta.apache.org
Subject: Re: html macro library


Kevin Bolton wrote:
> Has anyone developed a macro library for standard html items?  For
> example:
>  
> #macro (html_href $link $text)
> 
> <a href='$link'>$text</a>

I don't know whether anybody has developed such a library for Velocity, 
but it seems to me that, unless the macros could be applied recursively,

such a library would be of very limited use-value. Unfortunately, 
Velocimacros have design problems or limitations that prevent this.

You see, to be generally useful, a block-oriented HTML generating macro 
would have to be able to take a block (containing potentially other 
template directives) as its parameter. That is your $text parameter in 
the above.

FYI, at least one other template engine does afford this possibility. 
FreeMarker has had the ability to define macros with associated blocks 
since version 2.2.

If the Velocity community does resume active development of the template

engine, then the above kind of feature is probably well worth lobbying 
them for.

Best Regards,

Jonathan Revusky
--
lead developer, FreeMarker project, http://freemarker.org/ FreeMarker
vs. Velocity comparison page: http://freemarker.org/fmVsVel.html

FreeMarker 2.3 preview 1 is out! :-)



> 
> #end
> 
>  
> --------------------
> Kevin Bolton
> Paychex Inc
> (585) 216-0808
>  <ma...@paychex>  
>  
> 
> 
> 
> -----------------------------------------
> The information contained in this message may be privileged, 
> confidential, and protected from disclosure. If the reader of this
message is not the intended recipient, or any employee or agent
responsible for delivering this message to the intended recipient, you
are hereby notified that any dissemination, distribution, or copying of
this communication is strictly prohibited. If you have received this
communication in error, please notify us immediately by replying to the
message and deleting it from your computer.
> 
> Thank you. Paychex, Inc.



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


-----------------------------------------
The information contained in this message may be privileged, confidential, and protected from disclosure. If the reader of this message is not the intended recipient, or any employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. 

Thank you. Paychex, Inc.


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: html macro library

Posted by Jonathan Revusky <jo...@revusky.com>.
Kevin Bolton wrote:
> Has anyone developed a macro library for standard html items?  For
> example:
>  
> #macro (html_href $link $text)
> 
> <a href='$link'>$text</a>

I don't know whether anybody has developed such a library for Velocity, 
but it seems to me that, unless the macros could be applied recursively, 
such a library would be of very limited use-value. Unfortunately, 
Velocimacros have design problems or limitations that prevent this.

You see, to be generally useful, a block-oriented HTML generating macro 
would have to be able to take a block (containing potentially other 
template directives) as its parameter. That is your $text parameter in 
the above.

FYI, at least one other template engine does afford this possibility. 
FreeMarker has had the ability to define macros with associated blocks 
since version 2.2.

If the Velocity community does resume active development of the template 
engine, then the above kind of feature is probably well worth lobbying 
them for.

Best Regards,

Jonathan Revusky
--
lead developer, FreeMarker project, http://freemarker.org/
FreeMarker vs. Velocity comparison page: http://freemarker.org/fmVsVel.html

FreeMarker 2.3 preview 1 is out! :-)



> 
> #end 
> 
>  
> --------------------
> Kevin Bolton
> Paychex Inc 
> (585) 216-0808
>  <ma...@paychex>  
>  
> 
> 
> 
> -----------------------------------------
> The information contained in this message may be privileged, confidential, and protected from disclosure. If the reader of this message is not the intended recipient, or any employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. 
> 
> Thank you. Paychex, Inc.



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: html macro library

Posted by Nathan Bubna <na...@esha.com>.
Kevin said:
> Has anyone developed a macro library for standard html items?  For
> example:
>
> #macro (html_href $link $text)
>
> <a href='$link'>$text</a>
>
> #end

There have been some plans to create a library of velocimacros for the
velocity-tools project.  At this point, that has not really begun, and the
specific goals and parameters of such a library have yet to be firmly
established.  However, I can say with some measure of confidence that it is
unlikely that an #html_ref  macro would be included.  At the moment, my opinions
on that are much the same as Lev's.  Such a thing adds as much complexity as it
would replace.  I do think though that useful, "standard" html macros can exist.
There are several I use often that I consider to be candidates for such a
library.

Nathan Bubna
nathan@esha.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org