[stringtemplate-interest] format option implementation details
John Snyders
jjsnyders at rcn.com
Sun Dec 10 12:34:21 PST 2006
> > To make use of format you must create a renderer that implements
> > AttributeRenderer. AttributeRenderer is enhanced to add the
> > toString method that takes a formatName. (Now that I think of it,
> > for backwards compatibility perhaps we should create a new
> > interface such as AttributeRendererEx? so that existing renderers
> > don't break)
>
> Well, at least the compiler will tell them and it's a quick
> change...I'd prefer to force this "upgrade" probably.
OK
> > There are two interesting things to be aware of with the format option
> > 1) If format is applied to a template rather than an attribute an
> > intermediate string must be created so that the format can be
> > applied to the result of the template. This is not unlike when a
> > template is used in an indirect property (i.e. $attribute.({<some
> > template})$
>
> Good point. format forces early evaluation. :)
>
> > 2) if the renderer is associated with type String then it is
> > possible for the value of an attribute to be rendered twice. This
> > will only happen if the format is applied to a template rather than
> > an attribute.It happens because the String attribute is rendered
> > and written as part of the value of the template expansion then the
> > format is applied to the String value of the template. Now that I
> > think of this more it may be a bug. I'll look into it.
>
> Just an efficiency thing.
Not just efficiency. I depends on if your rendering is idempotent.
I had a renderer that escaped quotes " --> \". Now I end up with \\"
> > I need to do more testing but here is what I have done so far. If
> > someone wants the whole file let me know and I can send it but it
> > has other changes as well.
>
> I'll do my own implementation, using your excellent work as a guide!
> May I paraphrase your text here for the manual?
no problem
More information about the stringtemplate-interest
mailing list