[gobject-introspection: 12/30] devdocs: Format the values of constants



commit 26560766ce3505ef4f5b09b41f13895346133f3a
Author: Philip Chimento <philip chimento gmail com>
Date:   Mon Dec 7 01:03:56 2015 -0800

    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.

 giscanner/doctemplates/devdocs/Gjs/default.tmpl | 10 +++++++---
 giscanner/docwriter.py                          | 11 +++++++++++
 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 ''


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