[z3-checkins] r30031 - in z3/deliverance/branches/namespaced: . content themes/simple

paul at codespeak.net paul at codespeak.net
Fri Jul 14 11:10:15 CEST 2006


Author: paul
Date: Fri Jul 14 11:09:18 2006
New Revision: 30031

Added:
   z3/deliverance/branches/namespaced/mpfilter.conf
   z3/deliverance/branches/namespaced/mpfilter.py
Modified:
   z3/deliverance/branches/namespaced/README.txt
   z3/deliverance/branches/namespaced/ThemedHTTPServer.py
   z3/deliverance/branches/namespaced/content/intro.html
   z3/deliverance/branches/namespaced/deliverance.py
   z3/deliverance/branches/namespaced/themes/simple/sampletheme.xml
Log:
Switched to mod_python filter instead of handler, improved the README, removed any mentions of the previous content map stuff.

Modified: z3/deliverance/branches/namespaced/README.txt
==============================================================================
--- z3/deliverance/branches/namespaced/README.txt	(original)
+++ z3/deliverance/branches/namespaced/README.txt	Fri Jul 14 11:09:18 2006
@@ -14,15 +14,51 @@
 This runs the timeit function, showing average time to apply a simple theme.
 
 
-Quick Server Start
-------------------
+Quick mod_python Start
+----------------------
 
-1) python ./ThemedHTTPServer.py
+1) Edit mpfilter.conf and point it to where you put the SVN checkout.
 
-2) Open http://localhost:8000/content/
+2) In your Apache httpd.conf file, add a line like this::
 
-3) Click on the links in the menu, especially the "Unthemed" link that shows a 
-how content looks without a theme.
+  Include /Users/me/sandboxes/namespaced/mpfilter.conf
+
+3) Shut Apache down and restart.
+
+4) Keep an eye on the Apache error log::
+
+  tail -f logs/error_log
+
+5) Open a URL like this (or however you have your HTML files pointed to on 
+whichever port)::
+
+  http://localhost:9000/sandboxes/namespaced/
+
+6) If that works, click on the on the "content" directory or go to this URL::
+
+  http://localhost:9000/sandboxes/namespaced/content/intro.html
+
+7) In the site menu on that page, try clicking on the 3 links.
+
+
+Customization Quick Start
+-------------------------
+
+1) Edit ``themes/simple/sampletheme.xml`` and add the following snippet 
+**inside** the ``<div id="pageframe">``::
+
+  <div id="pageauthor">Theme section for author</div>
+
+2) Edit ``content/index.html`` and add the following in the ``<head>``:
+
+  <meta name="dc.creator" content="Your Name"/>
+
+3) Edit ``etc/themerules.xml`` and add a rule like the following::
+
+  <replace theme="//html:div[@id='pageauthor']" 
+      content="/html:html/html:head/html:meta[@name='dc.creator']/@content"/>
+  
+4) Restart Apache and reload the page.
 
 
 How Does This Work?
@@ -32,7 +68,7 @@
 the short version:
 
 1) A configuration "map" points at a pile of HTML artifacts that look the 
-way you'd like your site to look.  Let's call this a "theme".
+way you'd like your site to look.  Let's call this look-and-feel the "theme".
 
 2) A rule file defines boxes in that theme that should get filled by boxes 
 coming from the dynamic side.

Modified: z3/deliverance/branches/namespaced/ThemedHTTPServer.py
==============================================================================
--- z3/deliverance/branches/namespaced/ThemedHTTPServer.py	(original)
+++ z3/deliverance/branches/namespaced/ThemedHTTPServer.py	Fri Jul 14 11:09:18 2006
@@ -54,7 +54,7 @@
             # First check to see if there is a query string.  If so, presume that 
             # to mean they want the source version.
             qs = len(self.path.split("?"))
-            if ctype == "text/html" and qs == 1:
+            if ctype == "text/html" and qs == 99:
                 print "Applying theme to", path
                 xmlstring = open(path, "r").read()
                 response = appmap.publish(xmlstring)

Modified: z3/deliverance/branches/namespaced/content/intro.html
==============================================================================
--- z3/deliverance/branches/namespaced/content/intro.html	(original)
+++ z3/deliverance/branches/namespaced/content/intro.html	Fri Jul 14 11:09:18 2006
@@ -8,7 +8,7 @@
         <div class="document" id="deliverance">
             <div class="section" id="content-deliver-for-cms-systems">
                 <h1>
-                    <a name="content-deliver-for-cms-systems">Content deliver for CMS systems</a>
+                    <a name="content-deliver-for-cms-systems">Content delivery for CMS systems</a>
                 </h1>
                 <p>CMS systems, particularly in Zope, excel at the structured environment of content
                         <em>production</em>. This area places a strong emphasis on security,
@@ -24,19 +24,19 @@
                     resources. It runs in mod_python, generating branded pages and navigation
                     elements, giving high-performance throughput to anonymous visitors. Its primary
                     benefits:</p>
-                <blockquote>
-                    <p>o High performance</p>
-                    <p>o Simple re-branding</p>
-                    <p>o Trusted stack</p>
-                    <p>o Extreme productivity</p>
-                </blockquote>
+                <ul>
+                    <li>High performance</li>
+                    <li>Simple re-branding</li>
+                    <li>Trusted stack</li>
+                    <li>Extreme productivity</li>
+                </ul>
                 <p>It is focused on audiencces that want:</p>
-                <blockquote>
-                    <p>o Predictable delivery to anonymous visitors</p>
-                    <p>o Some portion of an airgap (logical/physical) between the CMS and the live
-                        site</p>
-                    <p>o Integration with mainstream systems and technologies</p>
-                </blockquote>
+                <ul>
+                    <li>Predictable delivery to anonymous visitors</li>
+                    <li>Some portion of an airgap (logical/physical) between the CMS and the live
+                        site</li>
+                    <li>Integration with mainstream systems and technologies</li>
+                </ul>
                 <p>This document discusses how the system works, then revisits the benefits in
                     detail.</p>
             </div>

Modified: z3/deliverance/branches/namespaced/deliverance.py
==============================================================================
--- z3/deliverance/branches/namespaced/deliverance.py	(original)
+++ z3/deliverance/branches/namespaced/deliverance.py	Fri Jul 14 11:09:18 2006
@@ -33,10 +33,7 @@
     def publish(self, xmlstring):
         """Given a string of XML, theme it"""
         
-        # Stage 1 and 2, get an etree for the rendered resource
         resource = etree.XML(xmlstring)
-        
-        # Stage 3, apply theme
         response = str(self.themeprocessor(resource))
 
         return response
@@ -122,7 +119,7 @@
         xslvalueof.set("select", self.get("content"))
 
 
-# lxml Namespace support
+# Bind Python classes for lxml namespace support
 namespace = Namespace(nsmap['dv'])
 namespace['layout'] = LayoutElement
 namespace['replace'] = RuleReplaceElement
@@ -130,27 +127,18 @@
 namespace['append'] = RuleAppendElement
     
 
-def testit(xmlstring):
-    
-    appmap = AppMap()
-    result = appmap.publish(xmlstring)
-    
-    return result
-
 def timeit(xmlstring):
     appmap = AppMap()
     start = time()
     iters = 50
     for i in range(iters):
         result = appmap.publish(xmlstring)
+    print "*** Average time:", (time() - start) / iters, " ***\n"
     print result[0:2000]
-    print "Average time:", (time() - start) / iters
     
 def main():
-    xmlstring = open("content/localhello.html").read()
+    xmlstring = open("content/index.html").read()
     timeit(xmlstring)
-    #testit(path1)
     
 if __name__ == "__main__":
-    result = main()
-    print result
+    main()

Added: z3/deliverance/branches/namespaced/mpfilter.conf
==============================================================================
--- (empty file)
+++ z3/deliverance/branches/namespaced/mpfilter.conf	Fri Jul 14 11:09:18 2006
@@ -0,0 +1,11 @@
+# This module can be pointed to from your main Apache 
+# configuration file to apply a theme to certain parts of your
+# URL space.
+
+LoadModule python_module modules/mod_python.so
+
+<Directory /Users/paul/sandboxes/z3/deliverance/branches/namespaced>
+  PythonOutputFilter mpfilter DELIVERANCE
+  AddOutputFilter DELIVERANCE .html
+  PythonDebug On
+</Directory>

Added: z3/deliverance/branches/namespaced/mpfilter.py
==============================================================================
--- (empty file)
+++ z3/deliverance/branches/namespaced/mpfilter.py	Fri Jul 14 11:09:18 2006
@@ -0,0 +1,50 @@
+"""
+Deliverance theming for mod_python filters
+
+Deliverance applies a theme to content.  This mod_python module acts as an 
+Apache "filter", transforming content as it passes through Apache.
+
+This module gets imported by mod_python during its startup.  Thus, the 
+appmap instance becomes a global, computed only once.  If you need to 
+recompute the theme, for example, restart the Apache.
+"""
+
+from mod_python import apache
+from deliverance import AppMap
+appmap = AppMap() # Theme is generated once at module import time
+
+def outputfilter(filter):
+    
+    # Check for a flag to not apply theme
+    args = filter.req.args
+
+    # XXX: mod_python might prefer a better approach to reading 
+    xmlstring = ''
+    s = filter.read()
+    while s:
+        xmlstring += s
+        s = filter.read()
+
+    if xmlstring:
+        if args and args.find("notheme") > -1:
+            filter.write(xmlstring)
+        else:
+            filter.write(appmap.publish(xmlstring))
+
+    if s is None:
+        filter.close()
+
+        
+def handler(req):
+    """Basic filter applying to all mime types it is registered for"""
+
+    # Get the path, strip off leading slash, and convert to a 
+    # dotted notation for xml:id compatibility
+    path_info = req.path_info[1:]
+    dotted_path = path_info.replace("/", ".")
+    
+    response = appmap.publish(dotted_path)
+    req.content_type = "text/html"
+    req.write(response)
+
+    return apache.OK

Modified: z3/deliverance/branches/namespaced/themes/simple/sampletheme.xml
==============================================================================
--- z3/deliverance/branches/namespaced/themes/simple/sampletheme.xml	(original)
+++ z3/deliverance/branches/namespaced/themes/simple/sampletheme.xml	Fri Jul 14 11:09:18 2006
@@ -4,7 +4,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
         <title>Theme Title</title>
-        <link rel="stylesheet" type="text/css" href="/themes/simple/simpletheme.css"/>
+        <link rel="stylesheet" type="text/css" href="../themes/simple/simpletheme.css"/>
     </head>
     <body>
         <div id="siteheader">
@@ -14,16 +14,15 @@
         </div>
         <div id="sitemenu">
             <ul>
-                <li><a href="/content/">Home</a> | </li>
-                <li><a href="/content/intro.html">About Deliverance</a> | </li>
-                <li><a href="/content/index.html?x=2">Unthemed Home</a></li>
+                <li><a href="index.html">Home</a> | </li>
+                <li><a href="intro.html">About Deliverance</a> | </li>
+                <li><a href="index.html?notheme=1">Unthemed Home</a></li>
             </ul>
         </div>
         <div id="pageframe">
             <h1 id="pagetitle">Theme Title</h1>
 
             <div id="pagecontent">This gets replaced because it is theme content.</div>
-
         </div>
     </body>
 </html>


More information about the z3-checkins mailing list