[gobject-introspection: 3/30] docwriter: Add support for plural type references.
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection: 3/30] docwriter: Add support for plural type references.
- Date: Tue, 14 Aug 2018 07:04:15 +0000 (UTC)
commit c66bc4042cc72e7b65b4126e44bff5f174b054b8
Author: Mathieu Duponchelle <mathieu duponchelle opencreed com>
Date: Tue Mar 10 15:58:19 2015 +0100
docwriter: Add support for plural type references.
giscanner/docwriter.py | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
---
diff --git a/giscanner/docwriter.py b/giscanner/docwriter.py
index a59cc7f2..7f8c5485 100644
--- a/giscanner/docwriter.py
+++ b/giscanner/docwriter.py
@@ -266,11 +266,17 @@ class DocFormatter(object):
return self.format_xref(signal)
def _process_type_name(self, node, match, props):
- type_ = self._resolve_type(props['type_name'])
+ ident = props['type_name']
+ type_ = self._resolve_type(ident)
+ plural = False
if type_ is None:
- return match
+ singularized = ident.rstrip("s") # Try to remove plural
+ type_ = self._resolve_type(singularized)
+ plural = True
+ if type_ is None:
+ return match
- return self.format_xref(type_)
+ return self.format_xref(type_, pluralize=plural)
def _process_enum_value(self, node, match, props):
member_name = props['member_name']
@@ -352,28 +358,36 @@ class DocFormatter(object):
else:
return make_page_id(node)
- def format_xref(self, node, **attrdict):
+ def format_xref(self, node, pluralize=False, **attrdict):
if node is None or not hasattr(node, 'namespace'):
attrs = [('xref', 'index')] + list(sorted(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
+ return self.format_xref(node.parent, pluralize=pluralize, **attrdict) + '.' + node.name
elif node.namespace is self._transformer.namespace:
- return self.format_internal_xref(node, attrdict)
+ return self.format_internal_xref(node, attrdict, pluralize=pluralize)
else:
- return self.format_external_xref(node, attrdict)
+ return self.format_external_xref(node, attrdict, pluralize=pluralize)
- def format_internal_xref(self, node, attrdict):
+ def format_internal_xref(self, node, attrdict, pluralize=False):
attrs = [('xref', make_page_id(node))] + list(sorted(attrdict.items()))
- return xmlwriter.build_xml_tag('link', attrs)
+ if not pluralize:
+ return xmlwriter.build_xml_tag('link', attrs)
+ else:
+ return xmlwriter.build_xml_tag('link', attrs, make_page_id(node) +
+ "s")
- def format_external_xref(self, node, attrdict):
+ def format_external_xref(self, node, attrdict, pluralize=False):
ns = node.namespace
attrs = [('href', '../%s-%s/%s.html' % (ns.name, str(ns.version),
make_page_id(node)))]
attrs += list(sorted(attrdict.items()))
- return xmlwriter.build_xml_tag('link', attrs, self.format_page_name(node))
+ if not pluralize:
+ return xmlwriter.build_xml_tag('link', attrs, self.format_page_name(node))
+ else:
+ return xmlwriter.build_xml_tag('link', attrs,
+ self.format_page_name(node) + "s")
def field_is_writable(self, field):
return True
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]