Debian Codegraph @

docs/templates/html.mako

raw
1 <%
2 import os
3
4 import pdoc
5 from pdoc.html_helpers import extract_toc, glimpse, to_html as _to_html, format_git_link
6
7
8 def link(dobj: pdoc.Doc, name=None):
9 name = name or dobj.qualname + ('()' if isinstance(dobj, pdoc.Function) else '')
10 if isinstance(dobj, pdoc.External) and not external_links:
11 return name
12 url = dobj.url(relative_to=module, link_prefix=link_prefix,
13 top_ancestor=not show_inherited_members)
14 return f'<a title="{dobj.refname}" href="{url}">{name}</a>'
15
16
17 def to_html(text):
18 return _to_html(text, docformat=docformat, module=module, link=link, latex_math=latex_math)
19
20
21 def get_annotation(bound_method, sep=':'):
22 annot = show_type_annotations and bound_method(link=link) or ''
23 if annot:
24 annot = ' ' + sep + '\N{NBSP}' + annot
25 return annot
26 %>
27
28 <%def name="ident(name)"><span class="ident">${name}</span></%def>
29
30 <%def name="show_source(d)">
31 % if (show_source_code or git_link_template) and d.source and d.obj is not getattr(d.inherits, 'obj', None):
32 <% git_link = format_git_link(git_link_template, d) %>
33 % if show_source_code:
34 <details class="source">
35 <summary>
36 <span>Expand source code</span>
37 % if git_link:
38 <a href="${git_link}" class="git-link">Browse git</a>
39 %endif
40 </summary>
41 <pre><code class="python">${d.source | h}</code></pre>
42 </details>
43 % elif git_link:
44 <div class="git-link-div"><a href="${git_link}" class="git-link">Browse git</a></div>
45 %endif
46 %endif
47 </%def>
48
49 <%def name="show_desc(d, short=False)">
50 <%
51 inherits = ' inherited' if d.inherits else ''
52 docstring = glimpse(d.docstring) if short or inherits else d.docstring
53 %>
54 % if d.inherits:
55 <p class="inheritance">
56 <em>Inherited from:</em>
57 % if hasattr(d.inherits, 'cls'):
58 <code>${link(d.inherits.cls)}</code>.<code>${link(d.inherits, d.name)}</code>
59 % else:
60 <code>${link(d.inherits)}</code>
61 % endif
62 </p>
63 % endif
64 <div class="desc${inherits}">${docstring | to_html}</div>
65 % if not isinstance(d, pdoc.Module):
66 ${show_source(d)}
67 % endif
68 </%def>
69
70 <%def name="show_module_list(modules)">
71 <h1>Python module list</h1>
72
73 % if not modules:
74 <p>No modules found.</p>
75 % else:
76 <dl id="http-server-module-list">
77 % for name, desc in modules:
78 <div class="flex">
79 <dt><a href="${link_prefix}${name}">${name}</a></dt>
80 <dd>${desc | glimpse, to_html}</dd>
81 </div>
82 % endfor
83 </dl>
84 % endif
85 </%def>
86
87 <%def name="show_column_list(items)">
88 <%
89 two_column = len(items) >= 6 and all(len(i.name) < 20 for i in items)
90 %>
91 <ul class="${'two-column' if two_column else ''}">
92 % for item in items:
93 <li><code>${link(item, item.name)}</code></li>
94 % endfor
95 </ul>
96 </%def>
97
98 <%def name="show_module(module)">
99 <%
100 variables = module.variables(sort=sort_identifiers)
101 classes = module.classes(sort=sort_identifiers)
102 functions = module.functions(sort=sort_identifiers)
103 submodules = module.submodules()
104 %>
105
106 <%def name="show_func(f)">
107 <dt id="${f.refname}"><code class="name flex">
108 <%
109 params = ', '.join(f.params(annotate=show_type_annotations, link=link))
110 return_type = get_annotation(f.return_annotation, '\N{non-breaking hyphen}>')
111 %>
112 <span>${f.funcdef()} ${ident(f.name)}</span>(<span>${params})${return_type}</span>
113 </code></dt>
114 <dd>${show_desc(f)}</dd>
115 </%def>
116
117 <header>
118 % if http_server:
119 <nav class="http-server-breadcrumbs">
120 <a href="/">All packages</a>
121 <% parts = module.name.split('.')[:-1] %>
122 % for i, m in enumerate(parts):
123 <% parent = '.'.join(parts[:i+1]) %>
124 :: <a href="/${parent.replace('.', '/')}/">${parent}</a>
125 % endfor
126 </nav>
127 % endif
128 <h1 class="title">${'Namespace' if module.is_namespace else \
129 'Package' if module.is_package and not module.supermodule else \
130 'Module'} <code>${module.name}</code></h1>
131 </header>
132
133 <section id="section-intro">
134 ${module.docstring | to_html}
135 ${show_source(module)}
136 </section>
137
138 <section>
139 % if submodules:
140 <h2 class="section-title" id="header-submodules">Sub-modules</h2>
141 <dl>
142 % for m in submodules:
143 <dt><code class="name">${link(m)}</code></dt>
144 <dd>${show_desc(m, short=True)}</dd>
145 % endfor
146 </dl>
147 % endif
148 </section>
149
150 <section>
151 % if variables:
152 <h2 class="section-title" id="header-variables">Global variables</h2>
153 <dl>
154 % for v in variables:
155 <% return_type = get_annotation(v.type_annotation) %>
156 <dt id="${v.refname}"><code class="name">var ${ident(v.name)}${return_type}</code></dt>
157 <dd>${show_desc(v)}</dd>
158 % endfor
159 </dl>
160 % endif
161 </section>
162
163 <section>
164 % if functions:
165 <h2 class="section-title" id="header-functions">Functions</h2>
166 <dl>
167 % for f in functions:
168 ${show_func(f)}
169 % endfor
170 </dl>
171 % endif
172 </section>
173
174 <section>
175 % if classes:
176 <h2 class="section-title" id="header-classes">Classes</h2>
177 <dl>
178 % for c in classes:
179 <%
180 class_vars = c.class_variables(show_inherited_members, sort=sort_identifiers)
181 smethods = c.functions(show_inherited_members, sort=sort_identifiers)
182 inst_vars = c.instance_variables(show_inherited_members, sort=sort_identifiers)
183 methods = c.methods(show_inherited_members, sort=sort_identifiers)
184 mro = c.mro()
185 subclasses = c.subclasses()
186 params = ', '.join(c.params(annotate=show_type_annotations, link=link))
187 %>
188 <dt id="${c.refname}"><code class="flex name class">
189 <span>class ${ident(c.name)}</span>
190 % if params:
191 <span>(</span><span>${params})</span>
192 % endif
193 </code></dt>
194
195 <dd>${show_desc(c)}
196
197 % if mro:
198 <h3>Ancestors</h3>
199 <ul class="hlist">
200 % for cls in mro:
201 <li>${link(cls)}</li>
202 % endfor
203 </ul>
204 %endif
205
206 % if subclasses:
207 <h3>Subclasses</h3>
208 <ul class="hlist">
209 % for sub in subclasses:
210 <li>${link(sub)}</li>
211 % endfor
212 </ul>
213 % endif
214 % if class_vars:
215 <h3>Class variables</h3>
216 <dl>
217 % for v in class_vars:
218 <% return_type = get_annotation(v.type_annotation) %>
219 <dt id="${v.refname}"><code class="name">var ${ident(v.name)}${return_type}</code></dt>
220 <dd>${show_desc(v)}</dd>
221 % endfor
222 </dl>
223 % endif
224 % if smethods:
225 <h3>Static methods</h3>
226 <dl>
227 % for f in smethods:
228 ${show_func(f)}
229 % endfor
230 </dl>
231 % endif
232 % if inst_vars:
233 <h3>Instance variables</h3>
234 <dl>
235 % for v in inst_vars:
236 <% return_type = get_annotation(v.type_annotation) %>
237 <dt id="${v.refname}"><code class="name">var ${ident(v.name)}${return_type}</code></dt>
238 <dd>${show_desc(v)}</dd>
239 % endfor
240 </dl>
241 % endif
242 % if methods:
243 <h3>Methods</h3>
244 <dl>
245 % for f in methods:
246 ${show_func(f)}
247 % endfor
248 </dl>
249 % endif
250
251 % if not show_inherited_members:
252 <%
253 members = c.inherited_members()
254 %>
255 % if members:
256 <h3>Inherited members</h3>
257 <ul class="hlist">
258 % for cls, mems in members:
259 <li><code><b>${link(cls)}</b></code>:
260 <ul class="hlist">
261 % for m in mems:
262 <li><code>${link(m, name=m.name)}</code></li>
263 % endfor
264 </ul>
265
266 </li>
267 % endfor
268 </ul>
269 % endif
270 % endif
271
272 </dd>
273 % endfor
274 </dl>
275 % endif
276 </section>
277 </%def>
278
279 <%def name="module_index(module)">
280 <%
281 variables = module.variables(sort=sort_identifiers)
282 classes = module.classes(sort=sort_identifiers)
283 functions = module.functions(sort=sort_identifiers)
284 submodules = module.submodules()
285 supermodule = module.supermodule
286 %>
287 <nav id="sidebar">
288
289 <%include file="logo.mako"/>
290
291 % if google_search_query:
292 <div class="gcse-search" style="height: 70px"
293 data-as_oq="${' '.join(google_search_query.strip().split()) | h }"
294 data-gaCategoryParameter="${module.refname | h}">
295 </div>
296 % endif
297
298 % if lunr_search is not None:
299 <%include file="_lunr_search.inc.mako"/>
300 % endif
301
302 <h1>Index</h1>
303 ${extract_toc(module.docstring) if extract_module_toc_into_sidebar else ''}
304 <ul id="index">
305 % if supermodule:
306 <li><h3>Super-module</h3>
307 <ul>
308 <li><code>${link(supermodule)}</code></li>
309 </ul>
310 </li>
311 % endif
312
313 % if submodules:
314 <li><h3><a href="#header-submodules">Sub-modules</a></h3>
315 <ul>
316 % for m in submodules:
317 <li><code>${link(m)}</code></li>
318 % endfor
319 </ul>
320 </li>
321 % endif
322
323 % if variables:
324 <li><h3><a href="#header-variables">Global variables</a></h3>
325 ${show_column_list(variables)}
326 </li>
327 % endif
328
329 % if functions:
330 <li><h3><a href="#header-functions">Functions</a></h3>
331 ${show_column_list(functions)}
332 </li>
333 % endif
334
335 % if classes:
336 <li><h3><a href="#header-classes">Classes</a></h3>
337 <ul>
338 % for c in classes:
339 <li>
340 <h4><code>${link(c)}</code></h4>
341 <%
342 members = c.functions(sort=sort_identifiers) + c.methods(sort=sort_identifiers)
343 if list_class_variables_in_index:
344 members += (c.instance_variables(sort=sort_identifiers) +
345 c.class_variables(sort=sort_identifiers))
346 if not show_inherited_members:
347 members = [i for i in members if not i.inherits]
348 if sort_identifiers:
349 members = sorted(members)
350 %>
351 % if members:
352 ${show_column_list(members)}
353 % endif
354 </li>
355 % endfor
356 </ul>
357 </li>
358 % endif
359
360 </ul>
361 </nav>
362 </%def>
363
364 <!doctype html>
365 <html lang="${html_lang}">
366 <head>
367 <meta charset="utf-8">
368 <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
369 <meta name="generator" content="pdoc ${pdoc.__version__}" />
370
371 <%
372 module_list = 'modules' in context.keys() # Whether we're showing module list in server mode
373 %>
374
375 % if module_list:
376 <title>Python module list</title>
377 <meta name="description" content="A list of documented Python modules." />
378 % else:
379 <title>${module.name} API documentation</title>
380 <meta name="description" content="${module.docstring | glimpse, trim, h}" />
381 % endif
382
383 <link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
384 <link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
385 % if syntax_highlighting:
386 <link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/${hljs_style}.min.css" crossorigin>
387 %endif
388
389 <%namespace name="css" file="css.mako" />
390 <style>${css.mobile()}</style>
391 <style media="screen and (min-width: 700px)">${css.desktop()}</style>
392 <style media="print">${css.print()}</style>
393
394 % if google_analytics:
395 <script>
396 window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
397 ga('create', '${google_analytics}', 'auto'); ga('send', 'pageview');
398 </script><script async src='https://www.google-analytics.com/analytics.js'></script>
399 % endif
400
401 % if google_search_query:
402 <link rel="preconnect" href="https://www.google.com">
403 <script async src="https://cse.google.com/cse.js?cx=017837193012385208679:pey8ky8gdqw"></script>
404 <style>
405 .gsc-control-cse {padding:0 !important;margin-top:1em}
406 body.gsc-overflow-hidden #sidebar {overflow: visible;}
407 </style>
408 % endif
409
410 % if latex_math:
411 <script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS_CHTML" integrity="sha256-kZafAc6mZvK3W3v1pHOcUix30OHQN6pU/NO2oFkqZVw=" crossorigin></script>
412 % endif
413
414 % if syntax_highlighting:
415 <script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
416 <script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
417 % endif
418
419 <%include file="head.mako"/>
420 </head>
421 <body>
422 <main>
423 % if module_list:
424 <article id="content">
425 ${show_module_list(modules)}
426 </article>
427 % else:
428 <article id="content">
429 ${show_module(module)}
430 </article>
431 ${module_index(module)}
432 % endif
433 </main>
434
435 <footer id="footer">
436 <%include file="credits.mako"/>
437 <p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> ${pdoc.__version__}</a>.</p>
438 </footer>
439
440 % if http_server and module: ## Auto-reload on file change in dev mode
441 <script>
442 setInterval(() =>
443 fetch(window.location.href, {
444 method: "HEAD",
445 cache: "no-store",
446 headers: {"If-None-Match": "${os.stat(module.obj.__file__).st_mtime}"},
447 }).then(response => response.ok && window.location.reload()), 700);
448 </script>
449 % endif
450 </body>
451 </html>