[stringtemplate-interest] String manipulations
John Snyders
jjsnyders at rcn.com
Fri Sep 29 20:17:51 PDT 2006
>
> Would it make sense to have a syntax for templates where the
> template (/group /global specification), specifies which renderer
> Classes should be attached to this template (/group /global
> default) ??
No, As the ST documentation says "You will notice that there is no way for
the template to say which renderer to use. Allowing such a mechanism would
effectively imply an ability to call random code from the template. In
StringTemplate's scheme, only the model or controller can set the renderer."
> > > > To sum up I would like to see option 4 supported and implemented as
> > > > you
> > > > described. The formatting would apply to (the result of) templates
> > > > to be
> > > > consistent with the ;separator.
> > >
> > > Yes, so I'd evaluate the entire expressions even if
> > >
> > > $names:{$i$. <b>$it$</b>}$; format="upperCase"$
> > >
> > > Here, the entire list of crap would be uppercased including the $i$
> > > numbers. Right?
> >
> > Yes I think that makes sense.
>
> 'separator' applies "between item pairs". Intuitively I would
> expect 'format' to apply "to each item".
>
> What if format="initialCaps"? In this case I would expect format
> to be passed each item one by one.
There seems to be a question about if format applies to each item
individually or to the whole template result.
In general options (that is what ;format is) apply to the template they
follow
The syntax is template-expression;options-list
What an option does with the expression is up to the option. Most of the
examples show ;separator applied to either attributes or template
applications that are multi valued. The same is true of ;null. ;separator
can be applied to a single value attribute or expression it just doesn't
have any effect in that case (because there is no in between). ;null can
also be applied to a scalar attribute:
$attr;null="unknown"$
is shorthand for
$if(attr)$$attr$$else$unknown$endif$
BTW: this does not work as I expected $[x, y, z];null="null"$ where some of
x, y, z are null.
I haven't played with wrap and anchor yet.
I think that format should apply to the whole template expression result. It
is consistent with the intent of format which is to control rendering. There
is no loss of control since you can do
$names:{Hello $it$;format="toUpper"}$
or
$names:{Hello $it$};format="toUpper"$
with names having Bob, Sue the first will output
Hello BOB Hello SUE
The second will output
HELLO BOB HELLO SUE
The other question was how does ;format interact with ;separator. Or more
general how do all the options interact. I'm not sure but I think the order
should be ;null, ;separator, ;format. I don't know where wrap and anchor fit
in.
> How about these:
>
> /* add separator after each name: */
> $names:separator=","$
No the : operator is used to apply templates so this would be confusing.
Also it is not needed because one can always add the extra , at the end
$names;separator=","$,
If there is a chance names could be empty then use
$names;separator=","$$if(names)$,$endif$
> /* add separator after all but last name: */
> $names;separator=","$
This is what we already have. It puts the separator between the elements.
>
> $names:{$i$. <b>$it$</b>}:format="upperCase"$
> $names:{$i$. <b>$it$</b>};format="upperCase"$
>
> $names:{$i$. <b>$it:format="upperCase"$</b>}$
> $names:{$i$. <b>$it;format="upperCase"$</b>}$
>
> $(names:{$i$. <b>$it$</b>}):format="upperCase"$
> $(names:{$i$. <b>$it$</b>});format="upperCase"$
>
>
> $names:{$i$. <b>$it$</b>}:format="initialCaps"$
> $names:{$i$. <b>$it$</b>};format="initialCaps"$
>
> $names:{$i$. <b>$it:format="initialCaps"$</b>}$
> $names:{$i$. <b>$it;format="initialCaps"$</b>}$
>
> $(names:{$i$. <b>$it$</b>}):format="initialCaps"$
> $(names:{$i$. <b>$it$</b>});format="initialCaps"$
>
> ??
Again the :format syntax is confusing.
The ;format syntax is something I am in favor of as long as the format
string (upperCase) for example specifies a method to call and not a string
to pass to a method.
The value of the format options "initialCaps", "upperCase" etc. should have
no effect on how format behaves.
-John
More information about the stringtemplate-interest
mailing list