[Telepathy-commits] [telepathy-spec/master] Initial work on a doc generation tool that uses Cheetah templates

Davyd Madeley davyd at madeley.id.au
Mon Mar 23 12:29:18 PDT 2009


---
 .gitignore                   |    1 +
 doc/spec/style.css           |   41 +++++++++++++++++++++++++++++++++++++++++
 doc/templates/interface.html |   38 ++++++++++++++++++++++++++++++++++++++
 tools/doc-generator.py       |   39 +++++++++++++++++++++++++++++++++++++++
 tools/specparser.py          |    5 ++++-
 5 files changed, 123 insertions(+), 1 deletions(-)
 create mode 100644 doc/spec/style.css
 create mode 100644 doc/templates/interface.html
 create mode 100755 tools/doc-generator.py

diff --git a/.gitignore b/.gitignore
index ee4339b..bbda8a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
 .*.sw?
 *.pyc
 /doc/*.html
+/doc/spec/*.html
 /doc/telepathy-spec.devhelp2
 /telepathy-spec-*.tar*
 /test/output
diff --git a/doc/spec/style.css b/doc/spec/style.css
new file mode 100644
index 0000000..e1cb00c
--- /dev/null
+++ b/doc/spec/style.css
@@ -0,0 +1,41 @@
+h1, h2 {
+	margin: 0;
+	padding: 0;
+}
+
+div.outset {
+	padding: 1ex;
+	margin-top: 1ex;
+	margin-bottom: 1ex;
+}
+
+div.inset {
+	background-color: white;
+	margin-top: 1ex;
+	margin-bottom: 1ex;
+	padding: 0.5ex;
+}
+
+#methods {
+	background-color: #fcaf3e;
+}
+
+div.method {
+	border: 1px solid #f57900;
+}
+
+#signals {
+	background-color: #729fcf;
+}
+
+div.signal {
+	border: 1px solid #3465a4;
+}
+
+#properties {
+	background-color: #ad7fa8;
+}
+
+div.property {
+	border: 1px solid #75507b;
+}
diff --git a/doc/templates/interface.html b/doc/templates/interface.html
new file mode 100644
index 0000000..e71b1cf
--- /dev/null
+++ b/doc/templates/interface.html
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" "">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+ <head>
+  <title>$interface.name</title>
+  <link rel="stylesheet" href="style.css" type="text/css"/>
+ </head>
+ <body>
+  <h1>Interface $interface.name</h1>
+
+  <div id="methods" class="outset method">
+   <h1>Methods</h1>
+   #for $method in $interface.methods.values()
+   <div id="$method.name" class="inset method">
+    <h2>$method.get_short_name()</h2>
+   </div>
+   #end for
+  </div>
+   
+  <div id="signals" class="outset signal">
+   <h1>Signals</h1>
+   #for $signal in $interface.signals.values()
+   <div id="$signal.name" class="inset signal">
+    <h2>$signal.get_short_name()</h2>
+   </div>
+   #end for
+  </div>
+   
+  <div id="properties" class="outset property">
+   <h1>Properties</h1>
+   #for $property in $interface.properties.values()
+   <div id="$property.name" class="inset property">
+    <h2>$property.get_short_name()</h2>
+   </div>
+   #end for
+  </div>
+ </body>
+</html>
diff --git a/tools/doc-generator.py b/tools/doc-generator.py
new file mode 100755
index 0000000..e938ee1
--- /dev/null
+++ b/tools/doc-generator.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+
+import sys
+import os.path
+
+try:
+    from Cheetah.Template import Template
+except ImportError, e:
+    print >> sys.stderr, e
+    print >> sys.stderr, "Install `python-cheetah'?"
+    sys.exit (-1)
+
+import specparser
+
+interfaces = specparser.parse (sys.argv[1])
+
+# load the template
+template_path = os.path.join (os.path.dirname (sys.argv[0]),
+                              '../doc/templates')
+output_path = os.path.join (os.path.dirname (sys.argv[0]),
+                              '../doc/spec')
+
+try:
+    file = open (os.path.join (template_path, 'interface.html'))
+    template_def = file.read ()
+    file.close ()
+except IOError, e:
+    print >> sys.stderr, "Could not load template file `interface.html'"
+    print >> sys.stderr, e
+    sys.exit (-1)
+
+for interface in interfaces.values ():
+    namespace = { 'interface': interface }
+    t = Template (template_def, namespaces = [namespace])
+    
+    # open the output file
+    out = open (os.path.join (output_path, '%s.html' % interface.name), 'w')
+    print >> out, t
+    out.close ()
diff --git a/tools/specparser.py b/tools/specparser.py
index ecdbe6d..11adc39 100644
--- a/tools/specparser.py
+++ b/tools/specparser.py
@@ -31,9 +31,12 @@ class base (object):
     def get_interface (self):
         return self.parent.get_interface ()
 
+    def get_short_name (self):
+        return self.name.rsplit ('.', 1)[1]
+
     def __repr__ (self):
         return '%s(%s)' % (self.__class__.__name__, self.name)
-
+    
 class Method (base):
     def __init__ (self, parent, namespace, dom):
         super (Method, self).__init__ (parent, namespace, dom)
-- 
1.5.6.5




More information about the telepathy-commits mailing list