[gobject-introspection] docwriter: improve xrefs



commit 66350483492ed921c8a1c7b6fcd4efcbb0b8c19d
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Tue Feb 25 19:00:02 2014 +0100

    docwriter: improve xrefs
    
    If a xref points to a node that was not visited, because it
    was not introspectable, don't assume it has no parent. Instead,
    try to fetch the parent from the node directly.
    This is still wrong (the xref points nowhere because no page is
    generated), but it looks less wrong.
    If OTOH a xref points to a different namespace, generate the
    link directly, because yelp-build is not capable of translating
    it.

 giscanner/docwriter.py |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/giscanner/docwriter.py b/giscanner/docwriter.py
index ec998f5..4e99477 100644
--- a/giscanner/docwriter.py
+++ b/giscanner/docwriter.py
@@ -42,7 +42,7 @@ def make_page_id(node, recursive=False):
     if hasattr(node, '_chain') and node._chain:
         parent = node._chain[-1]
     else:
-        parent = None
+        parent = getattr(node, 'parent', None)
 
     if parent is None:
         if isinstance(node, ast.Function) and node.shadows:
@@ -348,15 +348,27 @@ class DocFormatter(object):
             return make_page_id(node)
 
     def format_xref(self, node, **attrdict):
-        if node is None:
+        if node is None or not hasattr(node, 'namespace'):
             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
+        elif node.namespace is self._transformer.namespace:
+            return self.format_internal_xref(node, attrdict)
         else:
-            attrs = [('xref', make_page_id(node))] + attrdict.items()
-            return xmlwriter.build_xml_tag('link', attrs)
+            return self.format_external_xref(node, attrdict)
+
+    def format_internal_xref(self, node, attrdict):
+        attrs = [('xref', make_page_id(node))] + attrdict.items()
+        return xmlwriter.build_xml_tag('link', attrs)
+
+    def format_external_xref(self, node, attrdict):
+        ns = node.namespace
+        attrs = [('href', '../%s-%s/%s.html' % (ns.name, str(ns.version),
+                                                make_page_id(node)))]
+        attrs += attrdict.items()
+        return xmlwriter.build_xml_tag('link', attrs, self.format_page_name(node))
 
     def field_is_writable(self, field):
         return True
@@ -701,9 +713,7 @@ class DocFormatterGjs(DocFormatterIntrospectableBase):
                 else:
                     resolved = self._transformer.lookup_typenode(type_)
                     if resolved:
-                        ns = resolved.namespace
-                        return '<link href="../%s-%s/%s.page">%s</link>' % \
-                            (ns.name, str(ns.version), giname, giname)
+                        return self.format_xref(resolved)
             return giname
         else:
             return self.format_fundamental_type(type_.target_fundamental)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]