diff options
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/doctemplates/C/constant.tmpl | 5 | ||||
-rw-r--r-- | giscanner/doctemplates/Gjs/constant.tmpl | 5 | ||||
-rw-r--r-- | giscanner/doctemplates/Python/constant.tmpl | 5 | ||||
-rw-r--r-- | giscanner/doctemplates/namespace.tmpl | 8 | ||||
-rw-r--r-- | giscanner/docwriter.py | 58 |
5 files changed, 81 insertions, 0 deletions
diff --git a/giscanner/doctemplates/C/constant.tmpl b/giscanner/doctemplates/C/constant.tmpl new file mode 100644 index 00000000..2401cee4 --- /dev/null +++ b/giscanner/doctemplates/C/constant.tmpl @@ -0,0 +1,5 @@ +<%page args="constant"/> +<item> + <title><code>#define ${constant.ctype} ${formatter.format_value(constant.value)}</code></title> + ${formatter.format(constant, constant.doc)} +</item> diff --git a/giscanner/doctemplates/Gjs/constant.tmpl b/giscanner/doctemplates/Gjs/constant.tmpl new file mode 100644 index 00000000..bada58c3 --- /dev/null +++ b/giscanner/doctemplates/Gjs/constant.tmpl @@ -0,0 +1,5 @@ +<%page args="constant"/> +<item> + <title><code>${constant.parent.name}.${constant.name} = ${formatter.format_value(constant.value)};</code></title> + ${formatter.format(constant, constant.doc)} +</item> diff --git a/giscanner/doctemplates/Python/constant.tmpl b/giscanner/doctemplates/Python/constant.tmpl new file mode 100644 index 00000000..96e55399 --- /dev/null +++ b/giscanner/doctemplates/Python/constant.tmpl @@ -0,0 +1,5 @@ +<%page args="constant"/> +<item> + <title><code>${constant.parent.name}.${constant.name} = ${formatter.format_value(constant.value)}</code></title> + ${formatter.format(constant, constant.doc)} +</item> diff --git a/giscanner/doctemplates/namespace.tmpl b/giscanner/doctemplates/namespace.tmpl index bb58bb16..2c27ee42 100644 --- a/giscanner/doctemplates/namespace.tmpl +++ b/giscanner/doctemplates/namespace.tmpl @@ -15,5 +15,13 @@ <title>Other</title> </links> </%block> +<%block name="details"> +<terms> +% for constant in formatter.collect('constant'): +<%include file="${language}/constant.tmpl" args="constant=constant"/> +% endfor +</terms> +</%block> + <%block name="since_version"> </%block> diff --git a/giscanner/docwriter.py b/giscanner/docwriter.py index e129dc0b..702a469e 100644 --- a/giscanner/docwriter.py +++ b/giscanner/docwriter.py @@ -21,6 +21,8 @@ # 02110-1301, USA. # +import itertools +import json import os import re import tempfile @@ -178,6 +180,13 @@ class DocFormatter(object): return True + def collect(self, type_name): + namespace = self._transformer.namespace + type_ = {'constant': ast.Constant}[type_name] + for item in namespace.itervalues(): + if isinstance(item, type_): + yield item + def format(self, node, doc): if doc is None: return '' @@ -309,6 +318,9 @@ class DocFormatter(object): else: return parameter.argname + def format_value(self, value): + raise NotImplementedError + def format_function_name(self, func): raise NotImplementedError @@ -377,6 +389,45 @@ class DocFormatterC(DocFormatter): "NULL": "NULL", } + def _c_escape_dictionary(): + escapes = { + '\\': '\\\\', + '"': '\\"', + '\b': '\\b', + '\f': '\\f', + '\n': '\\n', + '\r': '\\r', + '\t': '\\t', + } + for i in itertools.chain(xrange(0, 0x20), xrange(0x80, 0x100)): + escapes[chr(i)] = '\\x%x' % (i, ) + return escapes + + def format_value(self, value, escapes=_c_escape_dictionary()): + def format_bytes(v): + return '"' + ''.join(escapes.get(c, c) for c in v) + '"' + + def format_unicode(v): + # Assume UTF8 encoding + return format_bytes(v.encode('utf8')) + + def format_integer(v): + return "%d" % (v, ) + + def format_float(v): + return "%g" % (v, ) + + if isinstance(value, str): + return format_bytes(value) + if isinstance(value, unicode): + return format_unicode(value) + elif isinstance(value, (int, long)): + return format_integer(value) + elif isinstance(value, float): + return format_float(value) + else: + raise NotImplementedError(type(value)) + def format_type(self, type_): if isinstance(type_, ast.Array): return self.format_type(type_.element_type) + '*' @@ -434,6 +485,9 @@ class DocFormatterPython(DocFormatterIntrospectableBase): return False + def format_value(self, value): + return "%r" % (value, ) + def format_parameter_name(self, node, parameter): # Force "self" for the first parameter of a method if self.is_method(node) and parameter is node.instance_parameter: @@ -506,6 +560,9 @@ class DocFormatterGjs(DocFormatterIntrospectableBase): return False + def format_value(self, value): + return json.dumps(value) + def format_fundamental_type(self, name): fundamental_types = { "utf8": "String", @@ -637,6 +694,7 @@ class DocWriter(object): template = self._lookup.get_template(template_name) result = template.render(namespace=namespace, + language=self._language, node=node, page_id=page_id, page_kind=page_kind, |