@@ -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+
6975def 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