[gobject-introspection/wip/docs: 18/23] mallardwriter: Use xmlwriter for xrefs



commit b4ce0aec3b74adbe996ea0489d9dd5dfe91ba11d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Jan 31 19:10:11 2013 -0500

    mallardwriter: Use xmlwriter for xrefs

 giscanner/mallardwriter.py |    6 ++++--
 giscanner/xmlwriter.py     |   34 +++++++++++++++++++---------------
 2 files changed, 23 insertions(+), 17 deletions(-)
---
diff --git a/giscanner/mallardwriter.py b/giscanner/mallardwriter.py
index bb5f893..6526a4a 100644
--- a/giscanner/mallardwriter.py
+++ b/giscanner/mallardwriter.py
@@ -28,7 +28,7 @@ import tempfile
 from xml.sax import saxutils
 from mako.lookup import TemplateLookup
 
-from . import ast
+from . import ast, xmlwriter
 from .utils import to_underscores
 
 def make_page_id(node):
@@ -319,7 +319,9 @@ class MallardFormatter(object):
             # Enum/BitField members are linked to the main enum page.
             return self.format_xref(node.parent) + '.' + node.name
         else:
-            return '<link xref="%s">%s</link>' % (make_page_id(node), self.format_page_name(node))
+            return xmlwriter.build_xml_tag('link',
+                                           [('xref', make_page_id(node))],
+                                           self.format_page_name(node))
 
     def format_property_flags(self, property_, construct_only=False):
         flags = []
diff --git a/giscanner/xmlwriter.py b/giscanner/xmlwriter.py
index fb34adf..11f8485 100755
--- a/giscanner/xmlwriter.py
+++ b/giscanner/xmlwriter.py
@@ -68,6 +68,23 @@ def collect_attributes(tag_name, attributes, self_indent,
             first = False
     return attr_value
 
+def build_xml_tag(tag_name, attributes=None, data=None, self_indent=0,
+                  self_indent_char=' '):
+    if attributes is None:
+        attributes = []
+    prefix = u'<%s' % (tag_name, )
+    if data is not None:
+        if isinstance(data, str):
+            data = data.decode('UTF-8')
+        suffix = u'>%s</%s>' % (escape(data), tag_name)
+    else:
+        suffix = u'/>'
+    attrs = collect_attributes(
+        tag_name, attributes,
+        self_indent,
+        self_indent_char,
+        len(prefix) + len(suffix))
+    return prefix + attrs + suffix
 
 with LibtoolImporter(None, None):
     if 'UNINSTALLED_INTROSPECTION_SRCDIR' in os.environ:
@@ -131,21 +148,8 @@ class XMLWriter(object):
         self.write_line('<!-- %s -->' % (text, ))
 
     def write_tag(self, tag_name, attributes, data=None):
-        if attributes is None:
-            attributes = []
-        prefix = u'<%s' % (tag_name, )
-        if data is not None:
-            if isinstance(data, str):
-                data = data.decode('UTF-8')
-            suffix = u'>%s</%s>' % (escape(data), tag_name)
-        else:
-            suffix = u'/>'
-        attrs = collect_attributes(
-            tag_name, attributes,
-            self._indent,
-            self._indent_char,
-            len(prefix) + len(suffix))
-        self.write_line(prefix + attrs + suffix)
+        self.write_line(build_xml_tag(tag_name, attributes, data,
+                                      self._indent, self._indent_char))
 
     def push_tag(self, tag_name, attributes=None):
         if attributes is None:



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