[telepathy-spec/master] Support tp:chapter in the parser
Davyd Madeley
davyd at madeley.id.au
Thu Mar 26 02:24:17 PDT 2009
---
doc/templates/index.html | 40 ++++++++++++++++++++++++----------------
doc/templates/style.css | 4 ++++
tools/doc-generator.py | 3 ++-
tools/specparser.py | 34 ++++++++++++++++++++++++++++++++++
4 files changed, 64 insertions(+), 17 deletions(-)
diff --git a/doc/templates/index.html b/doc/templates/index.html
index ed358f6..4679ae4 100644
--- a/doc/templates/index.html
+++ b/doc/templates/index.html
@@ -2,12 +2,12 @@
<!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>$title &mdash v$version</title>
+ <title>$spec.title &mdash v$spec.version</title>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<div class="header">
- <h1>$title</h1>
+ <h1>$spec.title</h1>
<a href="#interfaces">Interfaces</a>
| <a href="generic-types.html">Generic Types</a>
| <a href="errors.html">Errors</a>
@@ -15,30 +15,38 @@
</div>
<div class="main">
- <h3 class="version">Version $version</h3>
+ <h3 class="version">Version $spec.version</h3>
<p class="copyrights">
- #echo '<br/>'.join($copyrights)
+ #echo '<br/>'.join($spec.copyrights)
</p>
- $license
+ $spec.license
<a name="interfaces"></a>
<h3>Interfaces</h3>
<ul>
- #for $interface in $interfaces
- #if $interface.causes_havoc
- <li class="causes-havoc">
- #elif $interface.deprecated
- <li class="deprecated">
- #else
- <li>
+ #for ($chapter, $interfaces) in $spec.group_by_chapters()
+ #if $chapter is not None
+ <li class="chapter">$chapter.short_name</li>
+ $chapter.get_docstring()
+ <ul>
#end if
- <a href="$interface.get_url()">$interface.name</a>
+ #for $interface in $interfaces
#if $interface.causes_havoc
- (unstable)
+ <li class="causes-havoc">
#elif $interface.deprecated
- (deprecated)
+ <li class="deprecated">
+ #else
+ <li>
#end if
- </li>
+ <a href="$interface.get_url()">$interface.name</a>
+ #if $interface.causes_havoc
+ (unstable)
+ #elif $interface.deprecated
+ (deprecated)
+ #end if
+ </li>
+ #end for
+ #if $chapter: </ul>
#end for
</ul>
diff --git a/doc/templates/style.css b/doc/templates/style.css
index a6b2646..7d205be 100644
--- a/doc/templates/style.css
+++ b/doc/templates/style.css
@@ -138,6 +138,10 @@ table.summary td {
padding-right: 1ex;
}
+li.chapter {
+ margin-top: 1ex;
+}
+
li.causes-havoc {
font-style: italic;
}
diff --git a/tools/doc-generator.py b/tools/doc-generator.py
index 69c0cf5..c4ed5c0 100755
--- a/tools/doc-generator.py
+++ b/tools/doc-generator.py
@@ -75,8 +75,9 @@ for interface in spec.interfaces:
out.close()
# write out a TOC
+namespace = { 'spec': spec }
template_def = load_template('index.html')
-t = Template(template_def, namespaces=[spec])
+t = Template(template_def, namespaces=namespace)
out = open(os.path.join(output_path, 'index.html'), 'w')
print >> out, unicode(t).encode('utf-8')
out.close()
diff --git a/tools/specparser.py b/tools/specparser.py
index 1795328..0caab84 100644
--- a/tools/specparser.py
+++ b/tools/specparser.py
@@ -24,6 +24,7 @@
import sys
import xml.dom.minidom
+from itertools import groupby
import xincludator
@@ -216,6 +217,10 @@ class Base(object):
def __repr__(self):
return '%s(%s)' % (self.__class__.__name__, self.name)
+class Chapter(Base):
+ def get_root_namespace(self):
+ return None
+
class PossibleError(Base):
def __init__(self, parent, namespace, dom):
super(PossibleError, self).__init__(parent, namespace, dom)
@@ -391,6 +396,19 @@ class External(object):
def __repr__(self):
return '%s(%s)' % (self.__class__.__name__, self.name)
+def get_chapter_node (dom):
+ """Walk up the DOM tree until we hit either tp:chapter (at which point
+ we return the chapter node) or tp:spec (at which point we return None).
+ """
+
+ if dom.parentNode.namespaceURI == XMLNS_TP:
+ if dom.parentNode.localName == 'chapter':
+ return dom.parentNode
+ elif dom.parentNode.localName == 'spec':
+ return None
+
+ return get_chapter_node(dom.parentNode)
+
class Interface(Base):
def __init__(self, parent, namespace, dom):
super(Interface, self).__init__(parent, namespace, dom)
@@ -419,6 +437,9 @@ class Interface(Base):
self.requires = map(lambda n: n.getAttribute('interface'),
getChildrenByName(dom, XMLNS_TP, 'requires'))
+ # find out if this interface is part of a chapter
+ self.chapter = get_chapter_node(dom)
+
def get_interface(self):
return self
@@ -697,6 +718,19 @@ class Spec(object):
def get_spec(self):
return self
+ def group_by_chapters(self):
+ """Group consecutive interfaces that are part of the same chapter.
+ """
+ spec = self.get_spec()
+
+ def chapter(dom):
+ # ignore None elements
+ if dom is not None: return Chapter(spec, None, dom)
+ else: return None
+
+ return [ (chapter(c), list(i))
+ for (c, i) in groupby(self.interfaces, key=lambda i: i.chapter) ]
+
def lookup(self, name, namespace=None):
key = build_name(namespace, name)
return self.everything[key]
--
1.5.6.5
More information about the telepathy-commits
mailing list