[gobject-introspection/wip/docs-3: 4/8] doctool: Use builtin namespace walker
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/wip/docs-3: 4/8] doctool: Use builtin namespace walker
- Date: Sun, 24 Feb 2013 19:28:28 +0000 (UTC)
commit 4e39be9319dd48caca02da8aff5979a0855a2992
Author: Colin Walters <walters verbum org>
Date: Sat Feb 23 11:55:56 2013 -0500
doctool: Use builtin namespace walker
Rather than hand-rolling our own. This ensures we traverse all nodes.
https://bugzilla.gnome.org/show_bug.cgi?id=694593
giscanner/docwriter.py | 53 +++++++++++--------
.../Regress.AnnotationObject.watch.page | 2 +-
2 files changed, 32 insertions(+), 23 deletions(-)
---
diff --git a/giscanner/docwriter.py b/giscanner/docwriter.py
index e962b91..7924b2d 100644
--- a/giscanner/docwriter.py
+++ b/giscanner/docwriter.py
@@ -38,10 +38,18 @@ def make_page_id(node, recursive=False):
else:
return 'index'
+ if hasattr(node, '_chain') and node._chain:
+ parent = node._chain[-1]
+ else:
+ parent = None
+
+ if parent is None:
+ return '%s.%s' % (node.namespace.name, node.name)
+
if isinstance(node, (ast.Property, ast.Signal, ast.VFunction)):
- return '%s-%s' % (make_page_id(node.parent, recursive=True), node.name)
+ return '%s-%s' % (make_page_id(parent, recursive=True), node.name)
else:
- return '%s.%s' % (make_page_id(node.parent, recursive=True), node.name)
+ return '%s.%s' % (make_page_id(parent, recursive=True), node.name)
def get_node_kind(node):
if isinstance(node, ast.Namespace):
@@ -314,7 +322,10 @@ class DocFormatter(object):
return make_page_id(node)
def format_xref(self, node, **attrdict):
- if isinstance(node, ast.Member):
+ if node is None:
+ attrs = [('xref', 'index')] + attrdict.items()
+ return xmlwriter.build_xml_tag('link', attrs)
+ elif isinstance(node, ast.Member):
# Enum/BitField members are linked to the main enum page.
return self.format_xref(node.parent, **attrdict) + '.' + node.name
else:
@@ -587,27 +598,25 @@ class DocWriter(object):
# directory already made
pass
- nodes = [self._transformer.namespace]
- for node in self._transformer.namespace.itervalues():
- if isinstance(node, ast.Function) and node.moved_to is not None:
- continue
- if getattr(node, 'disguised', False):
- continue
- nodes.append(node)
- if isinstance(node, (ast.Class, ast.Interface, ast.Record)):
- nodes += getattr(node, 'methods', [])
- nodes += getattr(node, 'static_methods', [])
- nodes += getattr(node, 'virtual_methods', [])
- nodes += getattr(node, 'properties', [])
- nodes += getattr(node, 'signals', [])
- nodes += getattr(node, 'constructors', [])
- for node in nodes:
- if self._formatter.should_render_node(node):
- self._render_node(node, output)
-
- def _render_node(self, node, output):
+ self._walk_node(output, self._transformer.namespace, [])
+ self._transformer.namespace.walk(lambda node, chain: self._walk_node(output, node, chain))
+
+ def _walk_node(self, output, node, chain):
+ if isinstance(node, ast.Function) and node.moved_to is not None:
+ return False
+ if getattr(node, 'disguised', False):
+ return False
+ if self._formatter.should_render_node(node):
+ self._render_node(node, chain, output)
+ return True
+ return False
+
+ def _render_node(self, node, chain, output):
namespace = self._transformer.namespace
+ # A bit of a hack...maybe this should be an official API
+ node._chain = list(chain)
+
page_kind = get_node_kind(node)
template_name = '%s/%s.tmpl' % (self._language, page_kind)
page_id = make_page_id(node)
diff --git a/tests/scanner/Regress-1.0-C-expected/Regress.AnnotationObject.watch.page
b/tests/scanner/Regress-1.0-C-expected/Regress.AnnotationObject.watch.page
index 0f9933d..76402aa 100644
--- a/tests/scanner/Regress-1.0-C-expected/Regress.AnnotationObject.watch.page
+++ b/tests/scanner/Regress-1.0-C-expected/Regress.AnnotationObject.watch.page
@@ -38,7 +38,7 @@ void regress_annotation_object_watch (RegressAnnotationObject* object,
<p>This is here just for the sake of being overriden by its
-<link xref="Regress.AnnotationObject.watch_full"/>.</p>
+<link xref="Regress.watch_full"/>.</p>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]