Skip to content

Commit 8fa19c3

Browse files
authored
Merge pull request #9 from numberly/feature/autoqref
Implement autoquickref option
2 parents ead3f9f + 437a9ea commit 8fa19c3

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

doc/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Version 1.6.2
88

99
To be released.
1010

11+
- Implement ``:autoquickref:`` option that use available informations to
12+
build a ``quickref``. [:pull:`9` by Alexandre Bonnetain]
13+
1114

1215
Version 1.6.1
1316
`````````````

sphinxcontrib/autohttp/flask_base.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,20 @@ def get_routes(app, endpoint=None, order=None):
6666
yield method, paths, endpoint
6767

6868

69+
def get_blueprint(app, view_func):
70+
for name, func in app.view_functions.items():
71+
if view_func is func:
72+
return name.split('.')[0]
73+
74+
6975
def cleanup_methods(methods):
7076
autoadded_methods = frozenset(['OPTIONS', 'HEAD'])
7177
if methods <= autoadded_methods:
7278
return methods
7379
return methods.difference(autoadded_methods)
7480

7581

76-
def quickref_directive(method, path, content):
82+
def quickref_directive(method, path, content, blueprint=None, auto=False):
7783
rcomp = re.compile("^\s*.. :quickref:\s*(?P<quick>.*)$")
7884
method = method.lower().strip()
7985
if isinstance(content, six.string_types):
@@ -94,6 +100,12 @@ def quickref_directive(method, path, content):
94100
description = quickref
95101
break
96102

103+
if auto:
104+
if not description and content:
105+
description = content[0]
106+
if not name and blueprint:
107+
name = blueprint
108+
97109
row = {}
98110
row['name'] = name
99111
row['operation'] = ' - `%s %s <#%s-%s>`_' % (
@@ -115,7 +127,8 @@ class AutoflaskBase(Directive):
115127
'undoc-blueprints': directives.unchanged,
116128
'undoc-modules': directives.unchanged,
117129
'undoc-static': directives.unchanged,
118-
'include-empty-docstring': directives.unchanged}
130+
'include-empty-docstring': directives.unchanged,
131+
'autoquickref': directives.flag}
119132

120133
@property
121134
def endpoints(self):
@@ -248,8 +261,11 @@ def make_rst(self, qref=False):
248261
for method, paths, view_func, view_doc in routes:
249262
docstring = prepare_docstring(view_doc)
250263
if qref:
264+
auto = self.options.get("autoquickref", False) is None
265+
blueprint = get_blueprint(app, view_func)
251266
for path in paths:
252-
row = quickref_directive(method, path, docstring)
267+
row = quickref_directive(method, path, docstring,
268+
blueprint, auto=auto)
253269
yield row
254270
else:
255271
for line in http_directive(method, paths, docstring):

0 commit comments

Comments
 (0)