| 1 |
{#- Template for Python classes. |
| 2 |
|
| 3 |
This template renders a Python class. |
| 4 |
|
| 5 |
Context: |
| 6 |
class (griffe.Class): The class 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 " + class.path) }} |
| 18 |
{% endblock logs %} |
| 19 |
|
| 20 |
<div class="doc doc-object doc-class"> |
| 21 |
{% with obj = class, html_id = class.path %} |
| 22 |
|
| 23 |
{% if root %} |
| 24 |
{% set show_full_path = config.show_root_full_path %} |
| 25 |
{% set root_members = True %} |
| 26 |
{% elif root_members %} |
| 27 |
{% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %} |
| 28 |
{% set root_members = False %} |
| 29 |
{% else %} |
| 30 |
{% set show_full_path = config.show_object_full_path %} |
| 31 |
{% endif %} |
| 32 |
|
| 33 |
{% set class_name = class.path if show_full_path else class.name %} |
| 34 |
|
| 35 |
{% if not root or config.show_root_heading %} |
| 36 |
{% filter heading( |
| 37 |
heading_level, |
| 38 |
role="class", |
| 39 |
id=html_id, |
| 40 |
class="doc doc-heading", |
| 41 |
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-class"></code> '|safe if config.show_symbol_type_toc else '') + class.name, |
| 42 |
) %} |
| 43 |
|
| 44 |
{% block heading scoped %} |
| 45 |
{#- Heading block. |
| 46 |
|
| 47 |
This block renders the heading for the class. |
| 48 |
-#} |
| 49 |
{% if config.show_symbol_type_heading %}<code class="doc-symbol doc-symbol-heading doc-symbol-class"></code>{% endif %} |
| 50 |
{% if config.separate_signature %} |
| 51 |
<span class="doc doc-object-name doc-class-name">{{ class_name }}</span> |
| 52 |
{% elif config.merge_init_into_class and "__init__" in class.all_members %} |
| 53 |
{% with function = class.all_members["__init__"] %} |
| 54 |
{%+ filter highlight(language="python", inline=True) %} |
| 55 |
{{ class_name }}{% include "signature.html.jinja" with context %} |
| 56 |
{% endfilter %} |
| 57 |
{% endwith %} |
| 58 |
{% else %} |
| 59 |
<code>{{ class_name }}</code> |
| 60 |
{% endif %} |
| 61 |
{% endblock heading %} |
| 62 |
|
| 63 |
{% block labels scoped %} |
| 64 |
{#- Labels block. |
| 65 |
|
| 66 |
This block renders the labels for the class. |
| 67 |
-#} |
| 68 |
{% with labels = class.labels %} |
| 69 |
{% include "labels.html.jinja" with context %} |
| 70 |
{% endwith %} |
| 71 |
{% endblock labels %} |
| 72 |
|
| 73 |
{% endfilter %} |
| 74 |
|
| 75 |
{% block signature scoped %} |
| 76 |
{#- Signature block. |
| 77 |
|
| 78 |
This block renders the signature for the class. |
| 79 |
-#} |
| 80 |
{% if config.separate_signature and config.merge_init_into_class %} |
| 81 |
{% if "__init__" in class.all_members %} |
| 82 |
{% with function = class.all_members["__init__"] %} |
| 83 |
{% filter format_signature(function, config.line_length, crossrefs=config.signature_crossrefs) %} |
| 84 |
{{ class.name }} |
| 85 |
{% endfilter %} |
| 86 |
{% endwith %} |
| 87 |
{% endif %} |
| 88 |
{% endif %} |
| 89 |
{% endblock signature %} |
| 90 |
|
| 91 |
{% else %} |
| 92 |
{% if config.show_root_toc_entry %} |
| 93 |
{% filter heading(heading_level, |
| 94 |
role="class", |
| 95 |
id=html_id, |
| 96 |
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-class"></code> '|safe if config.show_symbol_type_toc else '') + class.name, |
| 97 |
hidden=True, |
| 98 |
) %} |
| 99 |
{% endfilter %} |
| 100 |
{% endif %} |
| 101 |
{% set heading_level = heading_level - 1 %} |
| 102 |
{% endif %} |
| 103 |
|
| 104 |
<div class="doc doc-contents {% if root %}first{% endif %}"> |
| 105 |
{% block contents scoped %} |
| 106 |
{#- Contents block. |
| 107 |
|
| 108 |
This block renders the contents of the class. |
| 109 |
It contains other blocks that users can override. |
| 110 |
Overriding the contents block allows to rearrange the order of the blocks. |
| 111 |
-#} |
| 112 |
{% block bases scoped %} |
| 113 |
{#- Class bases block. |
| 114 |
|
| 115 |
This block renders the bases for the class. |
| 116 |
-#} |
| 117 |
{% if config.show_bases and class.bases %} |
| 118 |
<p class="doc doc-class-bases"> |
| 119 |
Bases: {% for expression in class.bases -%} |
| 120 |
<code>{% include "expression.html.jinja" with context %}</code>{% if not loop.last %}, {% endif %} |
| 121 |
{% endfor -%} |
| 122 |
</p> |
| 123 |
{% endif %} |
| 124 |
{% endblock bases %} |
| 125 |
|
| 126 |
{% block inheritance_diagram scoped %} |
| 127 |
{#- Inheritance diagram block. |
| 128 |
|
| 129 |
This block renders the inheritance diagram for the class, |
| 130 |
using Mermaid syntax and a bit of JavaScript to make the nodes clickable, |
| 131 |
linking to the corresponding class documentation. |
| 132 |
-#} |
| 133 |
{% if config.show_inheritance_diagram and class.bases %} |
| 134 |
{% macro edges(class) %} |
| 135 |
{% for base in class.resolved_bases %} |
| 136 |
{{ base.path }} --> {{ class.path }} |
| 137 |
{{ edges(base) }} |
| 138 |
{% endfor %} |
| 139 |
{% endmacro %} |
| 140 |
<div style="display: none"> |
| 141 |
<autoref identifier="{{ class.path }}" optional id="mermaid-link-{{ class.path }}"></autoref> |
| 142 |
{% for base in class.mro() %} |
| 143 |
<autoref identifier="{{ base.path }}" optional id="mermaid-link-{{ base.path }}"></autoref> |
| 144 |
{% endfor %} |
| 145 |
</div> |
| 146 |
<div class="mermaid" id="mermaid-diagram-{{ class.path }}"> |
| 147 |
flowchart {{ config.inheritance_diagram_direction }} |
| 148 |
{{ class.path }}[{{ class.name }}] |
| 149 |
{% for base in class.mro() %} |
| 150 |
{{ base.path }}[{{ base.name }}] |
| 151 |
{% endfor %} |
| 152 |
|
| 153 |
{{ edges(class) | safe }} |
| 154 |
|
| 155 |
click {{ class.path }} href "" "{{ class.path }}" |
| 156 |
{% for base in class.mro() %} |
| 157 |
click {{ base.path }} href "" "{{ base.path }}" |
| 158 |
{% endfor %} |
| 159 |
</div> |
| 160 |
<script> |
| 161 |
var diagram = document.getElementById('mermaid-diagram-{{ class.path }}'); |
| 162 |
diagram.innerHTML = diagram.innerHTML.replace(/click ([\w.]+) href "" "\1"/g, function(match, nodeID, offset) { |
| 163 |
try { |
| 164 |
const link = document.getElementById("mermaid-link-" + nodeID).href; |
| 165 |
return `click ${nodeID} href "${link}" "${nodeID}"` |
| 166 |
} catch (e) { |
| 167 |
return ''; |
| 168 |
} |
| 169 |
}); |
| 170 |
</script> |
| 171 |
{% endif %} |
| 172 |
{% endblock inheritance_diagram %} |
| 173 |
|
| 174 |
{% block docstring scoped %} |
| 175 |
{#- Docstring block. |
| 176 |
|
| 177 |
This block renders the docstring for the class. |
| 178 |
-#} |
| 179 |
{% with docstring_sections = class.docstring.parsed %} |
| 180 |
{% include "docstring.html.jinja" with context %} |
| 181 |
{% endwith %} |
| 182 |
{% if config.merge_init_into_class %} |
| 183 |
{% if "__init__" in class.all_members and class.all_members["__init__"].has_docstring %} |
| 184 |
{% with function = class.all_members["__init__"] %} |
| 185 |
{% with obj = function, docstring_sections = function.docstring.parsed %} |
| 186 |
{% include "docstring.html.jinja" with context %} |
| 187 |
{% endwith %} |
| 188 |
{% endwith %} |
| 189 |
{% endif %} |
| 190 |
{% endif %} |
| 191 |
{% endblock docstring %} |
| 192 |
|
| 193 |
{% block summary scoped %} |
| 194 |
{#- Summary block. |
| 195 |
|
| 196 |
This block renders auto-summaries for classes, methods, and attributes. |
| 197 |
-#} |
| 198 |
{% include "summary.html.jinja" with context %} |
| 199 |
{% endblock summary %} |
| 200 |
|
| 201 |
{% block source scoped %} |
| 202 |
{#- Source block. |
| 203 |
|
| 204 |
This block renders the source code for the class. |
| 205 |
-#} |
| 206 |
{% if config.show_source %} |
| 207 |
{% if config.merge_init_into_class %} |
| 208 |
{% if "__init__" in class.all_members and class.all_members["__init__"].source %} |
| 209 |
{% with init = class.all_members["__init__"] %} |
| 210 |
<details class="quote"> |
| 211 |
<summary>Source code in <code>{{ init|source_location }}</code></summary> |
| 212 |
{{ init.source|highlight(language="python", linestart=init.lineno or 0, linenums=True) }} |
| 213 |
</details> |
| 214 |
{% endwith %} |
| 215 |
{% endif %} |
| 216 |
{% elif class.source %} |
| 217 |
<details class="quote"> |
| 218 |
<summary>Source code in <code>{{ class|source_location }}</code></summary> |
| 219 |
{{ class.source|highlight(language="python", linestart=class.lineno or 0, linenums=True) }} |
| 220 |
</details> |
| 221 |
{% endif %} |
| 222 |
{% endif %} |
| 223 |
{% endblock source %} |
| 224 |
|
| 225 |
{% block children scoped %} |
| 226 |
{#- Children block. |
| 227 |
|
| 228 |
This block renders the children (members) of the class. |
| 229 |
-#} |
| 230 |
{% set root = False %} |
| 231 |
{% set heading_level = heading_level + 1 %} |
| 232 |
{% include "children.html.jinja" with context %} |
| 233 |
{% endblock children %} |
| 234 |
{% endblock contents %} |
| 235 |
</div> |
| 236 |
|
| 237 |
{% endwith %} |
| 238 |
|
| 239 |
</div> |