You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Leszek Gawron <lg...@mobilebox.pl> on 2004/12/08 22:04:30 UTC
JXTG: invoke macro by name from expression
I would like to add one feature to JXTG that would allow not to promote
hacks like [1]. Example:
<jx:macro name="fooBar">
<some>content</some>
</jx:macro>
you can only invoke it by <fooBar/>
If I were able to do <jx:invoke macro="fooBar"/> I would be able to pass
macro name as a parameter to other macro which allows quite powerful
data injection technique:
<jx:macro name="superPrettyPrintedTable">
<jx:parameter name="headerTemplate"/>
<jx:parameter name="elements"/>
<jx:parameter name="rowTemplate"/>
<!-- fancy code with lots of graphics here -->
<table>
<tr>
<jx:invoke macro="${headerTemplate}"/>
</tr>
<jx:forEach var="currentElement"
items="elements"
varStatus="status">
<tr>
<td>${status.index}</td>
<jx:invoke macro="${rowTemplate}" element="${currentElement}"/>
</tr>
</jx:forEach>
</table>
<!-- fancy code with lots of graphics there -->
</jx:macro>
then use the macro like this:
<jx:macro name="addressesHeaderTemplate">
<th>City</th><th>Street</th>
</jx:macro>
<jx:macro name="addressRowTemplate">
<jx:parameter name="address"/>
<td>${address.city}</td>
<td>${address.street}/td>
</jx:macro>
<jx:invoke macro="superPrettyPrintedTable"
headerTemplate="addressHeaderTemplate"
elements="${addresses}"
rowTemplate="addressRowTemplate"/>
WDYT? We could deprecate jx:eval then which is not fully supported as
additional Map structure has to be used as [1] shows.
It does not seem that much coding is needed. I could also strip all
inner classes from JXTG at the same time as the first step for JXTG
refactoring.
[1] http://cocoon.apache.org/2.1/userdocs/flow/jxtemplate.html#eval
--
Leszek Gawron lgawron@mobilebox.pl
Project Manager MobileBox sp. z o.o.
+48 (61) 855 06 67 http://www.mobilebox.pl
mobile: +48 (501) 720 812 fax: +48 (61) 853 29 65
Re: JXTG: invoke macro by name from expression
Posted by Glen Ezkovich <ge...@mac.com>.
On Dec 8, 2004, at 3:04 PM, Leszek Gawron wrote:
> I would like to add one feature to JXTG that would allow not to
> promote hacks like [1]. Example:
>
> <jx:macro name="fooBar">
> <some>content</some>
> </jx:macro>
>
> you can only invoke it by <fooBar/>
>
> If I were able to do <jx:invoke macro="fooBar"/> I would be able to
> pass macro name as a parameter to other macro which allows quite
> powerful data injection technique:
>
> <jx:macro name="superPrettyPrintedTable">
> <jx:parameter name="headerTemplate"/>
> <jx:parameter name="elements"/>
> <jx:parameter name="rowTemplate"/>
> <!-- fancy code with lots of graphics here -->
> <table>
> <tr>
> <jx:invoke macro="${headerTemplate}"/>
> </tr>
> <jx:forEach var="currentElement"
> items="elements"
> varStatus="status">
> <tr>
> <td>${status.index}</td>
> <jx:invoke macro="${rowTemplate}" element="${currentElement}"/>
> </tr>
> </jx:forEach>
> </table>
> <!-- fancy code with lots of graphics there -->
> </jx:macro>
>
> then use the macro like this:
> <jx:macro name="addressesHeaderTemplate">
> <th>City</th><th>Street</th>
> </jx:macro>
> <jx:macro name="addressRowTemplate">
> <jx:parameter name="address"/>
> <td>${address.city}</td>
> <td>${address.street}/td>
> </jx:macro>
> <jx:invoke macro="superPrettyPrintedTable"
> headerTemplate="addressHeaderTemplate"
> elements="${addresses}"
> rowTemplate="addressRowTemplate"/>
>
>
> WDYT? We could deprecate jx:eval then which is not fully supported as
> additional Map structure has to be used as [1] shows.
>
> It does not seem that much coding is needed. I could also strip all
> inner classes from JXTG at the same time as the first step for JXTG
> refactoring.
Sounds good to me. a non-voting +1
Glen Ezkovich
HardBop Consulting
glen at hard-bop.com
http://www.hard-bop.com
A Proverb for Paranoids:
"If they can get you asking the wrong questions, they don't have to
worry about answers."
- Thomas Pynchon Gravity's Rainbow