1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
## Define mini-templates for each portion of the doco.
<%!
def indent(s, spaces=4):
new = s.replace('\n', '\n' + ' ' * spaces)
return ' ' * spaces + new.strip()
%>
<%def name="deflist(s)">:${indent(s)[1:]}</%def>
<%def name="h3(s)">### ${s}
</%def>
<%def name="function(func)" buffered="True">
<%
returns = show_type_annotations and func.return_annotation() or ''
if returns:
returns = ' \N{non-breaking hyphen}> ' + returns
%>
`${func.name}(${", ".join(func.params(annotate=show_type_annotations))})${returns}`
${func.docstring | deflist}
</%def>
<%def name="variable(var)" buffered="True">
<%
annot = show_type_annotations and var.type_annotation() or ''
if annot:
annot = ': ' + annot
%>
`${var.name}${annot}`
${var.docstring | deflist}
</%def>
<%def name="class_(cls)" buffered="True">
`${cls.name}(${", ".join(cls.params(annotate=show_type_annotations))})`
${cls.docstring | deflist}
<%
class_vars = cls.class_variables(show_inherited_members, sort=sort_identifiers)
static_methods = cls.functions(show_inherited_members, sort=sort_identifiers)
inst_vars = cls.instance_variables(show_inherited_members, sort=sort_identifiers)
methods = cls.methods(show_inherited_members, sort=sort_identifiers)
mro = cls.mro()
subclasses = cls.subclasses()
%>
% if mro:
${h3('Ancestors (in MRO)')}
% for c in mro:
* ${c.refname}
% endfor
% endif
% if subclasses:
${h3('Descendants')}
% for c in subclasses:
* ${c.refname}
% endfor
% endif
% if class_vars:
${h3('Class variables')}
% for v in class_vars:
${variable(v) | indent}
% endfor
% endif
% if static_methods:
${h3('Static methods')}
% for f in static_methods:
${function(f) | indent}
% endfor
% endif
% if inst_vars:
${h3('Instance variables')}
% for v in inst_vars:
${variable(v) | indent}
% endfor
% endif
% if methods:
${h3('Methods')}
% for m in methods:
${function(m) | indent}
% endfor
% endif
</%def>
## Start the output logic for an entire module.
<%
variables = module.variables(sort=sort_identifiers)
classes = module.classes(sort=sort_identifiers)
functions = module.functions(sort=sort_identifiers)
submodules = module.submodules()
heading = 'Namespace' if module.is_namespace else 'Module'
%>
${heading} ${module.name}
=${'=' * (len(module.name) + len(heading))}
${module.docstring}
% if submodules:
Sub-modules
-----------
% for m in submodules:
* ${m.name}
% endfor
% endif
% if variables:
Variables
---------
% for v in variables:
${variable(v)}
% endfor
% endif
% if functions:
Functions
---------
% for f in functions:
${function(f)}
% endfor
% endif
% if classes:
Classes
-------
% for c in classes:
${class_(c)}
% endfor
% endif
|