< Clarity, ClearSilver integration for Zope 3
Five 1.0 released! >

[Comments] (3) the Clarity Template Language:

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:

http://codespeak.net/svn/z3/clarity/trunk/xslt/

In particular, here's an example of Clarity code:

http://codespeak.net/svn/z3/clarity/trunk/xslt/example.cla

Filed under: , ,

Comments:

Posted by Kevin Dangoor at Sat Apr 16 2005 04:35

Now you're talking! I had *nearly* used ClearSilver for my current project, but the syntax really drove me away. I ended up with Cheetah. I think I still prefer the Cheetah style to the ZPT/Clarity style, but I definitely prefer ZPT/Clarity to ClearSilver. That's all a matter of personal opinion though.

Cool to see someone doing this integration work!

Posted by Martijn Faassen at Sat Apr 16 2005 15:26

Unfortunately after trying to extend the system to deal with things like tal:attributes, it turns out that XSLT it too limited a language to do this transformation properly. I'll have to descend into Python, but writing a transformation in that will take more time.

It's a combination of XSLT/XPath being really annoying (XPath doesn't have a strip-whitespace, which I really need), and ClearSilver being really annoying in the way it sets attribute values in a completely XML illegal way, like this:

">

Posted by Martijn Faassen at Sat Apr 16 2005 15:29

Argh, evidently Newsbruiser is not exactly good about escaping HTML *either* in its comment handling. I meant that ClearSilver allows this (let's see whether this works):

<a href="<?cs var:Foo.Bar?>">


[Main]

Unless otherwise noted, all content licensed by Martijn Faassen
under a Creative Commons License.