Skip to content

Commit 58031de

Browse files
committed
feat(doc): add jinja template
1 parent 32e6510 commit 58031de

File tree

14 files changed

+975
-110
lines changed

14 files changed

+975
-110
lines changed

docs/_templates/autoapi/index.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
API Reference
2+
=============
3+
4+
This page contains auto-generated API reference documentation [#f1]_.
5+
6+
.. toctree::
7+
:titlesonly:
8+
9+
{% for page in pages|selectattr("is_top_level_object") %}
10+
{{ page.include_path }}
11+
{% endfor %}
12+
13+
.. [#f1] Created with `sphinx-autoapi <https://github.com/readthedocs/sphinx-autoapi>`_

docs/_templates/autoapi/macros.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% import 'macros.rst' as macros %}
2+
{% macro auto_summary(objs, title='') -%}
3+
4+
.. list-table:: {{ title }}
5+
:header-rows: 0
6+
:widths: auto
7+
8+
{% for obj in objs %}
9+
* - obj.name
10+
- obj.summary
11+
{% endfor %}
12+
{% endmacro %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% extends "python/data.rst" %}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{% import 'macros.rst' as macros %}
2+
{% if obj.display %}
3+
{% if is_own_page %}
4+
{{ obj.id }}
5+
{{ "=" * obj.id | length }}
6+
7+
{% endif %}
8+
{% set visible_children = obj.children|selectattr("display")|list %}
9+
{% set own_page_children = visible_children|selectattr("type", "in", own_page_types)|list %}
10+
{% if is_own_page and own_page_children %}
11+
.. toctree::
12+
:hidden:
13+
14+
{% for child in own_page_children %}
15+
{{ child.include_path }}
16+
{% endfor %}
17+
18+
{% endif %}
19+
.. py:{{ obj.type }}:: {% if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}{% if obj.args %}({{ obj.args }}){% endif %}
20+
21+
{% for (args, return_annotation) in obj.overloads %}
22+
{{ " " * (obj.type | length) }} {{ obj.short_name }}{% if args %}({{ args }}){% endif %}
23+
24+
{% endfor %}
25+
{% if obj.bases %}
26+
{% if "show-inheritance" in autoapi_options %}
27+
28+
Bases: {% for base in obj.bases %}{{ base|link_objs }}{% if not loop.last %}, {% endif %}{% endfor %}
29+
{% endif %}
30+
31+
32+
{% if "show-inheritance-diagram" in autoapi_options and obj.bases != ["object"] %}
33+
.. autoapi-inheritance-diagram:: {{ obj.obj["full_name"] }}
34+
:parts: 1
35+
{% if "private-members" in autoapi_options %}
36+
:private-bases:
37+
{% endif %}
38+
39+
{% endif %}
40+
{% endif %}
41+
{% if obj.docstring %}
42+
43+
{{ obj.docstring|indent(3) }}
44+
{% endif %}
45+
{% for obj_item in visible_children %}
46+
{% if obj_item.type not in own_page_types %}
47+
48+
{{ obj_item.render()|indent(3) }}
49+
{% endif %}
50+
{% endfor %}
51+
{% if is_own_page and own_page_children %}
52+
{% set visible_attributes = own_page_children|selectattr("type", "equalto", "attribute")|list %}
53+
{% if visible_attributes %}
54+
Attributes
55+
----------
56+
57+
.. autoapisummary::
58+
59+
{% for attribute in visible_attributes %}
60+
{{ attribute.id }}
61+
{% endfor %}
62+
63+
64+
{% endif %}
65+
{% set visible_exceptions = own_page_children|selectattr("type", "equalto", "exception")|list %}
66+
{% if visible_exceptions %}
67+
Exceptions
68+
----------
69+
70+
.. autoapisummary::
71+
72+
{% for exception in visible_exceptions %}
73+
{{ exception.id }}
74+
{% endfor %}
75+
76+
77+
{% endif %}
78+
{% set visible_classes = own_page_children|selectattr("type", "equalto", "class")|list %}
79+
{% if visible_classes %}
80+
Classes
81+
-------
82+
83+
.. autoapisummary::
84+
85+
{{ macros.auto_summary(visible_classes, title="Classes") }}
86+
87+
88+
{% endif %}
89+
{% set visible_methods = own_page_children|selectattr("type", "equalto", "method")|list %}
90+
{% if visible_methods %}
91+
Methods
92+
-------
93+
94+
.. autoapisummary::
95+
96+
{% for method in visible_methods %}
97+
{{ method.id }}
98+
{% endfor %}
99+
100+
101+
{% endif %}
102+
{% endif %}
103+
{% endif %}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{% if obj.display %}
2+
{% if is_own_page %}
3+
{{ obj.id }}
4+
{{ "=" * obj.id | length }}
5+
6+
{% endif %}
7+
.. py:{{ obj.type }}:: {% if is_own_page %}{{ obj.id }}{% else %}{{ obj.name }}{% endif %}
8+
{% if obj.annotation is not none %}
9+
10+
:type: {% if obj.annotation %} {{ obj.annotation }}{% endif %}
11+
{% endif %}
12+
{% if obj.value is not none %}
13+
14+
{% if obj.value.splitlines()|count > 1 %}
15+
:value: Multiline-String
16+
17+
.. raw:: html
18+
19+
<details><summary>Show Value</summary>
20+
21+
.. code-block:: python
22+
23+
{{ obj.value|indent(width=6,blank=true) }}
24+
25+
.. raw:: html
26+
27+
</details>
28+
29+
{% else %}
30+
:value: {{ obj.value|truncate(100) }}
31+
{% endif %}
32+
{% endif %}
33+
34+
{% if obj.docstring %}
35+
36+
{{ obj.docstring|indent(3) }}
37+
{% endif %}
38+
{% endif %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% extends "python/class.rst" %}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% if obj.display %}
2+
{% if is_own_page %}
3+
{{ obj.id }}
4+
{{ "=" * obj.id | length }}
5+
6+
{% endif %}
7+
.. py:function:: {% if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}({{ obj.args }}){% if obj.return_annotation is not none %} -> {{ obj.return_annotation }}{% endif %}
8+
{% for (args, return_annotation) in obj.overloads %}
9+
10+
{%+ if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}({{ args }}){% if return_annotation is not none %} -> {{ return_annotation }}{% endif %}
11+
{% endfor %}
12+
{% for property in obj.properties %}
13+
14+
:{{ property }}:
15+
{% endfor %}
16+
17+
{% if obj.docstring %}
18+
19+
{{ obj.docstring|indent(3) }}
20+
{% endif %}
21+
{% endif %}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% if obj.display %}
2+
{% if is_own_page %}
3+
{{ obj.id }}
4+
{{ "=" * obj.id | length }}
5+
6+
{% endif %}
7+
.. py:method:: {% if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}({{ obj.args }}){% if obj.return_annotation is not none %} -> {{ obj.return_annotation }}{% endif %}
8+
{% for (args, return_annotation) in obj.overloads %}
9+
10+
{%+ if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}({{ args }}){% if return_annotation is not none %} -> {{ return_annotation }}{% endif %}
11+
{% endfor %}
12+
{% for property in obj.properties %}
13+
14+
:{{ property }}:
15+
{% endfor %}
16+
17+
{% if obj.docstring %}
18+
19+
{{ obj.docstring|indent(3) }}
20+
{% endif %}
21+
{% endif %}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{% import 'macros.rst' as macros %}
2+
{% if obj.display %}
3+
{% if is_own_page %}
4+
{{ obj.id }}
5+
{{ "=" * obj.id|length }}
6+
7+
.. py:module:: {{ obj.name }}
8+
9+
{% if obj.docstring %}
10+
.. autoapi-nested-parse::
11+
12+
{{ obj.docstring|indent(3) }}
13+
14+
{% endif %}
15+
16+
{% block submodules %}
17+
{% set visible_subpackages = obj.subpackages|selectattr("display")|list %}
18+
{% set visible_submodules = obj.submodules|selectattr("display")|list %}
19+
{% set visible_submodules = (visible_subpackages + visible_submodules)|sort %}
20+
{% if visible_submodules %}
21+
Submodules
22+
----------
23+
24+
.. toctree::
25+
:maxdepth: 1
26+
27+
{% for submodule in visible_submodules %}
28+
{{ submodule.include_path }}
29+
{% endfor %}
30+
31+
32+
{% endif %}
33+
{% endblock %}
34+
{% block content %}
35+
{% set visible_children = obj.children|selectattr("display")|list %}
36+
{% if visible_children %}
37+
{% set visible_attributes = visible_children|selectattr("type", "equalto", "data")|list %}
38+
{% if visible_attributes %}
39+
{% if "attribute" in own_page_types or "show-module-summary" in autoapi_options %}
40+
Attributes
41+
----------
42+
43+
{% if "attribute" in own_page_types %}
44+
.. toctree::
45+
:hidden:
46+
47+
{% for attribute in visible_attributes %}
48+
{{ attribute.include_path }}
49+
{% endfor %}
50+
51+
{% endif %}
52+
.. autoapisummary::
53+
54+
{% for attribute in visible_attributes %}
55+
{{ attribute.id }}
56+
{% endfor %}
57+
{% endif %}
58+
59+
60+
{% endif %}
61+
{% set visible_exceptions = visible_children|selectattr("type", "equalto", "exception")|list %}
62+
{% if visible_exceptions %}
63+
{% if "exception" in own_page_types or "show-module-summary" in autoapi_options %}
64+
Exceptions
65+
----------
66+
67+
{% if "exception" in own_page_types %}
68+
.. toctree::
69+
:hidden:
70+
71+
{% for exception in visible_exceptions %}
72+
{{ exception.include_path }}
73+
{% endfor %}
74+
75+
{% endif %}
76+
.. autoapisummary::
77+
78+
{% for exception in visible_exceptions %}
79+
{{ exception.id }}
80+
{% endfor %}
81+
{% endif %}
82+
83+
84+
{% endif %}
85+
{% set visible_classes = visible_children|selectattr("type", "equalto", "class")|list %}
86+
{% if visible_classes %}
87+
{% if "class" in own_page_types or "show-module-summary" in autoapi_options %}
88+
Classes
89+
-------
90+
91+
{% if "class" in own_page_types %}
92+
.. toctree::
93+
:hidden:
94+
95+
{{ macros.auto_summary(visible_classes, title="Classes") }}
96+
97+
{% endif %}
98+
.. autoapisummary::
99+
100+
{{ macros.auto_summary(visible_classes, title="Classes") }}
101+
{% endif %}
102+
103+
104+
{% endif %}
105+
{% set visible_functions = visible_children|selectattr("type", "equalto", "function")|list %}
106+
{% if visible_functions %}
107+
{% if "function" in own_page_types or "show-module-summary" in autoapi_options %}
108+
Functions
109+
---------
110+
111+
{% if "function" in own_page_types %}
112+
.. toctree::
113+
:hidden:
114+
115+
{% for function in visible_functions %}
116+
{{ function.include_path }}
117+
{% endfor %}
118+
119+
{% endif %}
120+
.. autoapisummary::
121+
122+
{% for function in visible_functions %}
123+
{{ function.id }}
124+
{% endfor %}
125+
{% endif %}
126+
127+
128+
{% endif %}
129+
{% set this_page_children = visible_children|rejectattr("type", "in", own_page_types)|list %}
130+
{% if this_page_children %}
131+
{{ obj.type|title }} Contents
132+
{{ "-" * obj.type|length }}---------
133+
134+
{% for obj_item in this_page_children %}
135+
{{ obj_item.render()|indent(0) }}
136+
{% endfor %}
137+
{% endif %}
138+
{% endif %}
139+
{% endblock %}
140+
{% else %}
141+
.. py:module:: {{ obj.name }}
142+
143+
{% if obj.docstring %}
144+
.. autoapi-nested-parse::
145+
146+
{{ obj.docstring|indent(6) }}
147+
148+
{% endif %}
149+
{% for obj_item in visible_children %}
150+
{{ obj_item.render()|indent(3) }}
151+
{% endfor %}
152+
{% endif %}
153+
{% endif %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% extends "python/module.rst" %}

0 commit comments

Comments
 (0)