Debian Codegraph @

src/mkdocstrings_handlers/python/templates/material/_base/function.html.jinja

raw
1 {#- Template for Python functions.
2
3 This template renders a Python function or method.
4
5 Context:
6 function (griffe.Function): The function to render.
7 root (bool): Whether this is the root object, injected with `:::` in a Markdown page.
8 heading_level (int): The HTML heading level to use.
9 config (dict): The configuration options.
10 -#}
11
12 {% block logs scoped %}
13 {#- Logging block.
14
15 This block can be used to log debug messages, deprecation messages, warnings, etc.
16 -#}
17 {{ log.debug("Rendering " + function.path) }}
18 {% endblock logs %}
19
20 {% import "language.html.jinja" as lang with context %}
21 {#- Language module providing the `t` translation method. -#}
22
23 <div class="doc doc-object doc-function">
24 {% with obj = function, html_id = function.path %}
25
26 {% if root %}
27 {% set show_full_path = config.show_root_full_path %}
28 {% set root_members = True %}
29 {% elif root_members %}
30 {% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %}
31 {% set root_members = False %}
32 {% else %}
33 {% set show_full_path = config.show_object_full_path %}
34 {% endif %}
35
36 {% set function_name = function.path if show_full_path else function.name %}
37 {#- Brief or full function name depending on configuration. -#}
38 {% set symbol_type = "method" if function.parent.is_class else "function" %}
39 {#- Symbol type: method when parent is a class, function otherwise. -#}
40
41 {% if not root or config.show_root_heading %}
42 {% filter heading(
43 heading_level,
44 role="function",
45 id=html_id,
46 class="doc doc-heading",
47 toc_label=(('<code class="doc-symbol doc-symbol-toc doc-symbol-' + symbol_type + '"></code>&nbsp;')|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else function.name),
48 skip_inventory=config.skip_local_inventory,
49 ) %}
50
51 {% block heading scoped %}
52 {#- Heading block.
53
54 This block renders the heading for the function.
55 -#}
56 {% if config.show_symbol_type_heading %}<code class="doc-symbol doc-symbol-heading doc-symbol-{{ symbol_type }}"></code>{% endif %}
57 {% if config.heading and root %}
58 {{ config.heading }}
59 {% elif config.separate_signature %}
60 <span class="doc doc-object-name doc-function-name">{{ function_name }}</span>
61 {% else %}
62 {%+ filter highlight(language="python", inline=True) -%}
63 {{ function_name }}
64 {%- include "type_parameters.html.jinja" with context -%}
65 {%- include "signature.html.jinja" with context -%}
66 {%- endfilter %}
67 {% endif %}
68 {% endblock heading %}
69
70 {% block labels scoped %}
71 {#- Labels block.
72
73 This block renders the labels for the function.
74 -#}
75 {% with labels = function.labels %}
76 {% include "labels.html.jinja" with context %}
77 {% endwith %}
78 {% endblock labels %}
79
80 {% endfilter %}
81
82 {% block signature scoped %}
83 {#- Signature block.
84
85 This block renders the signature for the function,
86 as well as its overloaded signatures if any.
87 -#}
88 {% if function.overloads and config.show_overloads %}
89 <div class="doc-overloads">
90 {% for overload in function.overloads %}
91 {% filter format_signature(overload, config.line_length, annotations=True, crossrefs=config.signature_crossrefs) %}
92 {{ overload.name }}
93 {% endfilter %}
94 {% endfor %}
95 </div>
96 {% endif %}
97 {% if config.separate_signature and not (config.show_overloads and function.overloads and config.overloads_only) %}
98 {% filter format_signature(function, config.line_length, crossrefs=config.signature_crossrefs) %}
99 {{ function.name }}
100 {% endfilter %}
101 {% endif %}
102 {% endblock signature %}
103
104 {% else %}
105
106 {% if config.show_root_toc_entry %}
107 {% filter heading(
108 heading_level,
109 role="function",
110 id=html_id,
111 toc_label=(('<code class="doc-symbol doc-symbol-toc doc-symbol-' + symbol_type + '"></code>&nbsp;')|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else function.name),
112 hidden=True,
113 skip_inventory=config.skip_local_inventory,
114 ) %}
115 {% endfilter %}
116 {% endif %}
117 {% set heading_level = heading_level - 1 %}
118 {% endif %}
119
120 <div class="doc doc-contents {% if root %}first{% endif %}">
121 {% block contents scoped %}
122 {#- Contents block.
123
124 This block renders the contents of the function.
125 It contains other blocks that users can override.
126 Overriding the contents block allows to rearrange the order of the blocks.
127 -#}
128 {% block docstring scoped %}
129 {#- Docstring block.
130
131 This block renders the docstring for the function.
132 -#}
133 {% with docstring_sections = function.docstring.parsed %}
134 {% include "docstring.html.jinja" with context %}
135 {% endwith %}
136 {% endblock docstring %}
137
138 {% if config.backlinks %}
139 <backlinks identifier="{{ html_id }}" handler="python" />
140 {% endif %}
141
142 {% block source scoped %}
143 {#- Source block.
144
145 This block renders the source code for the function.
146 -#}
147 {% if config.show_source and function.source %}
148 <details class="mkdocstrings-source">
149 <summary>{{ lang.t("Source code in") }} <code>{{ function|source_location }}</code></summary>
150 {{ function.source|highlight(language="python", linestart=function.lineno or 0, linenums=True) }}
151 </details>
152 {% endif %}
153 {% endblock source %}
154 {% endblock contents %}
155 </div>
156
157 {% endwith %}
158 </div>