summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavyd Madeley <davyd@madeley.id.au>2009-02-14 15:46:48 +0900
committerDavyd Madeley <davyd@madeley.id.au>2009-02-14 15:46:48 +0900
commit9fa3f910459d392fb68ee2cc6761d41166702925 (patch)
tree1a2a22f17096405444d9526b5389d0d2cf1050a7
parentc92e9886be63e63a469e1031708c3fe7095bd4bc (diff)
Initial work on a doc generation tool that uses Cheetah templates
-rw-r--r--.gitignore1
-rw-r--r--doc/spec/style.css41
-rw-r--r--doc/templates/interface.html38
-rwxr-xr-xtools/doc-generator.py39
-rw-r--r--tools/specparser.py5
5 files changed, 123 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index ee4339be..bbda8a7d 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 00000000..e1cb00cb
--- /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 00000000..e71b1cf4
--- /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 00000000..e938ee18
--- /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 ecdbe6db..11adc391 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)