[stringtemplate-interest] accept simple expression language
DVD
dvd at newfoundmarket.com
Tue May 12 12:06:35 PDT 2009
Hi, Terence:
what I meant was a scenario where the webs app let end user create a
template, say a web page template
and upload it to the Java web server directory that hosting personal ST
based
web publishing CMS. I could publish all the properties (say, O.a, O.b)
my current model provides for user to use in the ST file. But if one
user wants
to diplay the result of a+b, what should I do? Of course, the user
could request
me to add a property "c" = a+b. but that would make this CMS quite backward
compared to many other CMS. The worse, it might not make sense
to add this property to the Java model just for one user, or it might
end up with thousands
of properties like this. With a basic expression function in place,
the end user
could do basic "scripting" to get what they need without replying on
developer to provide
for them., I am talking about basic set of expressions such as simple
math, string maipulation,
alike, not a full blown languange. I know it "pollute" a little it would
make ST a complete solution to me.
In other words, this is a scenario that the model might not be readily
able to provide author
with needed values. It does not have to be "add".
Regards.
Terence Parr wrote:
> Hi,
>
> Well,My experience is that you don't really mean low-level operation
> like add. that is what computers understand. humans use low-level
> operations because it implements things like price including tax or
> give discount things like that. Are you sure you mean add? don't you
> mean some higher-level operation that really belongs in a model? why
> can't you ask the model to give you the result of some high-level
> operation and then implement it using addition in your model? the
> antlr tool code generator with all of its multiple targets is
> extremely complex and there is not a single need to do what you ask. I
> be surprised if we couldn't come up with a way to think about the
> problem that did not require you to violate the principles.
>
> Ter
> On May 11, 2009, at 8:06 PM, DVD wrote:
>
>> Hi, Terence,
>> Customization might not be the correct wording.
>> I understand ST enforces the separation. But I wonder if an option
>> could be provided when really needed for scenarios that
>> the authors either do not know Java or do not have easy means
>> to add property to model. In my example, the visitor would be allowed
>> to create their own template for their own web page and they would be
>> presented properties available from the model (a and be here).
>> if the user requires a value of c = a+b to be display in the web
>> page, then
>> there would not be easy way to do this.
>>
>> Perhaps some mechanism and built-in (and localled developed)
>> expression handler
>> could be provided so that authors could use somethinf like
>> $handler_add(O.a+O.b)$ where "handler" would be a special label
>> indicating to the ST engine that this is a expression processor to
>> call the provided expression handler.
>>
>> This is not a frequently used feature but I feel this would prevent
>> any showstopper when
>> needed. Otherwise, I would have to use another template system just
>> for this purpose.
>>
>> I know this could "pollute" the clean design of ST but I feel it
>> would be worth it to make it
>> all-around player with a slight compromise. Remember it took Sun so
>> many years to
>> give up the marketing of safe String class to provide the
>> StringBuilder class :-)
>>
>> Regards
>>
>>
>>
>>
>> Terence Parr wrote:
>>> Hi. Addition or other computation on model values is forbidden in
>>> the view to avoid entangling model/view. You really need to compute
>>> in the model and pass in some how. Adding numbers isn't
>>> "customization" though as you ask about...it's an entanglement to be
>>> avoided :)
>>>
>>> Ter
>>> On May 10, 2009, at 12:58 PM, DVD wrote:
>>>
>>>> Hello:
>>>>
>>>> I experimented with ST and really like use it for all my projects
>>>> replacing freemarker.
>>>> The only thing I feel uncertain is that ST does not provide an option
>>>> to allow using a simple expression langauge for template author for
>>>> customization without
>>>> requiring model developer to provide the needed data. For example,
>>>> if originally the template is like
>>>>
>>>> $O.a$$O.b$
>>>>
>>>> but a user wants to have only value c = summing a and b,
>>>> something like
>>>> $O.a+O.b$
>>>>
>>>> I guess in order to get this, model dev has to add property "c" in
>>>> O in
>>>> order for author
>>>> to get. This is a big problem if an application expects authors to
>>>> import their own templates,
>>>> since the authors would have no way to customize it, even for some
>>>> simple operation.
>>>> Renderer might not help so I am not sure if there is any solution for
>>>> this scenario. I went through
>>>> the doc but did not have an example.
>>>>
>>>> Thanks
>>>>
>>>> _______________________________________________
>>>> stringtemplate-interest mailing list
>>>> stringtemplate-interest at antlr.org
>>>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>>>
>>
>
More information about the stringtemplate-interest
mailing list