Leszek Gawron wrote:

As we have now two ways of calling a macro:

<root xmlns:jx="http://apache.org/cocoon/templates/jx/1.0";>
    <jx:macro name="d">
        <jx:parameter name="p"/>
        <macroTest a="${p}">
            <jx:evalBody/>
        </macroTest>
    </jx:macro>
    <m>
        <d p="foo">
            <content b="${1+2}"/>
        </d>
    </m>
    <n>
        <jx:set var="macroName" value="d"/>
        <jx:call macro="${macroName}">
            <jx:withParam name="p" value="bar"/>
            <content b="${2+3}"/>
        </jx:call>
    </n>
</root>

what do you think about removing the old syntax in 2.2?
<d p="foo">
<content b="${1+2}"/>
</d>
For me it is counter-intuitive and leads to accidental mistakes (not so easy to find by newbies).


-1 on removing this syntax, as it prevents writing things such as the CForms template language using JXTG (or CTemplate).

Or if you find this counter-intuitive, maybe we can introduce the concept of "element interceptor" which is a macro that gets called when a particular element is encountered. This makes it explicit that some elements will become macro calls.

<jx:intercept element="ft:widget">
 <!-- macro body -->
</jx:intercept>

I also propose to remove <jx:eval/> tag as it is probably only used for:
<root xmlns:jx="http://apache.org/cocoon/templates/jx/1.0";>
  <jx:set var="tags" value="${java.util.HashMap()}"/>
  <jx:macro name="dynamic-tag">
    <jx:parameter name="id"/>
    <jx:set var="ignored" value="${tags.put(id, macro.body)}"/>
  </jx:macro>

  <dynamic-tag id="example">
    <em>This tag was invoked dynamically</em>
  </dynamic-tag>

  <p>I'm about to invoke a dynamic tag:</p>
  <jx:eval select="${tags.example}"/>
</root>

which is clearly a hack that can be now implemented nicely with:
<root xmlns:jx="http://apache.org/cocoon/templates/jx/1.0";>
  <jx:macro name="example">
    <em>This tag was invoked dynamically</em>
  </jx:macro>

  <p>I'm about to invoke a dynamic tag:</p>
  <jx:set var="dynamicName" value="example"/>
  <jx:call macro="${dynamicName}"/>
</root>

Moreover you can provide a body with <jx:call/> which you cannot do with <jx:eval/>


Sounds good.

Another question:
Do you think this syntax would be useful?
<jx:call macro="${macroName}" p="bar">
    <content b="${2+3}"/>
</jx:call>


Do you mean the "p" param as attribute? Yes, it's useful, because IMO <jx:withParam> is just as overly verbose as XSLT, to which JXTG is supposed to provide a simpler replacement ;-)

Sylvain

--
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }



Reply via email to