how do I add a new directive?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

how do I add a new directive?

Stefan Kloe

Hi,
I want to add a new template directive that converts a string at the data model into a dom tree.

Why?
We (the company I am working for) are using a closed source software that uses FreeMarker (for mail templates). It doesn't know (yet?) about FreeMarkers xml abilities. I believe there are more frameworks / programs that use freemarker and just put every variable as a string into the data model. So we came to the conclusion that having a directive to parse a variable into a dom tree may be a good enhancement.

I started looking through the sources but I'm some kind of lost. Any suggestions where to start?

Best regards,
Stefan
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: how do I add a new directive?

Daniel Dekany
Wednesday, February 28, 2007, 3:42:53 PM, Stefan Kloe wrote:

> Hi,
> I want to add a new template directive that converts a string at the
> data model into a dom tree.
[snip]
> I started looking through the sources but I'm some kind of lost. Any
> suggestions where to start? Best regards, Stefan

I shouldn't need to look into the source codes for solving this, the
FreeMarker Manual and the API javadoc should be enough. Anyway, from
what you said, you need not a directive but a method (or function)
here. See TemplateMethodModelEx in the JavaDocs. You can make your
custom method accessible for the templates as shared variable (See
Configuration in the javadocs), or as a part of an FTL library (see
the #import directive and the new (?new) buit-in in the manual).

--
Best regards,
 Daniel Dekany


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Antwort: Re: how do I add a new directive?

Stefan Kloe

Thank you so much, Daniel.

I'm really impressed by FreeMarker. I just extended TemplateMethodModel and used NodeModel.parse inside the exec-method and now everythings works as I wanted it to.

Is there anything I can give back to this project? I don't know if you'd like to get my sources since this is such a minor addition. On the other hand I could contribute a few lines to your manual about how to add a method.

Today was a very good day because of Freemarkers clean design and concept :)

Best regards,
Stefan Kloe
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Antwort: Re: how do I add a new directive?

Daniel Dekany
Friday, March 2, 2007, 5:57:40 PM, Stefan Kloe wrote:

> Thank you so much, Daniel.
>  
> I'm really impressed by FreeMarker. I just extended
> TemplateMethodModel and used NodeModel.parse inside the exec-method
> and now everythings works as I wanted it to.  
>  
> Is there anything I can give back to this project? I don't know if
> you'd like to get my sources since this is such a minor addition. On
> the other hand I could contribute a few lines to your manual about how to add a method.

Er... Surely there is no "How to add a method" section in the Manual,
but it meant to be obvious. Because, it is described that what kind of
types do FTL support, so similarly as you can add a string or number,
you can also add a method to the data model, etc. Anyway, it seems
people are often confused about this, so I added this to my TODO. I
will update the Manual and then the site updates will be uploaded in a
week or so, I hope.

> Today was a very good day because of Freemarkers clean design and concept :)

<OT>
Thanks in the name of all guys who has worked on FreeMarker. But... it
means something that people often say that FreeMarker is this and that
"clean"... because IMO it looks pretty ugly because of all the
historical baggage it carries and project manager switches and
whatever misnomers (well, I wasn't always here... ;)). So, come on, OS
Java programmers of the world, is this something you usually don't
beat in clarity?
</OT>

> Best regards,
> Stefan Kloe

--
Best regards,
 Daniel Dekany


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Antwort: Re: how do I add a new directive?

Attila Szegedi
Well, there are realy many aspects to this question. We certainly have to  
support some "historical baggage" and this makes the code less concise  
than it could be if it wasn't there. I'd however say that it doesn't make  
the code less clean. For me, clean means implemented as elegantly as  
possible to serve its purpose, and we're quite good in that regard, IMHO.  
Backward compatibility is a feature, so the code to support this feature  
has to be there. But we aren't making things needlesly messy, nor do we  
resort to amateurish hacks in implementation. Well, at least we try hard  
not to. Of course, throwing out BWC as a requirement would indeed make the  
code more compact, as it would no longer mannifest itself as a concern  
there :-)

That said, if anyone out there is still using "classical compatibility"  
flag, please raise your hand.

Attila.

On Fri, 02 Mar 2007 19:31:43 -0000, Daniel Dekany <[hidden email]>  
wrote:

> Friday, March 2, 2007, 5:57:40 PM, Stefan Kloe wrote:
>
>> Today was a very good day because of Freemarkers clean design and  
>> concept :)
>
> <OT>
> Thanks in the name of all guys who has worked on FreeMarker. But... it
> means something that people often say that FreeMarker is this and that
> "clean"... because IMO it looks pretty ugly because of all the
> historical baggage it carries and project manager switches and
> whatever misnomers (well, I wasn't always here... ;)). So, come on, OS
> Java programmers of the world, is this something you usually don't
> beat in clarity?
> </OT>
>
>> Best regards,
>> Stefan Kloe
>

--
home: http://www.szegedi.org
weblog: http://constc.blogspot.com

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Antwort: Re: how do I add a new directive?

Daniel Dekany
Tuesday, March 6, 2007, 9:30:02 AM, Attila Szegedi wrote:

> Well, there are realy many aspects to this question. We certainly have to
> support some "historical baggage" and this makes the code less concise
> than it could be if it wasn't there. I'd however say that it doesn't make
> the code less clean. For me, clean means implemented as elegantly as  
> possible to serve its purpose, and we're quite good in that regard, IMHO.

But look at it with the eyes of the newcomer. Or actually, with anyone
who doesn't deal with FreeMarker itself. We have misnomers (both in
API and terminology) and even not-too-intuitive packaing, that will
confuse people. And even functional problems, like we don't have a
real Directive class or interface that users could to write whatever
directives that are possible with #macro. Then, the language design
itself suffers from the bad decisions of the past somewhat as well. So
these are what I have referred to, when I said it's strange people
used to call it is clean. This engine went trough a lot of history (in
net developement time) and thus (naturally) got dirty.

> Backward compatibility is a feature, so the code to support this feature
> has to be there. But we aren't making things needlesly messy, nor do we
> resort to amateurish hacks in implementation. Well, at least we try hard
> not to. Of course, throwing out BWC as a requirement would indeed make the
> code more compact, as it would no longer mannifest itself as a concern
> there :-)
>
> That said, if anyone out there is still using "classical compatibility"
> flag, please raise your hand.

Does that flag working at all? I mean, without being too buggy?

> Attila.
>
> On Fri, 02 Mar 2007 19:31:43 -0000, Daniel Dekany <[hidden email]>
> wrote:
>
>> Friday, March 2, 2007, 5:57:40 PM, Stefan Kloe wrote:
>>
>>> Today was a very good day because of Freemarkers clean design and  
>>> concept :)
>>
>> <OT>
>> Thanks in the name of all guys who has worked on FreeMarker. But... it
>> means something that people often say that FreeMarker is this and that
>> "clean"... because IMO it looks pretty ugly because of all the
>> historical baggage it carries and project manager switches and
>> whatever misnomers (well, I wasn't always here... ;)). So, come on, OS
>> Java programmers of the world, is this something you usually don't
>> beat in clarity?
>> </OT>
>>
>>> Best regards,
>>> Stefan Kloe

--
Best regards,
 Daniel Dekany


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Antwort: Re: how do I add a new directive?

Attila Szegedi
On Tue, 06 Mar 2007 08:50:47 -0000, Daniel Dekany <[hidden email]>  
wrote:

>
> But look at it with the eyes of the newcomer. Or actually, with anyone
> who doesn't deal with FreeMarker itself. We have misnomers (both in
> API and terminology) and even not-too-intuitive packaing, that will
> confuse people. And even functional problems, like we don't have a
> real Directive class or interface that users could to write whatever
> directives that are possible with #macro. Then, the language design
> itself suffers from the bad decisions of the past somewhat as well. So
> these are what I have referred to, when I said it's strange people
> used to call it is clean. This engine went trough a lot of history (in
> net developement time) and thus (naturally) got dirty.
>

Yes, I agree with you on all these points.

>> Backward compatibility is a feature, so the code to support this feature
>> has to be there. But we aren't making things needlesly messy, nor do we
>> resort to amateurish hacks in implementation. Well, at least we try hard
>> not to. Of course, throwing out BWC as a requirement would indeed make  
>> the
>> code more compact, as it would no longer mannifest itself as a concern
>> there :-)
>>
>> That said, if anyone out there is still using "classical compatibility"
>> flag, please raise your hand.
>
> Does that flag working at all? I mean, without being too buggy?

Well, nobody's complaining :-)

Attila.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel