[stringtemplate-interest] Renderer "modes"

Terence Parr parrt at cs.usfca.edu
Mon Jun 19 11:20:53 PDT 2006


On Jun 19, 2006, at 11:15 AM, Jeremy Gray wrote:

> I've read the paper (I think I've read through all of the ST paper
> versions, presentation versions I can find, and its been quite an
> experience watching them evolve over time :)

Yeah, it's been a long road to formalize all this stuff given that I  
have been cranking on ANTLR v3 at same time ;)

> but unless I missed
> something it doesn't address the example brought up in my reply  
> (that of
> needing to, for example, format DateTime instances differently within
> the same template). Can you point me in the right direction?

Sure.  Check section 4 at the end:

What happens when the designer needs dates to be some-
times long and sometimes short format? This case is also
easily handled without resorting to unrestricted code in the
template and without burdening the programmer with the
extra code needed to wrap all date attributes. The Date
class can be subclassed to provide property methods such
as getMedium() so that templates may reference $myDate$
to get the default rendering and $myDate.medium$ to get
a medium format. For any given type, the developer may
automatically provide augmented properties without hav-
ing to manually create instances of a Date subclass. The
setAttribute() method of the ST class can be overridden
to trap and automatically wrap ob jects of a particular type
to provide new properties...

Ter


More information about the stringtemplate-interest mailing list