[stringtemplate-interest] Does StringTemplate support components?

Terence Parr parrt at cs.usfca.edu
Tue Jan 2 15:25:53 PST 2007


On Dec 27, 2006, at 4:45 PM, Bill Venners wrote:
> So why not let each component keep track of its own data and
> templates, and do the rendering of itself. What I'd need in ST is a
> way to call render() on components I suppose, and I don't believe I
> have a way to do that in ST, because it would open up the possibility
> of calling any arbitrary Java code.

Hi Bill, sorry for the delay, I have been working like mad to finish  
the new ANTLR V3 book.

Can you just make the component answer toString()?

> The other thing that bugs me a bit is that I can't know at compile
> time if I'm using a parameter in a template that doesn't exist in the
> data.

Yeah, that is annoying.

> I'm tempted towards the JSP approach of taking some template
> and translating it into print statements that could be called by the
> render method of component objects. These would not compile if there
> were naming problems.

I have thought about a mode where STs could be translated to pure  
Java or whatever language.

> I know that Terrence came to the design of ST while solving real
> problems of web pages and code generation. Is there any reason why
> doing such a component approach might be less useful in practice than
> the ST approach?

The only issue is that you're using real code, which opens up the  
potential for abuse.    Templates can't be extended with us all sorts  
of functionality whereas the component could be.  Further, components  
can't be used by graphics designers-- they have to be programmers to  
understand code.

Ter


More information about the stringtemplate-interest mailing list