The ClearSilver templating language does not have a very pleasant syntax for people familiar with the TAL notation of Zope Page Templates. That's not to say ClearSilver's syntax is awful; it's deliberately simple, and I'm sure one could get used to it pretty quickly. Still, I started wondering what ClearSilver syntax would look like if it were more like TAL. Let's call such a theoretical TAL-like ClearSilver "Clarity". Perhaps this is a bit confusing, as it's the same name as the ClearSilver integration package I talked about before, but it's a nice name. :)
The Clarity templating language could be seen as a simple frontend to ClearSilver, meaning there is a one-to-one mapping of any Clarity code to ClearSilver code.
I realized that it should be possible to implement such a frontend fairly easily by involving yet another templating language: XSLT. I could use an XSLT template to translate Clarity templates to the equivalent ClearSilver templates.
So, I started an experiment. So far it's working out fairly well, though only a very limited set of ClearSilver commands can be produced right now (just var and set). Clarity right now defines the following statements: cs:define, cs:content and cs:replace, which more or less work like the equivalents in TAL, though the define syntax and semantics are different (that of set in ClearSilver). I even added support for "structure", in that I use the ClearSilver html_quote() by default everywhere, unless "structure" is used.
Pretty neat stuff, though somewhat perverse. I could even integrate this into the Clarity Zope 3 package using lxml, so that any .cla templates will be automatically preprocessed to ClearSilver templates whenever needed...
And for the people who know him, no, this is not a secret project to drive Paul Everitt completely nuts. :)
The code can be found here:
In particular, here's an example of Clarity code: