@@ -33,34 +33,21 @@ def _process_docstring(app, what, name, obj, options, lines):
3333
3434
3535class GitlabDocstring (GoogleDocstring ):
36- _j2_env = None
37-
38- def _build_j2_env (self ):
39- if self ._j2_env is None :
40- self ._j2_env = jinja2 .Environment (loader = jinja2 .FileSystemLoader (
41- os .path .dirname (__file__ )), trim_blocks = False )
42- self ._j2_env .filters ['classref' ] = classref
43-
44- return self ._j2_env
45-
46- def _build_manager_doc (self ):
47- env = self ._build_j2_env ()
48- template = env .get_template ('manager_tmpl.j2' )
49- output = template .render (cls = self ._obj .obj_cls )
50-
51- return output .split ('\n ' )
52-
53- def _build_object_doc (self ):
54- env = self ._build_j2_env ()
55- template = env .get_template ('object_tmpl.j2' )
56- output = template .render (obj = self ._obj )
36+ def _build_doc (self , tmpl , ** kwargs ):
37+ env = jinja2 .Environment (loader = jinja2 .FileSystemLoader (
38+ os .path .dirname (__file__ )), trim_blocks = False )
39+ env .filters ['classref' ] = classref
40+ template = env .get_template (tmpl )
41+ output = template .render (** kwargs )
5742
5843 return output .split ('\n ' )
5944
6045 def __init__ (self , * args , ** kwargs ):
6146 super (GitlabDocstring , self ).__init__ (* args , ** kwargs )
6247
6348 if hasattr (self ._obj , 'obj_cls' ) and self ._obj .obj_cls is not None :
64- self ._parsed_lines = self ._build_manager_doc ()
49+ self ._parsed_lines = self ._build_doc ('manager_tmpl.j2' ,
50+ cls = self ._obj .obj_cls )
6551 elif hasattr (self ._obj , 'canUpdate' ) and self ._obj .canUpdate :
66- self ._parsed_lines = self ._build_object_doc ()
52+ self ._parsed_lines = self ._build_doc ('object_tmpl.j2' ,
53+ obj = self ._obj )
0 commit comments