summaryrefslogtreecommitdiff
path: root/giscanner
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu.vizoso@collabora.com>2012-02-20 16:57:14 +0100
committerTomeu Vizoso <tomeu.vizoso@collabora.com>2012-02-20 16:57:14 +0100
commit5cb2864c612e06c430e81037a9ff58b30409bebe (patch)
tree791293283e6fb3ef385addc1a77e451b7019f019 /giscanner
parenteb87a304de537271ccc1d0d5406fe5ca32d29675 (diff)
downloadgobject-introspection-5cb2864c612e06c430e81037a9ff58b30409bebe.tar.gz
g-ir-doc-tool: Display the hierarchy tree for classes
Diffstat (limited to 'giscanner')
-rw-r--r--giscanner/mallard-Python-class.tmpl8
-rw-r--r--giscanner/mallardwriter.py59
2 files changed, 35 insertions, 32 deletions
diff --git a/giscanner/mallard-Python-class.tmpl b/giscanner/mallard-Python-class.tmpl
index 489a4295..62feb9ab 100644
--- a/giscanner/mallard-Python-class.tmpl
+++ b/giscanner/mallard-Python-class.tmpl
@@ -29,12 +29,16 @@ ${formatter.to_underscores(node.name).lower()} = ${namespace.name}.${node.name}(
% if node.version:
<p>Since ${node.version}</p>
% endif
- <synopsis ui:expanded="no">
+ <synopsis>
<title>Hierarchy</title>
<tree>
+% for class_ in formatter.get_class_hierarchy(node):
<item>
- <code>GObject.Object</code>
+ <code>${class_.namespace.name}.${class_.name}</code>
+% endfor
+% for class_ in formatter.get_class_hierarchy(node):
</item>
+% endfor
</tree>
</synopsis>
<links type="topic" ui:expanded="yes"
diff --git a/giscanner/mallardwriter.py b/giscanner/mallardwriter.py
index 327ccc96..87b6f55c 100644
--- a/giscanner/mallardwriter.py
+++ b/giscanner/mallardwriter.py
@@ -32,9 +32,12 @@ from mako.runtime import supports_caller
from . import ast
from .utils import to_underscores
+def _space(num):
+ return " " * num
+
class MallardFormatter(object):
- def __init__(self, namespace):
- self._namespace = namespace
+ def __init__(self, transformer):
+ self._transformer = transformer
def escape(self, text):
return saxutils.escape(text.encode('utf-8')).decode('utf-8')
@@ -66,27 +69,28 @@ class MallardFormatter(object):
link = re.split('[^a-zA-Z_:-]', rest, maxsplit=1)[0]
if link.endswith(':'):
link = link[:-1]
+ namespace = self._transformer.namespace
if '::' in link:
type_name, signal_name = link.split('::')
- if type_name in self._namespace.ctypes:
- type_ = self._namespace.get_by_ctype(type_name)
- xref = '%s.%s-%s' % (self._namespace.name, type_.name, signal_name)
- xref_name = '%s.%s::%s' % (self._namespace.name, type_.name, signal_name)
+ if type_name in namespace.ctypes:
+ type_ = namespace.get_by_ctype(type_name)
+ xref = '%s.%s-%s' % (namespace.name, type_.name, signal_name)
+ xref_name = '%s.%s::%s' % (namespace.name, type_.name, signal_name)
else:
xref = link
xref_name = link
elif ':' in link:
type_name, property_name = link.split(':')
- if type_name in self._namespace.ctypes:
- type_ = self._namespace.get_by_ctype(type_name)
- xref = '%s.%s-%s' % (self._namespace.name, type_.name, property_name)
- xref_name = '%s.%s:%s' % (self._namespace.name, type_.name, property_name)
+ if type_name in namespace.ctypes:
+ type_ = namespace.get_by_ctype(type_name)
+ xref = '%s.%s-%s' % (namespace.name, type_.name, property_name)
+ xref_name = '%s.%s:%s' % (namespace.name, type_.name, property_name)
else:
xref = link
xref_name = link
- elif link in self._namespace.ctypes:
- type_ = self._namespace.get_by_ctype(link)
- xref = '%s.%s' % (self._namespace.name, type_.name)
+ elif link in namespace.ctypes:
+ type_ = namespace.get_by_ctype(link)
+ xref = '%s.%s' % (namespace.name, type_.name)
xref_name = xref
else:
xref = link
@@ -116,6 +120,16 @@ class MallardFormatter(object):
def to_underscores(self, string):
return to_underscores(string)
+ def get_class_hierarchy(self, node):
+ parent_chain = []
+
+ while node.parent:
+ node = self._transformer.lookup_giname(str(node.parent))
+ parent_chain.append(node)
+
+ parent_chain.reverse()
+ return parent_chain
+
class MallardFormatterC(MallardFormatter):
def format_type(self, type_):
@@ -155,9 +169,9 @@ class MallardWriter(object):
self._language = language
if self._language == 'C':
- self._formatter = MallardFormatterC(self._transformer.namespace)
+ self._formatter = MallardFormatterC(self._transformer)
elif self._language == 'Python':
- self._formatter = MallardFormatterPython(self._transformer.namespace)
+ self._formatter = MallardFormatterPython(self._transformer)
else:
raise SystemExit("Unsupported language: %s" % language)
@@ -226,18 +240,3 @@ class MallardWriter(object):
fp = open(output_file_name, 'w')
fp.write(result)
fp.close()
-
- def _render_page_object_hierarchy(self, page_node):
- parent_chain = self._get_parent_chain(page_node)
- parent_chain.append(page_node)
- lines = []
-
- for level, parent in enumerate(parent_chain):
- prepend = ""
- if level > 0:
- prepend = _space((level - 1)* 6) + " +----"
- lines.append(_space(2) + prepend + self._formatter.get_class_name(parent))
-
- self._writer.disable_whitespace()
- self._writer.write_line("\n".join(lines))
- self._writer.enable_whitespace()