[z3-checkins] r55535 - z3/deliverance/sandboxes/paul/dvng
paul at codespeak.net
paul at codespeak.net
Tue Jun 3 22:34:49 CEST 2008
Author: paul
Date: Tue Jun 3 22:34:47 2008
New Revision: 55535
Added:
z3/deliverance/sandboxes/paul/dvng/README.txt
z3/deliverance/sandboxes/paul/dvng/content1.html
z3/deliverance/sandboxes/paul/dvng/content2.html
z3/deliverance/sandboxes/paul/dvng/contentcustom.xsl
- copied, changed from r55528, z3/deliverance/sandboxes/paul/dvng/mycustomizations.xsl
z3/deliverance/sandboxes/paul/dvng/stub.xsl
z3/deliverance/sandboxes/paul/dvng/theme1.html
- copied unchanged from r55528, z3/deliverance/sandboxes/paul/dvng/theme.html
z3/deliverance/sandboxes/paul/dvng/themecustom.xsl
z3/deliverance/sandboxes/paul/dvng/themeset.rng
- copied, changed from r55528, z3/deliverance/sandboxes/paul/dvng/rules.rng
z3/deliverance/sandboxes/paul/dvng/themeset1.xml
- copied, changed from r55528, z3/deliverance/sandboxes/paul/dvng/themeset.xml
Removed:
z3/deliverance/sandboxes/paul/dvng/mycustomizations.xsl
z3/deliverance/sandboxes/paul/dvng/rules.rng
z3/deliverance/sandboxes/paul/dvng/theme.html
z3/deliverance/sandboxes/paul/dvng/themeset.xml
Modified:
z3/deliverance/sandboxes/paul/dvng/dvngcompiler.py
z3/deliverance/sandboxes/paul/dvng/theme2.html
Log:
Added a README, implemented custom rules on theme loading and content rendering.
Added: z3/deliverance/sandboxes/paul/dvng/README.txt
==============================================================================
--- (empty file)
+++ z3/deliverance/sandboxes/paul/dvng/README.txt Tue Jun 3 22:34:47 2008
@@ -0,0 +1,106 @@
+========================================
+DVNG Experimental Implementation
+========================================
+
+This directory contains the software, but not the documentation, for
+an experimental implementation of Deliverance.
+
+Usage
+=====================
+
+1) Generate a "compiledthemeset"::
+
+ python ./dvngcompiler.py themeset1.xml > var/dvfinalstage.xsl
+
+2) Apply it to some content::
+
+ xsltproc var/dvfinalstage.xsl content3.html
+
+3) Validate the "themeset" (aka rules file)::
+
+ xmllint --relaxng themeset.rng themeset1.xml
+
+Goals
+=====================
+
+- *Speed*. The current Deliverance renderers do a lot of work on each
+ request. DVNG plans to do a lot of work once, with the result being
+ usable not just between requests, but for as long as the theme and
+ rules do not change.
+
+- *Reliability*. The production renderer is much less complex.
+
+- *Debuggability*. By making each stage of the rendering introspectable
+ in a "view source" fashion, you get some of the benefits of a
+ pipeline. Namely, you know what part of the process broke down.
+
+- *Extensibility*. Custom Deliverance rules, and even full-scale
+ extensions via imported XSLT, provide ways to make specialized changes
+ to the themes, rules, or even incoming content. All without adding
+ more features to Deliverance.
+
+Design
+=====================
+
+DVNG breaks the work of Deliverance up into two very fundamentally
+different steps:
+
+1) The integrator runs semi-complicated software to produced a
+"compiled themeset".
+
+2) For the most part, this "compiled themeset" is a standalone XSLT.
+In production, it has very little custom software or implementation
+complexity, beyond its use of XSLT as an intermediate language.
+
+3) Extensibility is done either through normal XSL extensibility
+features (by pointing at a custom XSL file for higher-precedence
+template rules) or WSGI middleware.
+
+Notes
+=====================
+
+- While any-old XSLT processor will work, to take advantage of
+ grabbing stuff from non-content (e.g. the request) as match
+ conditions, you need to gather up that information and pass it along
+ as an XSL parameter.
+
+- For deployment mode, such as installing Plone and using it with
+ out-of-the-box themes, we could just point at xsltproc and fork a
+ child process, to avoid lxml issues.
+
+History
+=====================
+
+
+0.0.1 (June 3, 2008)
+--------------------------
+
+- Only the replace rule works
+
+- Pagetypes are implemented and aggregate with themes
+
+- Customization can be done via pointing at a custom xsl file for both
+ cleaning up the theme before loading, as well as complex hacks on
+ the content per-request. See the breadcrumbs example in
+ ``contentcustom.xsl``.
+
+- An RNG that validates the "contract". Also with embedded
+ documentation, so people that use nxml-mode or oXygen can get help
+ text as they do autocomplete.
+
+- Not implemented:
+
+ o Other rules
+
+ o Any concept of link rewriting
+
+ o Actually grabbing and passing in the extended match conditions
+ such as req
+
+ o No debugging, to flag when theme or content xpaths misfire
+
+ o No support for CSS selectors yet
+
+ o Switching the doctype requires some custom XSL mojo
+
+
Added: z3/deliverance/sandboxes/paul/dvng/content1.html
==============================================================================
--- (empty file)
+++ z3/deliverance/sandboxes/paul/dvng/content1.html Tue Jun 3 22:34:47 2008
@@ -0,0 +1,20 @@
+<html>
+ <head>
+ <title>Red Balloons for Neanderthals</title>
+ </head>
+ <body>
+ <ul id="related">
+ <li><a href="item1">Item One</a></li>
+ <li><a href="item2">Item Two</a></li>
+ </ul>
+ <ul id="breadcrumbs">
+ <li><a href="/">Home</a></li>
+ <li><a href="/articles">Articles</a></li>
+ <li>Red Balloons for Neanderthals</li>
+ </ul>
+ <div id="content">
+ <p>The article text <em>goes here</em>.</p>
+ <p>More content here.</p>
+ </div>
+ </body>
+</html>
Added: z3/deliverance/sandboxes/paul/dvng/content2.html
==============================================================================
--- (empty file)
+++ z3/deliverance/sandboxes/paul/dvng/content2.html Tue Jun 3 22:34:47 2008
@@ -0,0 +1,23 @@
+<html>
+ <head>
+ <title>Red Balloons for Neanderthals</title>
+ <meta name="dv.section" content="DVNG Articles"/>
+ <meta name="dcmi.author" content="Grok Smasher"/>
+ <meta name="dcmi.modified" content="2007/02/21"/>
+ </head>
+ <body>
+ <ul id="related">
+ <li><a href="item1">Item One</a></li>
+ <li><a href="item2">Item Two</a></li>
+ </ul>
+ <ul id="breadcrumbs">
+ <li><a href="/">Home</a></li>
+ <li><a href="/articles">Articles</a></li>
+ <li>Red Balloons for Neanderthals</li>
+ </ul>
+ <div id="content">
+ <p>The article text <em>goes here</em>.</p>
+ <p>More content here.</p>
+ </div>
+ </body>
+</html>
Copied: z3/deliverance/sandboxes/paul/dvng/contentcustom.xsl (from r55528, z3/deliverance/sandboxes/paul/dvng/mycustomizations.xsl)
==============================================================================
--- z3/deliverance/sandboxes/paul/dvng/mycustomizations.xsl (original)
+++ z3/deliverance/sandboxes/paul/dvng/contentcustom.xsl Tue Jun 3 22:34:47 2008
@@ -3,4 +3,13 @@
<xsl:template match="/">
<div>I overroad everything!</div>
</xsl:template>
+ <xsl:template match="ul[@id='breadcrumbs']">
+ <div id="breadcrumbs">
+ <strong>You are here: </strong>
+ <xsl:for-each select="li/a">
+ <a href="{@href}"><xsl:value-of select="."/></a>
+ <xsl:if test="position() != last()"> | </xsl:if>
+ </xsl:for-each>
+ </div>
+ </xsl:template>
</xsl:stylesheet>
Modified: z3/deliverance/sandboxes/paul/dvng/dvngcompiler.py
==============================================================================
--- z3/deliverance/sandboxes/paul/dvng/dvngcompiler.py (original)
+++ z3/deliverance/sandboxes/paul/dvng/dvngcompiler.py Tue Jun 3 22:34:47 2008
@@ -38,7 +38,7 @@
return node.tag.split("}")[1]
-class DVNG2:
+class DVNG:
# heredir is set to the directory above step01-04
moduledir = os.path.dirname(os.path.abspath(__file__))
@@ -50,6 +50,28 @@
self.themes = []
self.themeset = etree.ElementTree(file=self.themesetfn)
+ # If there are custom stylesheets for hacking the theme (on
+ # loading) or the content (per-request), load them now.
+ root = self.themeset.getroot()
+ customizers = root.xpath("dv:customizers", namespaces=NSMAP)
+ if len(customizers) > 0:
+ customthemehref = customizers[0].get("theme", None)
+ customcontenthref = customizers[0].get("content", None)
+
+ if customcontenthref is not None:
+ fn = os.path.join(self.moduledir, customcontenthref)
+ self.customcontent = etree.ElementTree(file=fn)
+ else:
+ self.customcontent = None
+
+ # Now load the theme customizer, if it is there
+ if customthemehref is not None:
+ fn = os.path.join(self.moduledir, customthemehref)
+ customizetheme = etree.ElementTree(file=fn)
+ self.customizetheme = etree.XSLT(customizetheme)
+ else:
+ self.customizetheme = None
+
# The .xsl file that serves as boilerplate for the final
stubfn = os.path.join(self.moduledir, "stub.xsl")
self.xslt = etree.ElementTree(file=stubfn).getroot()
@@ -70,6 +92,12 @@
pttid = get_tag(ptt) + "-" + str(i)
theme = Theme(ptt, pttid)
+ # If the themeset says to customize the theme HTML,
+ # do so. For example, some crazy breadcrumbs thing.
+ if self.customizetheme is not None:
+ result = self.customizetheme(theme.htmlroot)
+ theme.htmlroot = result.getroot()
+
# Find places in the theme html that need rules inserted
# and do so
theme.insertRules()
@@ -100,11 +128,9 @@
# If there is a /themeset/@custom, use it for custom rules
# that need to come in at a higher precedence. Thus,
# append them to the end.
- custom = self.themeset.getroot().get("custom", None)
- if custom is not None:
- customfn = os.path.join(self.moduledir, custom)
- customrules = etree.ElementTree(file=customfn)
- for rule in customrules.xpath("/*/*"):
+
+ if self.customcontent is not None:
+ for rule in self.customcontent.xpath("/*/*"):
self.xslt.insert(0, rule)
@@ -245,7 +271,7 @@
def main():
themesetfn = sys.argv[1]
- dvng = DVNG2(themesetfn)
+ dvng = DVNG(themesetfn)
dvng.makeThemes()
dvng.assembleStylesheet()
Deleted: /z3/deliverance/sandboxes/paul/dvng/mycustomizations.xsl
==============================================================================
--- /z3/deliverance/sandboxes/paul/dvng/mycustomizations.xsl Tue Jun 3 22:34:47 2008
+++ (empty file)
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
- <xsl:template match="/">
- <div>I overroad everything!</div>
- </xsl:template>
-</xsl:stylesheet>
Deleted: /z3/deliverance/sandboxes/paul/dvng/rules.rng
==============================================================================
--- /z3/deliverance/sandboxes/paul/dvng/rules.rng Tue Jun 3 22:34:47 2008
+++ (empty file)
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<grammar
- xmlns="http://relaxng.org/ns/structure/1.0"
- xmlns:dv="http://openplans.org/deliverance"
- xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
- datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
- <start>
- <element name="dv:themeset">
- <oneOrMore>
- <element name="dv:theme">
- <attribute name="href"/>
- <zeroOrMore>
- <element name="dv:match">
- <interleave>
- <zeroOrMore>
- <element name="dv:content"><text/></element>
- </zeroOrMore>
- <zeroOrMore>
- <element name="dv:req">
- <attribute name="key"/>
- <text/>
- </element>
- </zeroOrMore>
- </interleave>
- </element>
- </zeroOrMore>
- <element name="dv:rules">
- <interleave>
- <zeroOrMore>
- <element name="dv:replace">
- <attribute name="theme"/>
- <attribute name="content"/>
- </element>
- </zeroOrMore>
- </interleave>
- </element>
- </element>
- </oneOrMore>
- </element>
- </start>
-</grammar>
\ No newline at end of file
Added: z3/deliverance/sandboxes/paul/dvng/stub.xsl
==============================================================================
--- (empty file)
+++ z3/deliverance/sandboxes/paul/dvng/stub.xsl Tue Jun 3 22:34:47 2008
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ <xsl:template match="/">
+ <!-- This is the "entry point". All the themes and pagetypes will be
+ compiled and appended in here-->
+ </xsl:template>
+ <xsl:template match="node()|@*">
+ <xsl:copy>
+ <xsl:apply-templates select="node()|@*"/>
+ </xsl:copy>
+ </xsl:template>
+</xsl:stylesheet>
Deleted: /z3/deliverance/sandboxes/paul/dvng/theme.html
==============================================================================
--- /z3/deliverance/sandboxes/paul/dvng/theme.html Tue Jun 3 22:34:47 2008
+++ (empty file)
@@ -1,11 +0,0 @@
-<html>
- <head>
- <title>Theme Page Title</title>
- </head>
- <body>
- <h1 id="pageheading">Theme Page Heading</h1>
- <div id="pagecontent">
- <p>Some sample theme content.</p>
- </div>
- </body>
-</html>
\ No newline at end of file
Modified: z3/deliverance/sandboxes/paul/dvng/theme2.html
==============================================================================
--- z3/deliverance/sandboxes/paul/dvng/theme2.html (original)
+++ z3/deliverance/sandboxes/paul/dvng/theme2.html Tue Jun 3 22:34:47 2008
@@ -7,8 +7,10 @@
<tr>
<td width="200" bgcolor="gray" valign="top">
<h2 align="center">Navigation</h2>
+ <ul id="navmenu"/>
</td>
<td valign="top">
+ <ul id="breadcrumbs"/>
<h1 id="pageheading">Theme Page Heading</h1>
<div id="pagecontent">Theme content to replace.</div>
</td>
Added: z3/deliverance/sandboxes/paul/dvng/themecustom.xsl
==============================================================================
--- (empty file)
+++ z3/deliverance/sandboxes/paul/dvng/themecustom.xsl Tue Jun 3 22:34:47 2008
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ <xsl:template match="node()|@*">
+ <xsl:copy>
+ <xsl:apply-templates select="node()|@*"/>
+ </xsl:copy>
+ </xsl:template>
+</xsl:stylesheet>
Copied: z3/deliverance/sandboxes/paul/dvng/themeset.rng (from r55528, z3/deliverance/sandboxes/paul/dvng/rules.rng)
==============================================================================
--- z3/deliverance/sandboxes/paul/dvng/rules.rng (original)
+++ z3/deliverance/sandboxes/paul/dvng/themeset.rng Tue Jun 3 22:34:47 2008
@@ -1,41 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
-<grammar
- xmlns="http://relaxng.org/ns/structure/1.0"
- xmlns:dv="http://openplans.org/deliverance"
- xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
- datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+<grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:dv="http://openplans.org/deliverance"
+ xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
+ datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<element name="dv:themeset">
+ <a:documentation>Declare one or more theme definitions along with optional loading of
+ custom XSL stylesheets.</a:documentation>
+ <optional>
+ <element name="dv:customizers">
+ <a:documentation>(Optional) Point at an XSLT that modifies the theme (on
+ loading) or the content (on each request.)</a:documentation>
+ <optional>
+ <attribute name="theme">
+ <a:documentation>Path to an XSL file that will modify the theme before
+ Deliverance compiles it.</a:documentation>
+ <data type="anyURI"/>
+ </attribute>
+ <attribute name="content">
+ <a:documentation>Path to an XSL file whose rules will get added, at a
+ higher precedence, to the compiled themeset.</a:documentation>
+ <data type="anyURI"/>
+ </attribute>
+ </optional>
+ </element>
+ </optional>
<oneOrMore>
<element name="dv:theme">
<attribute name="href"/>
- <zeroOrMore>
- <element name="dv:match">
- <interleave>
- <zeroOrMore>
- <element name="dv:content"><text/></element>
- </zeroOrMore>
- <zeroOrMore>
- <element name="dv:req">
- <attribute name="key"/>
- <text/>
- </element>
- </zeroOrMore>
- </interleave>
- </element>
- </zeroOrMore>
- <element name="dv:rules">
- <interleave>
- <zeroOrMore>
- <element name="dv:replace">
- <attribute name="theme"/>
- <attribute name="content"/>
- </element>
- </zeroOrMore>
- </interleave>
- </element>
+ <interleave>
+ <zeroOrMore>
+ <ref name="match.element"/>
+ </zeroOrMore>
+ <zeroOrMore>
+ <element name="dv:pagetype">
+ <a:documentation>Additional rules that get applied to certain
+ content under extra match conditions.</a:documentation>
+ <ref name="match.element"/>
+ <ref name="rules.element"/>
+ </element>
+ </zeroOrMore>
+ <ref name="rules.element"/>
+ </interleave>
</element>
</oneOrMore>
</element>
</start>
-</grammar>
\ No newline at end of file
+ <define name="rules.element">
+ <element name="dv:rules">
+ <interleave>
+ <zeroOrMore>
+ <element name="dv:replace">
+ <attribute name="theme"/>
+ <attribute name="content"/>
+ </element>
+ </zeroOrMore>
+ </interleave>
+ </element>
+ </define>
+ <define name="match.element">
+ <element name="dv:match">
+ <a:documentation>Conditions under which this theme or pagetype will get triggered.
+ Multiple conditions are OR'd together.</a:documentation>
+ <interleave>
+ <zeroOrMore>
+ <element name="dv:content">
+ <text/>
+ </element>
+ </zeroOrMore>
+ <zeroOrMore>
+ <element name="dv:req">
+ <attribute name="key"/>
+ <text/>
+ </element>
+ </zeroOrMore>
+ </interleave>
+ </element>
+ </define>
+</grammar>
Deleted: /z3/deliverance/sandboxes/paul/dvng/themeset.xml
==============================================================================
--- /z3/deliverance/sandboxes/paul/dvng/themeset.xml Tue Jun 3 22:34:47 2008
+++ (empty file)
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<themeset xmlns="http://openplans.org/deliverance" custom="mycustomizations.xsl">
- <theme href="theme2.html">
- <pagetype>
- <match>
- <content>/html</content>
- </match>
- <rules>
- <replace theme="//td/h1[@id='pageheading']" content="/html/head/title"/>
- <replace theme="//div[@id='pagecontent']" content="/html/body/div[@id='content']"/>
- </rules>
- </pagetype>
- <match>
- <!-- These are OR'd together -->
- <content>/html/head/meta[@name='dv.section']</content>
- <req key="domain_url">look-at-me.com</req>
- </match>
- <rules>
- <replace theme="//td/h1[@id='pageheading']" content="/html/head/title"/>
- </rules>
- </theme>
- <theme href="theme.html">
- <rules>
- <replace theme="//div[@id='pagecontent']" content="/html/body/div[@id='content']"/>
- </rules>
- </theme>
-</themeset>
Copied: z3/deliverance/sandboxes/paul/dvng/themeset1.xml (from r55528, z3/deliverance/sandboxes/paul/dvng/themeset.xml)
==============================================================================
--- z3/deliverance/sandboxes/paul/dvng/themeset.xml (original)
+++ z3/deliverance/sandboxes/paul/dvng/themeset1.xml Tue Jun 3 22:34:47 2008
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
-<themeset xmlns="http://openplans.org/deliverance" custom="mycustomizations.xsl">
+<?oxygen RNGSchema="themeset.rng" type="xml"?>
+<themeset xmlns="http://openplans.org/deliverance">
+ <customizers theme="themecustom.xsl" content="contentcustom.xsl"/>
<theme href="theme2.html">
+ <!-- A pretty theme with a sidebar -->
<pagetype>
<match>
<content>/html</content>
@@ -8,6 +11,8 @@
<rules>
<replace theme="//td/h1[@id='pageheading']" content="/html/head/title"/>
<replace theme="//div[@id='pagecontent']" content="/html/body/div[@id='content']"/>
+ <replace theme="//ul[@id='navmenu']" content="/html/body/ul[@id='related']"/>
+ <replace theme="//ul[@id='breadcrumbs']" content="/html/body/ul[@id='breadcrumbs']"/>
</rules>
</pagetype>
<match>
@@ -19,7 +24,7 @@
<replace theme="//td/h1[@id='pageheading']" content="/html/head/title"/>
</rules>
</theme>
- <theme href="theme.html">
+ <theme href="theme1.html">
<rules>
<replace theme="//div[@id='pagecontent']" content="/html/body/div[@id='content']"/>
</rules>
More information about the z3-checkins
mailing list