cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leszek Gawron <lgaw...@mobilebox.pl>
Subject JXTG: invoke macro by name from expression
Date Wed, 08 Dec 2004 21:04:30 GMT
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

Mime
View raw message