[stringtemplate-interest] [antlr-interest] StringTemplate functions like capitalize()?
Nate
misc at n4te.com
Wed Mar 21 13:11:26 PDT 2007
Calling an arbitrary method from ST is against the rules, but the action
the OP is trying to perform is for display only. The only real solution
is to get the ST source and add a capitalizeFirst function. Other
solutions are clunky at the very least.
On a similar note, I have found the lack of ST expressiveness a problem.
I have lists of objects that contain the data I want to display. In many
cases the objects contain lists of other objects. When the data in my
objects are not in such a format that ST can display them like I want, I
find I have to modify my objects to expose the data in the way ST needs.
What this means is that the UI layer is affecting my API. For simple
templates, values can be retreived from an object and put in various
template attributes. But more complex object graphs make this very messy
and difficult, if not impossible.
I am all for separating model and view, but I don't think view-only
logic expressiveness should be lost. As it is now with ST being
relatively strict with enforcing the "rules", there are still various
ways I can break the separation. 100% fool proof would make ST too
restrictive and difficult to use. You have made certain sacrifices and
this makes sense. I think ST should follow all the rules out of the box
and enforce them to the best of its ability, but make it easier to
implement view-only logic. It should be easy to add a view method like
capitalizeFirst.
-Nate
Terence Parr wrote:
> Hi, That is against the "rules". Can't call generate code from a view.
>
> You need a renderer or the like.
>
> ter
> On Mar 18, 2007, at 4:16 AM, Joan Pujol wrote:
>
>
>> Hello,
>>
>> It's possible to call a external function with stringtemplate?
>> I've the problem that I'm generating Java code and for Beans
>> convention I need to capitalize.
>>
>> Something like:
>>
>> basictype(name,type)::= <<
>> private final <typeMap.(type)> name= new <typeMap.(type)>();
>>
>> public <typeMap.(type)> get<name>() { capitalization wanted
>> in get<name>()
>> return <name>;
>> }
>>
>>
>> --
>> Joan Jesús Pujol Espinar
>> http://www.joanpujol.cat
>> http://lujop.deviantart.com
>>
More information about the stringtemplate-interest
mailing list