summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2015-12-07 01:03:56 -0800
committerrockon999 <rockon999@users.noreply.github.com>2018-08-06 02:53:45 -0500
commit26560766ce3505ef4f5b09b41f13895346133f3a (patch)
tree8b07da06da010f064cf7f570a5c0d5a3dbd34736
parentdbcc0f8af23ccd385a1edd888034e79c47908520 (diff)
downloadgobject-introspection-26560766ce3505ef4f5b09b41f13895346133f3a.tar.gz
devdocs: Format the values of constants
We change the style of documentation pages for constants, so that their values are displayed in a <dt>/<dd> pair. We add a new method to the formatter family, format_value() which should print the representation of a constant's value in the target language; much like repr() in Python.
-rw-r--r--giscanner/doctemplates/devdocs/Gjs/default.tmpl10
-rw-r--r--giscanner/docwriter.py11
2 files changed, 18 insertions, 3 deletions
diff --git a/giscanner/doctemplates/devdocs/Gjs/default.tmpl b/giscanner/doctemplates/devdocs/Gjs/default.tmpl
index 5130fadc..0c0fdf6c 100644
--- a/giscanner/doctemplates/devdocs/Gjs/default.tmpl
+++ b/giscanner/doctemplates/devdocs/Gjs/default.tmpl
@@ -1,6 +1,10 @@
<%inherit file="base.tmpl"/>
% if isinstance(node, ast.Constant):
- <code>
- const ${formatter.format_page_name(node)} = ${node.value};
- </code>
+ <dl>
+ <dt>Value</dt>
+ <dd>
+ <code data-mime="application/javascript"><!--
+ -->${formatter.format_value(node)}</code>
+ </dd>
+ </dl>
% endif
diff --git a/giscanner/docwriter.py b/giscanner/docwriter.py
index 35ba6f1c..a0052d87 100644
--- a/giscanner/docwriter.py
+++ b/giscanner/docwriter.py
@@ -418,6 +418,9 @@ class DocFormatter(object):
def format_type(self, type_, link=False):
raise NotImplementedError
+ def format_value(self, node):
+ raise NotImplementedError
+
def format_page_name(self, node):
if isinstance(node, ast.Namespace):
return node.name
@@ -1091,6 +1094,14 @@ class DevDocsFormatterGjs(DocFormatterGjs):
return "GLib.Variant"
return name
+ def format_value(self, node):
+ # Constants only have fundamental types?
+ type_ = node.value_type.target_fundamental
+ if type_ in ["utf8", "gunichar", "filename"]:
+ return repr(node.value)
+ # escapes quotes in the string; ought to be the same in Javascript
+ return node.value
+
def format(self, node, doc):
if doc is None:
return ''