[z3-checkins] r5390 - z3/util/trunk

faassen at codespeak.net faassen at codespeak.net
Tue Jun 29 17:37:14 MEST 2004


Author: faassen
Date: Tue Jun 29 17:37:13 2004
New Revision: 5390

Added:
   z3/util/trunk/layout.html
   z3/util/trunk/mkwebsite.py
   z3/util/trunk/publish.py
Log:
Check in start of scripts that can produce z3 web site from a variety of 
rst (and other) sources.


Added: z3/util/trunk/layout.html
==============================================================================
--- (empty file)
+++ z3/util/trunk/layout.html	Tue Jun 29 17:37:13 2004
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html 
+     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+     "DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title>{{title}}</title>
+<link rel="stylesheet" type="text/css" href="{{style}}" title="Design" />
+</head>
+<body>
+
+<div id="Header">
+  <div id="Backgroundimage">
+        <img src="five-head.png"
+        title="background-image" />
+  </div>
+  <ul>
+    <li>
+    <a href="index.html" class="home" title="Z3 Base">Z3 Base</a>
+    </li>
+    <li>
+    <a href="five.html" class="home" title="Five">Five</a>
+    </li>
+    <li>
+    <a href="modzope.html" class="home" title="Mod Zope">Mod Zope</a>
+    </li>
+    <li>
+    <a href="zopexml.html" class="home" title="Zope XML">Zope XML</a>
+    </li>
+  </ul>
+</div>
+
+<div id="Box">
+
+<div id="RightMenu">
+<h4>Quick links</h4>
+<ul>
+  <li>
+    <a href="http://codespeak.net/svn/z3/Five/">svn (the code)</a>
+  </li>
+  <li>
+    <a href="http://codespeak.net/mailman/listinfo/z3-five">z3-five mailing list</a>
+  </li>
+  <li>
+    <a href="http://codespeak.net/mailman/listinfo/z3-checkins">z3-checkins mailing list</a>
+  </li>
+</ul>
+</div>
+
+<div id="Content">
+<h1>{{title}}</h1>
+{{body}}
+</div>
+</div>
+</body>
+</html>

Added: z3/util/trunk/mkwebsite.py
==============================================================================
--- (empty file)
+++ z3/util/trunk/mkwebsite.py	Tue Jun 29 17:37:13 2004
@@ -0,0 +1,25 @@
+import publish
+website = publish.Website('/home/faassen/tmp/testwebsite')
+
+f = open('/home/faassen/working/z3/util/layout.html')
+data = f.read()
+f.close()
+five_layouter = publish.SimpleLayouter(data, style='../style.css')
+z3_layouter = publish.SimpleLayouter(data, style='style.css')
+
+website.registerPages(
+    [
+    publish.FilePage('test.txt'),
+    publish.FilePage('test2.txt'),
+    ],
+    z3_layouter,
+    '.')
+
+website.registerPages(
+    [
+    publish.UrlPage('http://codespeak.net/svn/z3/Five/trunk/doc/features.txt'),
+    ],
+    five_layouter,
+    'five')
+
+website.save()

Added: z3/util/trunk/publish.py
==============================================================================
--- (empty file)
+++ z3/util/trunk/publish.py	Tue Jun 29 17:37:13 2004
@@ -0,0 +1,123 @@
+from docutils import core
+import os, urllib2
+
+class Website:
+    def __init__(self, website_path):
+        self._website_path = website_path
+        self._page_infos = []
+
+    def registerPages(self, pages, layouter, directory):
+        for page in pages:
+            path = os.path.join(self._website_path, directory)
+            path = os.path.join(path, page.getName())
+            self._page_infos.append(PageInfo(page, layouter, path))
+            
+    def save(self):
+        for page_info in self._page_infos:
+            page_info.save()
+
+class PageInfo:
+    def __init__(self, page, layouter, destination_path):
+        self._page = page
+        self._layouter = layouter
+        self._destination_path = destination_path
+
+    def render(self):
+        return self._page.render(self._layouter)
+    
+    def save(self):
+        try:
+            os.makedirs(os.path.dirname(self._destination_path))
+        except os.error:
+            pass
+        data = self.render()
+        f = open(self._destination_path, 'w')
+        f.write(data)
+        f.close()
+        
+class RstPage:
+    def render(self, layouter):
+        return layouter.render(**self.getRstData())
+
+    def getRstData(self):
+        return html_parts(self.getRawData(), initial_header_level=2)
+
+    def render(self, layouter):
+        return layouter.render(**self.getRstData())
+
+class UrlPage(RstPage):
+    def __init__(self, url):
+        self._url = url
+
+    def getName(self):
+        i = self._url.rfind('/')
+        name = self._url[i+1:]
+        return os.path.splitext(name)[0] + '.html'
+
+    def getRawData(self):
+        f = urllib2.urlopen(self._url)
+        data = f.read()
+        f.close()
+        return data
+    
+class FilePage(RstPage):
+    def __init__(self, path):
+        self._path = path
+
+    def getName(self):
+        name = os.path.basename(self._path)
+        return os.path.splitext(name)[0] + '.html'
+
+    def getRawData(self):
+        f = open(self._path)
+        data = f.read()
+        f.close()
+        return data
+ 
+class SimpleLayouter:
+    """Simple layouter which replaces {{foo}} with values.
+    """
+    def __init__(self, layout, **kw):
+        self._layout = layout
+        self._kw = kw
+        
+    def render(self, **kw):
+        kw.update(self._kw)
+        layout = self._layout
+        for key, value in kw.items():
+            layout = layout.replace('{{%s}}' % key, value)
+        return layout
+   
+def html_parts(input_string, source_path=None, destination_path=None,
+               input_encoding='unicode', doctitle=1, initial_header_level=1):
+    """
+    Given an input string, returns a dictionary of HTML document parts.
+
+    Dictionary keys are the names of parts, and values are Unicode strings;
+    encoding is up to the client.
+
+    Parameters:
+
+    - `input_string`: A multi-line text string; required.
+    - `source_path`: Path to the source file or object.  Optional, but useful
+      for diagnostic output (system messages).
+    - `destination_path`: Path to the file or object which will receive the
+      output; optional.  Used for determining relative paths (stylesheets,
+      source links, etc.).
+    - `input_encoding`: The encoding of `input_string`.  If it is an encoded
+      8-bit string, provide the correct encoding.  If it is a Unicode string,
+      use "unicode", the default.
+    - `doctitle`: Disable the promotion of a lone top-level section title to
+      document title (and subsequent section title to document subtitle
+      promotion); enabled by default.
+    - `initial_header_level`: The initial level for header elements (e.g. 1
+      for "<h1>").
+    """
+    overrides = {'input_encoding': input_encoding,
+                 'doctitle_xform': doctitle,
+                 'initial_header_level': initial_header_level}
+    parts = core.publish_parts(
+        source=input_string, source_path=source_path,
+        destination_path=destination_path,
+        writer_name='html', settings_overrides=overrides)
+    return parts


More information about the z3-checkins mailing list