has
Posts: 15
Nickname: has
Registered: Nov, 2004
|
|
Re: In search of a Pythonic, XML-based Templating Language
|
Posted: Nov 30, 2004 1:36 PM
|
|
> Yes, I believe [Nevow] could be considered in this bunch.
Nevow's not a templating language but a collection of templating-related technologies that includes Nevow.Renderer, which compiles an HTML/XML template into an object model that can be manipulated programmatically, and Nevow.Stan, a programmatic HMTL/XML generator, along with a form builder and other cool-looking stuff. The main problem with Nevow's design, IMO, is dependencies: there's about half a dozen really interesting but very different technologies, each of which could/should really should stand on its own but instead they're all bundled up and coupled together. Not sure if it's still dependent on twisted, but if it is then I'd consider that a deal-killer too.
> I'm more interested in standalone template > languages that can be adapted for different needs (web > templating, static file generation, transformation, etc.). > I wonder how hard it would be to use just the templating > piece without the rest of the MVC framework or twisted.
I remember looking at it some time back as I'd an interest in playing around with Stan, but found it easier just to whip up a quick Stan clone than figure out how to decouple the original Stan. The situation may have improved (or maybe gotten worse) since then; I dunno.
As an alternative to Nevow.Renderer, you might try looking at my own HTMLTemplate module which uses the same simplified-DOM-style approach. (There's a couple simple examples included, and a nice meaty real-world example can be found in the htmldoc module of the appscript package also on my site.) HTMLTemplate doesn't XML templating straight out of the box, but that's mainly a limitation of Python's HTMLParser which could be replaced easily enough with another, XML-savvy, SAX parser. It's deliberately designed to be small, simple and easy to hack - e.g. I've created a improved version (unreleased; bug me if you want a copy) with a more uniform, flexible design and basic introspection support that'd allow one to implement neat stuff like automatic dict interpolation as add-on layers - so creating a powerful and flexible XML templating system out of it oughtn't to be too hard.
FWIW, I've designed and written both embedded mini-language and DOM-like templating systems, and while the former do have their niche the latter are far, far easier to implement, less rigid and constraining and much more elegant and easy to use, better suited to the majority of uses and users, and won't get you into trouble over Greenspun's Tenth Rule. If you're designing a templating engine from scratch, I really recommend you explore this approach before sinking lots of time into creating your own custom language from scratch when you could quickly and easily leverage the full Python language directly (a lesson I learned the hard way, ugh...).
HTH
|
|