[z3-checkins] r31301 - in z3/deliverance/branches/packaged/deliverance: . tests tests/test-data tests/test-data/themes tests/test-data/themes/simple tests/test-data/themes/spiral
ianb at codespeak.net
ianb at codespeak.net
Mon Aug 14 18:55:32 CEST 2006
Author: ianb
Date: Mon Aug 14 18:55:27 2006
New Revision: 31301
Added:
z3/deliverance/branches/packaged/deliverance/tests/test-data/themecompiler.xsl
- copied unchanged from r30823, z3/deliverance/branches/packaged/deliverance/themecompiler.xsl
z3/deliverance/branches/packaged/deliverance/tests/test-data/themes/
z3/deliverance/branches/packaged/deliverance/tests/test-data/themes/simple/
- copied from r30821, z3/deliverance/branches/packaged/themes/simple/
z3/deliverance/branches/packaged/deliverance/tests/test-data/themes/spiral/
- copied from r30821, z3/deliverance/branches/packaged/themes/spiral/
Modified:
z3/deliverance/branches/packaged/deliverance/main.py
z3/deliverance/branches/packaged/deliverance/tests/test_wsgifilter.py
z3/deliverance/branches/packaged/deliverance/wsgifilter.py
Log:
It finally works. Kinda. The lxml namespace extensions just don't seem to be applied at all. The resource finding is not recursive in any way, it reads from files on disk
Modified: z3/deliverance/branches/packaged/deliverance/main.py
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/main.py (original)
+++ z3/deliverance/branches/packaged/deliverance/main.py Mon Aug 14 18:55:27 2006
@@ -27,7 +27,7 @@
# defined via a custom Python class defined below (class LayoutElement)
root = self.tree.getroot()
layout = root.xpath("dv:layouts/dv:layout", nsmap)[0]
- self.themeprocessor = layout.processor
+ self.themeprocessor = make_processor(layout)
def publish(self, xmlstring):
@@ -44,55 +44,64 @@
class DVRuleBase(ElementBase):
def getThemeNode(self):
- """Get a node in the theme doc"""
+ return getThemeNode(self)
- # Current node is a rule, get xpath from the @theme attr
- themedoc = self.xpath("../../dv:theme", nsmap)[0][0]
- xpath = self.get("theme")
- try:
- themenode = themedoc.xpath(xpath, nsmap)[0]
- except IndexError:
- msg = "Themedoc has no node at: %s" % xpath
- print msg
- themenode = None
+def getThemeNode(el):
+ """Get a node in the theme doc"""
- return themenode
+ # Current node is a rule, get xpath from the @theme attr
+ themedoc = el.xpath("../../dv:theme", nsmap)[0][0]
+ xpath = el.get("theme")
+ try:
+ themenode = themedoc.xpath(xpath, nsmap)[0]
+ except IndexError:
+ msg = "Themedoc has no node at: %s" % xpath
+ print msg
+ themenode = None
+
+ return themenode
class LayoutElement(ElementBase):
def processor(self):
- """Make XSLT processor by changing theme based on rules"""
-
- # Apply all the rules
- for rule in self.xpath("./dv:rules/*", nsmap):
- rule.apply()
-
- # Merge applied rules into compilerdoc
- compilerroot = self.xpath("../dv:compiler/xsl:stylesheet", nsmap)[0]
- themeroot = self.xpath("dv:theme/html:html", nsmap)[0]
- target = compilerroot.xpath("xsl:template[@match='/']", nsmap)[0]
- target.append(themeroot)
-
- #print etree.tostring(compilerroot)
-
- return etree.XSLT(compilerroot)
+ return make_processor(self)
processor = property(processor)
+
+def make_processor(el):
+ """Make XSLT processor by changing theme based on rules"""
+
+ # Apply all the rules
+ for rule in el.xpath("./dv:rules/*", nsmap):
+ apply_rules(rule)
+
+ # Merge applied rules into compilerdoc
+ compilerroot = el.xpath("../dv:compiler/xsl:stylesheet", nsmap)[0]
+ themeroot = el.xpath("dv:theme/html:html", nsmap)[0]
+ target = compilerroot.xpath("xsl:template[@match='/']", nsmap)[0]
+ target.append(themeroot)
+
+ #print etree.tostring(compilerroot)
+
+ return etree.XSLT(compilerroot)
class RuleReplaceElement(DVRuleBase):
def apply(self):
- # TODO: Someething here
- themenode = self.getThemeNode()
- if themenode is None:
- return
- del(themenode[:])
- themenode.text = None
- xslvalueof = etree.SubElement(themenode,
- "{%s}value-of" % nsmap["xsl"])
- xslvalueof.set("select", self.get("content"))
+ return apply_rules(self)
+
+def apply_rules(el):
+ # TODO: Someething here
+ themenode = getThemeNode(el)
+ if themenode is None:
+ return
+ del(themenode[:])
+ themenode.text = None
+ xslvalueof = etree.SubElement(themenode,
+ "{%s}value-of" % nsmap["xsl"])
+ xslvalueof.set("select", el.get("content"))
class RuleCopyElement(DVRuleBase):
Modified: z3/deliverance/branches/packaged/deliverance/tests/test_wsgifilter.py
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/tests/test_wsgifilter.py (original)
+++ z3/deliverance/branches/packaged/deliverance/tests/test_wsgifilter.py Mon Aug 14 18:55:27 2006
@@ -16,6 +16,6 @@
def test_filter():
root = app.get('/')
- print res
+ print root
assert 0
Modified: z3/deliverance/branches/packaged/deliverance/wsgifilter.py
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/wsgifilter.py (original)
+++ z3/deliverance/branches/packaged/deliverance/wsgifilter.py Mon Aug 14 18:55:27 2006
@@ -10,14 +10,13 @@
from paste.wsgilib import intercept_output
from paste.response import header_value, replace_header
from deliverance.main import AppMap
-appmap = AppMap() # Theme is generated once at module import time
class DeliveranceMiddleware(object):
def __init__(self, app, appmap):
self.app = app
self.appmap = appmap
-
+
def __call__(self, environ, start_response):
qs = environ.get('QUERY_STRING', '')
notheme = 'notheme' in qs
@@ -31,7 +30,7 @@
# should_intercept returned False
return body
body = self.filter_body(body)
- replace_header(headers, 'content-length', len(body))
+ replace_header(headers, 'content-length', str(len(body)))
start_response(status, headers)
return [body]
@@ -40,7 +39,7 @@
return type.startswith('text/html')
def filter_body(self, body):
- return appmap.publish(body)
+ return self.appmap.publish(body)
def handler(req):
"""Basic filter applying to all mime types it is registered for"""
More information about the z3-checkins
mailing list