diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-07-30 10:38:27 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-07-30 10:38:27 +0200 |
commit | 7e669bcf6b6336ec429da949bcb4aa456971dba2 (patch) | |
tree | d19912f950d1cac1c38b857b7d5bdaba2289544e /doc/sphinx/_exts/httpdomain/autohttp/flaskqref.py | |
download | anastasis-7e669bcf6b6336ec429da949bcb4aa456971dba2.tar.gz anastasis-7e669bcf6b6336ec429da949bcb4aa456971dba2.tar.bz2 anastasis-7e669bcf6b6336ec429da949bcb4aa456971dba2.zip |
folding history in preparation of GNU Anastasis v0.0.0 release
Diffstat (limited to 'doc/sphinx/_exts/httpdomain/autohttp/flaskqref.py')
-rw-r--r-- | doc/sphinx/_exts/httpdomain/autohttp/flaskqref.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/doc/sphinx/_exts/httpdomain/autohttp/flaskqref.py b/doc/sphinx/_exts/httpdomain/autohttp/flaskqref.py new file mode 100644 index 0000000..c28bb15 --- /dev/null +++ b/doc/sphinx/_exts/httpdomain/autohttp/flaskqref.py @@ -0,0 +1,80 @@ +""" + sphinxcontrib.autohttp.flaskqref + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + The sphinx.ext.autodoc-style HTTP API quick reference + builder (from Flask) + for sphinxcontrib.httpdomain. + + :copyright: Copyright 2011 by Hong Minhee + :license: BSD, see LICENSE for details. + +""" + +from docutils import nodes +from docutils.statemachine import ViewList + +from sphinxcontrib import httpdomain +from sphinx.util.nodes import nested_parse_with_titles + +from .flask import AutoflaskBase + + +class QuickReferenceFlaskDirective(AutoflaskBase): + + + header = [ '', + '.. list-table::', + ' :widths: 20 45 35', + ' :header-rows: 1', + '', + ' * - Resource', + ' - Operation', + ' - Description' + ] + + def run(self): + node = nodes.section() + node.document = self.state.document + result = ViewList() + for line in QuickReferenceFlaskDirective.header: + result.append(line, '<qrefflask>') + table={} + table_sorted_names=[] + + for table_row in self.make_rst(qref=True): + name = table_row['name'] + if table.get(name) is None: + table[name]=[] + table[name].append(table_row) + if name not in table_sorted_names: + table_sorted_names.append(name) + + table_sorted_names.sort() + + for name in table_sorted_names: + # Keep table display clean by not repeating duplicate + # resource names and descriptions + display_name = name + previous_description=None + for row in table[name]: + result.append(' * - %s' % display_name, '<qrefflask>') + display_name ="" + result.append(row['operation'], '<qrefflask>') + description = row['description'] + if previous_description is not None and previous_description == description: + description ="" + else: + previous_description = description + + result.append(' - %s' % description, '<qrefflask>') + + result.append('', '<qrefflask>') + nested_parse_with_titles(self.state, result, node) + return node.children + +def setup(app): + if 'http' not in app.domains: + httpdomain.setup(app) + app.add_directive('qrefflask', QuickReferenceFlaskDirective) + |