[stringtemplate-interest] Automatically extracting sub-templates? (LONG)

Paul Winkler pw_lists at slinkp.com
Mon Feb 6 16:53:37 PST 2006


Hi,

I've just today discovered StringTemplate, and am doing preliminary
evaluations of it for company-wide templating. We are building
a large website based on a service-oriented architecture where
some services may be implemented in Java app servers, some may
be Python, etc.  Most of our output will initially be HTML,
but we may target unspecified formats in the future.
So a portable, flexible templating language that allows the
same templates to be used on different platforms / languages
is very desirable.  I like the "push" model too.

My question is this:
Can anyone think of an easy way to automatically extract
sub-templates, given a large template?

Use case:
Designer creates full-page HTML mockup.
Designer creates StringTemplate markup based on that HTML mockup.
Each app renders only small fragments of that page, which are 
assembled by a controller.  

(I'm sure somebody will jump in and say that each app should
only be returning XML or JSON or something, and only one central
view layer should have anything to do with HTML. Yes, well, we may yet
do that, and I'm not even on the architecture team; meanwhile this is
what I've been tasked with investigating.)

Now, I don't want the apps to have to know how to extract just the part
of the template they are interested in and throw away the rest. 
That seems like unnecessary responsibility for each app.
So it would be better to factor out the template into sub-templates
and each app will only use a small template tailor-made for its
fragment of the page.

But neither do I want us to have to manually rewrite some or all of
those subtemplates whenever the visual design changes.  
I've been down the road of
pages-assembled-from-lots-of-tiny-manually-maintained-fragments, and I
do not like it; too fragile, and a pain to figure out which bit of
markup came from which template.

So, I'd prefer to automatically extract the subtemplates whenever the
master template is changed.  There is a layout management application in
this architecture, and it knows which apps are responsible for which
"slots", so it could be given this responsibility.
  
What I'm trying to figure out is whether there is any feature of
StringTemplate itself that I could leverage for doing the extraction.
I haven't seen any yet, and from all the docs and examples I've seen so
far, it seems not part of the paradigm; "document with holes in
it" doesn't map well to "tree from which you can pick off
branches and treat them as new trees".

So I'm guessing I may need some other tool and/or mix in some other
markup to do this extraction.  Which shouldn't be hard, but:

Am I missing something? 

FWIW, the other approach we are considering is what we are calling
"element labeling" - a generic name we've given to the approaches taken
by XMLC, PyMeld, and Amrita (and maybe others?).  In that approach, the
nodes are identified by ID; no other special markup goes in the
templates at all; and some view class is responsible for loading the
template and doing something with those nodes.  Very clean separation,
and again it gives us cross-platform templates.  In that approach, it
would be trivial to extract nodes and spit them out as sub-templates.
The down side is that you end up with a fair amount of rather verbose
code in your view classes. (At the same time it reduces the workload for
the HTML designers, so the decision is partly one of human resource
management.)

Would also be interested in strategies others have discovered
in similar scenarios.

-- 

Paul Winkler
http://www.slinkp.com


More information about the stringtemplate-interest mailing list