""" 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, '') 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, '') display_name ="" result.append(row['operation'], '') description = row['description'] if previous_description is not None and previous_description == description: description ="" else: previous_description = description result.append(' - %s' % description, '') result.append('', '') 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)