cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vadim Gritsenko <va...@reverycodes.com>
Subject Re: [RT] Attribute Driven Templates (Was: [RT] do me a favor, don't call them taglibs)
Date Tue, 07 Dec 2004 01:40:11 GMT
Daniel Fagerstrom wrote:
> 

Just a reminder; before you guys start implementing one or another template 
language, could we have [VOTE] for one of the variants, have [PROPOSAL], or at 
least [SUMMARY]? :)

Here, I just want to comment that I find way more intuitive and user friendly 
following constructs:


> if(<test>)
> ----------
> 
> example:
> 
> <div do="if(count(cart/item) == 0)">

<div t:if="cart/item">
and
<div t:unless="cart/item">
for conditions.


>   Your cart is empty
> <div>
> 
> 
> forEach(<sequence>)
> -------------------
> 
> example:
> 
> <table>
>   <tr do="forEach(cart/item)">

<tr t:forEach="cart/item">
or
<tr t:forEach="item in cart/item">
for iterators.


>     <td>${index}</td>
>     <td>${description}</td>
>     <td>${price}</td>
>   </tr>
> </table>
> 
> 
> for(var=<name>,begin=<expr>,end=<expr>,step=<expr>)
> ---------------------------------------------------

Is it necessary? Current jxtg does not have it (IIRC).


> context=<expr>
> --------------
> 
> Set the current evaluation context for expressions.
> 
> example:
> 
> <table do="context=/shopping/cart">

<table t:for="/shopping/cart">
or t:context, or some such.

... and the rest is similar. I also feel that expressions like 
"if();context();let();for();etc;etc;etc" are too complicated for what is 
necessary in Cocoon Templates.

Vadim


>   ...
> </table>
> 
> 
> let(<name>=<expr>,...,<name>=<expr>)
> ------------------------------------
> 
> Define a number of variables for the current context. Observe that this 
> not is a set operation it just defines the content of the variable 
> $<name> in the current context, it doesn't intoduce any possibilities to 
> have side effects.
> 
> example:
> 
> <h1 do="let(greeting=concat('Hello', user)>
>   The value of greeting is ${$greeting}
> <h1>
> 
> 
> macro(<name>,<param-name>,...,<param-name>)
> -------------------------------------------
> 
> example:
> 
> <table do="macro(mytable,list,td-class)">
>   <tr do="forEach($list)">
>     <td class="${$class}">${item}</td>
>   </tr>
> </table>
> 
> We also need an evalBody as in JXTG. And maybe we should have a 
> possibilty to give a name space to the macro name.
> 
> 
> eval(<name>,context=<expr>,<param-name>=<expr>,...,<param-name>=<expr>)
> -----------------------------------------------------------------------
> 
> Evaluates the named macro in either the curent context or the 
> excplictliy chosen, with a number of forma parameters. The containing 
> element is replaced by the result of the evaluation. And the content of 
> the the containing element is available in the macro through "evalBody".
> 
> example:
> 
> <table do="eval(mytable,list=carts,class='checked-out')"/>
> 
> We could maybe even have the synatax:
> 
> <table do="mytable(list=carts,class='checked-out')"/>
> 
> for user defined macros.
> 
> 
> replace(<expr>)
> ---------------
> 
> Replaces the containing element with the result of the expression, 
> useful for inserting DOM etc from the flow layer.
> 
> example:
> 
> <div do="replace(.)"/>
> 
> 
> content(<expr>)
> ---------------
> 
> Like replace but replaces only the content.
> 
> 
> attributes(<name>=<expr>,...,<name>=<expr>)
> -------------------------------------------
> 
> Inserts an attribute.
> 
> 
> Several directives
> ------------------
> 
> So, how do we handle multiple directives for one element? We could 
> handle the TAL example above like:
> 
> <p 
> do="let(x=/a/long/path/from/the/root;if(x);content(x/txt);attributes(class=x/class)">

> 
>   Ex Text
> </p>
> 
> The idea is that when the leftmost directive is executed it has the 
> ability to access the result of executing the directive sequence right 
> of it in its current context. It will be the rightmost directive that 
> has direct access to the containing element with evaluated attributes 
> and body.
> 
> The corresponding tag based template expression would be (in pseudo jx):
> 
> <jx:let name="x" value="/a/long/path/from/the/root">
>   <jx:if test="x">
>     <jx:content select="x/txt">
>       <jx:attribute name="class" value="x/class">
>         <p>Ex Text</p>
>       </jx:attribute>
>     </jx:content>
>   </jx:if>
> <jx:let>
> 
> The jx:attribute and jx:content returns the patched variant of its 
> respectively body. Not particulary natural constructions in a tag based 
> template language, but hopefully it explains the direcive combination 
> construction.

<snip/>

Mime
View raw message