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