summaryrefslogtreecommitdiff
path: root/giscanner/doctemplates/devdocs/Gjs/_index.tmpl
blob: e53f45589dbbc02a2b328bf783143d87ef45d637 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<%namespace name="doc" file="_doc.tmpl"/>

<%
  ancestors = []
  if isinstance(node, ast.Class):
    ancestors = formatter.get_inheritable_types(node)

  fields = getattr(node, 'fields', [])
  extra_fields = [getattr(f.anonymous_node, 'fields', []) for f in fields
    if f.anonymous_node is not None]
  extra_fields = [field for sublist in extra_fields for field in sublist]
  non_private_fields = [f for f in fields + extra_fields
      if not formatter.is_private_field(node, f)]

  def get_ancestor_counts(*kinds):
    counts = {}
    for a in ancestors:
      count = 0
      for kind in kinds:
        if kind == 'fields':
          count += len(non_private_fields)
        else:
          count += len(getattr(a, kind, []))
      if count:
        counts[a] = count
    return counts

  def should_render(*kinds):
    has_nonempty = False
    for kind in kinds:
      if kind == 'fields':
        if non_private_fields:
          has_nonempty = True
      elif getattr(node, kind, []):
        has_nonempty = True
    return has_nonempty or get_ancestor_counts(*kinds)
%>

<%def name="inherited(*kinds)">
  <% counts = get_ancestor_counts(*kinds) %>
  % if counts:
    <%
      links = ', '.join(['{} ({})'.format(formatter.format_xref(a), count)
        for a, count in counts.items()])
    %>
    ${formatter.format(node, '**Inherited:** ' + links)}
  % endif
</%def>

<%def name="format_function_cell(m)">
  <td class="${doc.deprecated_class(m)}">
    <a href="#${formatter.make_anchor(m)}">
      ${formatter.format_function_name(m)}<!-- no space
    --></a><!-- no space
    -->(${formatter.format_in_parameters(m)})
  </td>
</%def>

% if should_render('static_methods', 'constructors', 'methods'):
  <h2 id="index-methods">Methods</h2>
  ${inherited('static_methods', 'constructors', 'methods')}
  <%
    static_methods = getattr(node, 'static_methods', []) + getattr(node, 'constructors', [])
    methods = static_methods + getattr(node, 'methods', [])
  %>
  % if methods:
    <table class="index">
      <tbody>
      % for m in methods:
        <%doc:introspectable node="${m}">
        <tr>
          % if m in static_methods:
            <td class="static-method-indicator">static</td>
          % else:
            <td></td>
          % endif
          ${format_function_cell(m)}
        </tr>
        </%doc:introspectable>
      % endfor
      </tbody>
    </table>
  % endif
% endif

% if should_render('virtual_methods'):
  <h2 id="index-vfuncs">Virtual methods</h2>
  ${inherited('virtual_methods')}
  % if getattr(node, 'virtual_methods', []):
    <table>
      <tbody>
      % for m in node.virtual_methods:
        <%doc:introspectable node="${m}">
        <tr>
          ${format_function_cell(m)}
        </tr>
        </%doc:introspectable>
      % endfor
      </tbody>
    </table>
  % endif
% endif

% if should_render('properties'):
  <h2 id="index-properties">Properties</h2>
  ${inherited('properties')}
  % if getattr(node, 'properties', []):
    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Type</th>
          <th>Flags</th>
        </tr>
      </thead>
      <tbody>
      % for p in node.properties:
        <%doc:introspectable node="${p}">
        <tr>
          <td class="${doc.deprecated_class(p)}">
            <a href="#${formatter.make_anchor(p)}">${p.name}</a>
          </td>
          <td>${formatter.format_type(p.type)}</td>
          <td>${formatter.format_property_flags(p, abbrev=True)}</td>
        </tr>
        </%doc:introspectable>
      % endfor
      </tbody>
    </table>
  % endif
% endif

% if should_render('signals'):
  <h2 id="index-signals">Signals</h2>
  ${inherited('signals')}
  % if getattr(node, 'signals', []):
    <table>
      <tbody>
      % for s in node.signals:
        <%doc:introspectable node="${s}">
        <tr>
          <td class="${doc.deprecated_class(s)}">
            <a href="#${formatter.make_anchor(s)}">${s.name}</a><!-- no space
            -->(${formatter.format_signal_parameters(s)})
          </td>
        </tr>
        </%doc:introspectable>
      % endfor
      </tbody>
    </table>
  % endif
% endif

% if should_render('fields'):
  <h2 id="index-fields">Fields</h2>
  ${inherited('fields')}
  % if non_private_fields:
    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Type</th>
          <th>Access</th>
          <th>Description</th>
        </tr>
      </thead>
      <tbody>
      % for f in non_private_fields:
        <%doc:introspectable node="${f}">
        <tr>
          <td class="${doc.deprecated_class(f)}">
            <span class="entry" href="#${formatter.make_anchor(f)}">
              ${f.name}
            </span>
          </td>
          <td>${formatter.format_type(f.type)}</td>
          <td>${formatter.format_property_flags(f, abbrev=True)}</td>
          ## Fields almost never warrant a detailed entry, we'll just make this
          ## the entry to be indexed by DevDocs
          <td>
          % if f.doc:
            ${formatter.format_inline(node, f.doc)}
          % endif
          </td>
        </tr>
        </%doc:introspectable>
      % endfor
      </tbody>
    </table>
  % endif
% endif