Enforcing Strict Model-View Separation in Template Engines
http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf
presentation slides
http://www.antlr.org/workshop/ANTLR2004/proceedings/StringTemplate.pdf
One of the cleanest apis I have come across besides the full featured,
http://www.stringtemplate.org/ is the Template Power library for php.
http://templatepower.codocad.com/manual/index.php
It supports basic operations of cloning a template block and setting
variables. Everything else is handled in client code.
When it comes to doing source code transformations on python code,
rope looks interesting
http://rope.sourceforge.net/library.html
see
rope.refactor.* and
rope.contrib.generate
Sean