Re: Another Idea/Question
Luther Baker <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
On Nov 13, 2008, at 6:53 AM, Daniel Dekany wrote:
> Saturday, November 8, 2008, 6:29:38 PM, Luther Baker wrote:
>
>> Hope I'm not bothering anyone's time but wanted to run another idea
>> past you.
>>
>> I know that a macro can be implemented by a Java class as well as a
>> text template.
>>
>> I have a desire to do 'both' simultaneously.
>>
>> <snip.../>
>> but it would still work. Is there a more elegant way to do this in
>> FM?
>
> I think the usual way of doing this is that you write the "editor"
> macro in FTL, and then that macro calls out for the java code
> explicitly:
>
> <#macro editor>
> <#local m = macroHelpers.editor()> <#-- calls a Java method -->
> ${m.fieldOne} ${m.fieldTwo}
> </#macro>
>
> (In any case, conveniently calling a macro has much higher priority
> than conveniently defining it, so writing <@DualMacro table/> and like
> into your templates is most certainly a bad idea.)
>
> --
> Best regards,
> Daniel Dekany
>
I agree with your sentiment there at the end - but I also have an
ambitious goal to also make it easy to define macros. I think more
people will use them (at least, within my framework).
To that end - I believe I can create an abstract base class to
encapsulate most of the arguments required to implement
TemplateDirectiveModel and then come up with some type of mechanism to
invoke the end user's methods - but with reflection in such abundance
these days - I'd much prefer a native FTL runtime lookup mechanism
that noticed exactly what the user implemented (conventional method
names or annotations) and invoked the operation as such. To that end -
I've been able to avoid interfaces for the most part, etc. For what it
is worth, the new Spring MVC and Tapestry annotations do just that.
GET and POST methods as well as arguments can be annotated and thereby
- leverage the simple use of POJOS.
No problems - that is simply what I am doing in my framework and I'm
trying to shoehorn FTL in as my template engine. It is working great!
I just want to offer a very simple way for a developer to write macros
or 'components' in Java.
I've not looked at the code - but is it possible that this mechanism
is injected? :) That'd be easy to overwrite ... essentially, find the
method the user wants to match up to this directive and invoke it
every time the directive shows up. Again, FTL is great, I'm just
exposing certain things in my framework and the more direct the
mapping to FTL, the easier is it to publish.
Thanks again,
-Luther
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/