summaryrefslogtreecommitdiff
path: root/doc/build/templates/pydoc.html
blob: 72e31e0d99cc43ca609c2a8a2cb1ed4512542683 (plain)
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
<%doc>pydoc.myt - provides formatting functions for printing docstring.AbstractDoc generated python documentation objects.</%doc>
<%!
import docstring
import sys, re

def whitespace(docstring):
    if not docstring:
        return ''
    
    # Convert tabs to spaces (following the normal Python rules)
    # and split into a list of lines:
    lines = docstring.expandtabs().splitlines()
    # Determine minimum indentation (first line doesn't count):
    indent = sys.maxint
    for line in lines[1:]:
        stripped = line.lstrip()
        if stripped:
            indent = min(indent, len(line) - len(stripped))
    # Remove indentation (first line is special):
    trimmed = [lines[0].strip()]
    if indent < sys.maxint:
        for line in lines[1:]:
            trimmed.append(line[indent:].rstrip())
    # Strip off trailing and leading blank lines:
    while trimmed and not trimmed[-1]:
        trimmed.pop()
    while trimmed and not trimmed[0]:
        trimmed.pop(0)
    # Return a single string:
    return '\n'.join(trimmed)
    
def convquotes(text):
    return re.sub(r'``(.*?)``', lambda m: "<b>%s</b>" % m.group(1), text)
    
%>
<%namespace name="formatting" file="formatting.html"/>
<%namespace name="nav" file="nav.html"/>

<%def name="obj_doc(obj, toc, extension, paged)">
    <%
    if obj.isclass:
        links = []
        for elem in obj.inherits:
            if isinstance(elem, docstring.ObjectDoc):
                links.append(capture(nav.toclink, toc=toc, path=elem.toc_path, extension=extension, description=elem.name, paged=paged))
            else:
                links.append(str(elem))
        htmldescription = "class " + obj.classname + "(%s)" % (','.join(links))
    else:
        htmldescription = obj.description

    %>

    <%call expr="formatting.section(toc=toc, path=obj.toc_path, description=htmldescription, paged=paged, extension=extension)">
    % if obj.doc:
    <div class="darkcell"><pre>${obj.doc or '' |whitespace, h,convquotes}</pre></div>
    % endif
    
    % if not obj.isclass and obj.functions:

        <%call expr="formatting.section(toc=toc, path=obj.mod_path, paged=paged, extension=extension)">
            % for func in obj.functions:
                ${function_doc(func=func,toc=toc)}
            % endfor
        </%call>

    % else:

        % if obj.functions:
            % for func in obj.functions:
                % if isinstance(func, docstring.FunctionDoc):
                    ${function_doc(func=func, toc=toc)}
                % elif isinstance(func, docstring.PropertyDoc):
                    ${property_doc(prop=func)}
                % endif
            % endfor
        % endif
    % endif

    % if obj.classes:
        % for class_ in obj.classes:
            ${obj_doc(obj=class_, toc=toc, extension=extension, paged=paged)}
        % endfor
    % endif    
    </%call>
</%def>

<%def name="function_doc(func, toc)">
    <div class="darkcell">
    <%
        if hasattr(func, 'toc_path'):
            item = toc.get_by_path(func.toc_path)
        else:
            item = None
    %>
    <A name="${item and item.path or ''}"></a>
    <b>def ${func.name}(${", ".join(map(lambda k: "<i>%s</i>" % k, func.arglist))})</b>
    <div class="docstring">
    <pre>${func.doc or '' | whitespace, h, convquotes}</pre>
    </div>
    </div>
</%def>

<%def name="property_doc(prop)">
         <div class="darkcell">
         <A name=""></a>
         <b>${prop.name} = property()</b>
         <div class="docstring">
         <pre>${prop.doc or '' | whitespace, h, convquotes}</pre>
         </div> 
         </div>
</%def>