Wrap attributes for lines which are wider than 79 characters
authorJohan Dahlin <johan@gnome.org>
Mon, 28 Apr 2008 00:15:16 +0000 (00:15 +0000)
committerJohan Dahlin <johan@src.gnome.org>
Mon, 28 Apr 2008 00:15:16 +0000 (00:15 +0000)
2008-04-27  Johan Dahlin  <johan@gnome.org>

* giscanner/xmlwriter.py:
Wrap attributes for lines which are wider than 79 characters

svn path=/trunk/; revision=235

ChangeLog
giscanner/xmlwriter.py

index 9ba9ac0..c53ec13 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2008-04-27  Johan Dahlin  <johan@gnome.org>
 
+       * giscanner/xmlwriter.py:
+       Wrap attributes for lines which are wider than 79 characters
+
        * giscanner/scannerlexer.l:
        Allow parenthesis in annotations
 
index ccb75c6..c80c90d 100644 (file)
@@ -40,8 +40,25 @@ class XMLWriter(object):
 
         return attr_value
 
+    def _collect_attributes_wrapped(self, tag_name, attributes):
+        assert attributes
+        attr_value = ''
+        indent_len = 0
+        for attr, value in attributes:
+            if indent_len:
+                attr_value += '\n%s' % (' ' * indent_len)
+            assert value is not None, attr
+            attr_value += ' %s=%s' % (attr, quoteattr(value))
+            if not indent_len:
+                indent_len = (self._indent +
+                              len(tag_name) + 1)
+
+        return attr_value
+
     def _open_tag(self, tag_name, attributes=None):
         attrs = self._collect_attributes(attributes)
+        if (len(attrs) + len(tag_name) + 2) > 79:
+            attrs = self._collect_attributes_wrapped(tag_name, attributes)
         self.write_line('<%s%s>' % (tag_name, attrs))
 
     def _close_tag(self, tag_name):