[z3-checkins] r10717 - in z3/clarity/trunk: . xslt

faassen at codespeak.net faassen at codespeak.net
Sat Apr 16 00:05:13 MEST 2005


Author: faassen
Date: Sat Apr 16 00:05:13 2005
New Revision: 10717

Added:
   z3/clarity/trunk/xslt/
   z3/clarity/trunk/xslt/README.txt
   z3/clarity/trunk/xslt/clarity.xsl
   z3/clarity/trunk/xslt/example.cla
Modified:
   z3/clarity/trunk/README.txt
Log:
Add initial version of clarity.xsl XSLT template.


Modified: z3/clarity/trunk/README.txt
==============================================================================
--- z3/clarity/trunk/README.txt	(original)
+++ z3/clarity/trunk/README.txt	Sat Apr 16 00:05:13 2005
@@ -74,6 +74,11 @@
   </body>
   </p>
 
+Experimental TAL-like Clarity language
+--------------------------------------
+
+See the README.txt in the 'xslt' directory for more details.
+
 License
 -------
 

Added: z3/clarity/trunk/xslt/README.txt
==============================================================================
--- (empty file)
+++ z3/clarity/trunk/xslt/README.txt	Sat Apr 16 00:05:13 2005
@@ -0,0 +1,21 @@
+Clarity Template Language
+=========================
+
+Clarity is an experimental templating language that is a TAL-like
+expression of ClearSilver. It is intended to make ClearSilver more
+appetizing for people used to Zope Page Templates.
+
+Clarity works as a preprocessor frontend to ClearSilver. Clarity
+templates (.cla files) go in, and the equivalent ClearSilver template
+comes out.
+
+The frontend has been implemented as an XSLT stylesheet. If you have
+libxslt installed, you can run the example by typing::
+
+  xsltproc clarity.xsl example.cla
+
+You'll see the resulting ClearSilver output after translating the
+clarity template in 'example.cla'.
+
+Right now, the Clarity frontend only translates to a very limited
+subset of ClearSilver, and is only a proof of concept.

Added: z3/clarity/trunk/xslt/clarity.xsl
==============================================================================
--- (empty file)
+++ z3/clarity/trunk/xslt/clarity.xsl	Sat Apr 16 00:05:13 2005
@@ -0,0 +1,53 @@
+<xsl:stylesheet 
+    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:cs="http://namespaces.zope.org/clearsilver"
+    version="1.0" >
+  <xsl:output method="xml" /> 
+
+  <xsl:template match="/">
+    <xsl:apply-templates />
+  </xsl:template>
+
+  <xsl:template match="*[@cs:content]">
+    <xsl:copy>
+      <xsl:apply-templates select="@*" />
+    </xsl:copy>
+   </xsl:template>
+
+  <xsl:template match="*[@cs:replace]">
+    <xsl:apply-templates select="@*[namespace-uri()='http://namespaces.zope.org/clearsilver']" />
+  </xsl:template>
+  
+  <xsl:template match="@cs:define">
+    <xsl:processing-instruction name="cs">set:<xsl:value-of select="." /></xsl:processing-instruction>
+  </xsl:template>
+
+  <xsl:template match="@cs:content | @cs:replace">
+    <xsl:choose>
+      <xsl:when test="starts-with(., 'structure ')">
+	<xsl:processing-instruction name="cs">var:<xsl:value-of select="substring(., 11)" /></xsl:processing-instruction>
+      </xsl:when>
+      <xsl:otherwise>
+	<xsl:processing-instruction name="cs">var:html_escape(<xsl:value-of select="." />)</xsl:processing-instruction>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template match="@*">
+    <xsl:if test="namespace-uri() != 'http://namespaces.zope.org/clearsilver'">
+      <xsl:copy-of select="."/>
+    </xsl:if>
+  </xsl:template>
+  
+  <xsl:template match="*">
+    <xsl:copy>
+      <xsl:apply-templates select="@*"/>
+      <xsl:apply-templates />
+    </xsl:copy>
+  </xsl:template>
+  
+  <xsl:template match="comment()">
+    <xsl:comment><xsl:value-of select="."/></xsl:comment>
+  </xsl:template>
+
+</xsl:stylesheet>

Added: z3/clarity/trunk/xslt/example.cla
==============================================================================
--- (empty file)
+++ z3/clarity/trunk/xslt/example.cla	Sat Apr 16 00:05:13 2005
@@ -0,0 +1,34 @@
+<html xmlns:cs="http://namespaces.zope.org/clearsilver">
+<body>
+
+<!-- plain html -->
+<p>Hello world</p>
+
+<!-- simple cases -->
+<p cs:content="Foo.Bar">Content</p>
+<p cs:replace="Foo.Bar">Replace</p>
+
+<!-- simple cases, with attributes -->
+<p class="hey" cs:content="Foo.Bar">Content</p>
+<!-- the div should not get a class attribute! -->
+<div>
+<p class="hoi" cs:replace="Foo.Bar">Content</p>
+</div>
+
+<!-- structure -->
+<p cs:content="structure Foo.Bar">Content</p>
+<p cs:replace="structure Foo.Bar">Content</p>
+
+<!-- simple define -->
+<p cs:define="foo = 'Bar' + 'Baz'">
+<strong>Something here</strong>
+</p>
+
+<!-- define and content combination -->
+<p cs:define="foo = 'Baz'" cs:content="foo">Some content</p>
+
+<!-- define and replace combination -->
+<p cs:define="foo = 'Baz'" cs:replace="foo">Some content</p>
+
+</body>
+</html>


More information about the z3-checkins mailing list