|
1 | | -{#- Template for Python attributes. |
| 1 | +{% extends "_base/attribute.html.jinja" %} |
2 | 2 |
|
3 | | -This template renders a Python attribute (or variable). |
4 | | -This can be a module attribute or a class attribute. |
| 3 | +{% block heading %} |
| 4 | + {#- Heading block. |
5 | 5 |
|
6 | | -Context: |
7 | | - attribute (griffe.Attribute): The attribute to render. |
8 | | - root (bool): Whether this is the root object, injected with `:::` in a Markdown page. |
9 | | - heading_level (int): The HTML heading level to use. |
10 | | - config (dict): The configuration options. |
11 | | --#} |
12 | | - |
13 | | -{% block logs scoped %} |
14 | | - {#- Logging block. |
15 | | -
|
16 | | - This block can be used to log debug messages, deprecation messages, warnings, etc. |
| 6 | + This block renders the heading for the attribute. |
17 | 7 | -#} |
18 | | - {{ log.debug("Rendering " + attribute.path) }} |
19 | | -{% endblock logs %} |
20 | | - |
21 | | -<div class="doc doc-object doc-attribute"> |
22 | | - {% with obj = attribute, html_id = attribute.path %} |
23 | | - |
24 | | - {% if root %} |
25 | | - {% set show_full_path = config.show_root_full_path %} |
26 | | - {% set root_members = True %} |
27 | | - {% elif root_members %} |
28 | | - {% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %} |
29 | | - {% set root_members = False %} |
30 | | - {% else %} |
31 | | - {% set show_full_path = config.show_object_full_path %} |
32 | | - {% endif %} |
33 | | - |
34 | | - {# {% set attribute_name = attribute.path if show_full_path else attribute.name %} #} |
35 | | - {# TODO some better way to visualize the alias #} |
36 | | - {% set attribute_name = attribute.extra.griffe_pydantic.alias %} |
37 | | - |
38 | | - {% if not root or config.show_root_heading %} |
39 | | - {% filter heading( |
40 | | - heading_level, |
41 | | - role="data" if attribute.parent.kind.value == "module" else "attr", |
42 | | - id=html_id, |
43 | | - class="doc doc-heading", |
44 | | - toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-attribute"></code> '|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else attribute.name), |
45 | | - skip_inventory=config.skip_local_inventory, |
46 | | - ) %} |
47 | | - |
48 | | - {% block heading scoped %} |
49 | | - {#- Heading block. |
50 | | -
|
51 | | - This block renders the heading for the attribute. |
52 | | - -#} |
53 | | - {% if config.show_symbol_type_heading %}<code class="doc-symbol doc-symbol-heading doc-symbol-attribute"></code>{% endif %} |
54 | | - {% if config.heading and root %} |
55 | | - {{ config.heading }} |
56 | | - {% elif config.separate_signature %} |
57 | | - <span class="doc doc-object-name doc-attribute-name">{{ attribute_name }}</span> |
58 | | - {% else %} |
59 | | - {%+ filter highlight(language="python", inline=True) %} |
60 | | - {{ attribute_name }}{% if attribute.annotation and config.show_signature_annotations %}: {{ attribute.annotation }}{% endif %} |
61 | | - {% if config.show_attribute_values and attribute.value %} = {{ attribute.value }}{% endif %} |
62 | | - {% endfilter %} |
63 | | - {% endif %} |
64 | | - {% endblock heading %} |
65 | | - |
66 | | - {% block labels scoped %} |
67 | | - {#- Labels block. |
68 | | -
|
69 | | - This block renders the labels for the attribute. |
70 | | - -#} |
71 | | - {% with labels = attribute.labels %} |
72 | | - {% include "labels.html.jinja" with context %} |
73 | | - {% endwith %} |
74 | | - {% endblock labels %} |
75 | | - |
76 | | - {% endfilter %} |
77 | | - |
78 | | - {% block signature scoped %} |
79 | | - {#- Signature block. |
80 | | -
|
81 | | - This block renders the signature for the attribute. |
82 | | - -#} |
83 | | - {% if config.separate_signature %} |
84 | | - {% filter format_attribute(attribute, config.line_length, crossrefs=config.signature_crossrefs, show_value=config.show_attribute_values) %} |
85 | | - {{ attribute.name }} |
86 | | - {% endfilter %} |
87 | | - {% endif %} |
88 | | - {% endblock signature %} |
89 | | - |
90 | | - {% else %} |
91 | | - |
92 | | - {% if config.show_root_toc_entry %} |
93 | | - {% filter heading(heading_level, |
94 | | - role="data" if attribute.parent.kind.value == "module" else "attr", |
95 | | - id=html_id, |
96 | | - toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-attribute"></code> '|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else attribute_name), |
97 | | - hidden=True, |
98 | | - skip_inventory=config.skip_local_inventory, |
99 | | - ) %} |
100 | | - {% endfilter %} |
101 | | - {% endif %} |
102 | | - {% set heading_level = heading_level - 1 %} |
103 | | - {% endif %} |
104 | | - |
105 | | - <div class="doc doc-contents {% if root %}first{% endif %}"> |
106 | | - {% block contents scoped %} |
107 | | - {#- Contents block. |
108 | | -
|
109 | | - This block renders the contents of the attribute. |
110 | | - It contains other blocks that users can override. |
111 | | - Overriding the contents block allows to rearrange the order of the blocks. |
112 | | - -#} |
113 | | - {% block docstring scoped %} |
114 | | - {#- Docstring block. |
115 | | -
|
116 | | - This block renders the docstring for the attribute. |
117 | | - -#} |
118 | | - {% with docstring_sections = attribute.docstring.parsed %} |
119 | | - {% include "docstring.html.jinja" with context %} |
120 | | - {% endwith %} |
121 | | - {% endblock docstring %} |
122 | | - |
123 | | - {% if config.backlinks %} |
124 | | - <backlinks identifier="{{ html_id }}" handler="python" /> |
125 | | - {% endif %} |
126 | | - {% endblock contents %} |
127 | | - </div> |
128 | | - |
129 | | - {% endwith %} |
130 | | -</div> |
| 8 | + {% if config.show_symbol_type_heading %}<code class="doc-symbol doc-symbol-heading doc-symbol-attribute"></code>{% endif %} |
| 9 | + {% if config.heading and root %} |
| 10 | + {{ config.heading }} |
| 11 | + {% elif config.separate_signature %} |
| 12 | + <span class="doc doc-object-name doc-attribute-name">{{ attribute_name }} ({{ attribute.extra.griffe_pydantic.alias }})</span> |
| 13 | + {% else %} |
| 14 | + {%+ filter highlight(language="python", inline=True) %} |
| 15 | + {{ attribute_name }}{% if attribute.annotation and config.show_signature_annotations %}: {{ attribute.annotation }}{% endif %} |
| 16 | + {% if config.show_attribute_values and attribute.value %} = {{ attribute.value }}{% endif %} |
| 17 | + {% endfilter %} |
| 18 | + {% endif %} |
| 19 | +{% endblock heading %} |
0 commit comments