Skip to content

Commit 49fcd56

Browse files
committed
feat: Suffix templates with jinja extension, add templates for enum, enum member, class and constructor
Issue-3: #3 Issue-4: #4
1 parent 3895e88 commit 49fcd56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+524
-255
lines changed

src/mkdocstrings_handlers/typescript/handler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def render(self, data: CollectorItem, config: Mapping[str, Any]) -> str:
146146
"""
147147
final_config = {**self.default_config, **config}
148148
heading_level = final_config["heading_level"]
149-
template = self.env.get_template("module.html")
149+
template = self.env.get_template("module.html.jinja")
150150
return template.render(
151151
config=final_config,
152152
module=data,

src/mkdocstrings_handlers/typescript/templates/material/_base/children.html src/mkdocstrings_handlers/typescript/templates/material/_base/children.html.jinja

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{{ log.debug("Rendering children of " + obj.path) }}
55
<div class="doc doc-children">
66
{% for obj in children %}
7-
{% include "dispatch.html" with context %}
7+
{% include "dispatch.html.jinja" with context %}
88
{% endfor %}
99
</div>
1010
{% endif %}
@@ -15,15 +15,15 @@
1515
{% for group in obj.resolved_groups %}
1616
<b>{{ group.title }}</b>
1717
{% for obj in group.children %}
18-
{% include "dispatch.html" with context %}
18+
{% include "dispatch.html.jinja" with context %}
1919
{% endfor %}
2020
{% endfor %}
2121
</div>
2222
{% elif obj.children %}
2323
{{ log.debug("Rendering children of " + obj.path) }}
2424
<div class="doc doc-children">
2525
{% for obj in obj.children %}
26-
{% include "dispatch.html" with context %}
26+
{% include "dispatch.html.jinja" with context %}
2727
{% endfor %}
2828
</div>
2929
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{{ log.debug("Rendering " + class.path) }}
2+
3+
<div class="doc doc-object doc-class">
4+
{% with obj = class, html_id = class.path %}
5+
6+
{% if root %}
7+
{% set show_full_path = config.show_root_full_path %}
8+
{% set root_members = True %}
9+
{% elif root_members %}
10+
{% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %}
11+
{% set root_members = False %}
12+
{% else %}
13+
{% set show_full_path = config.show_object_full_path %}
14+
{% endif %}
15+
16+
{% set class_name = class.path if show_full_path else class.name %}
17+
18+
{% if not root or config.show_root_heading %}
19+
{% filter heading(
20+
heading_level,
21+
role="class",
22+
id=html_id,
23+
class="doc doc-heading",
24+
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-class"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + class.name,
25+
) %}
26+
27+
{% block heading scoped %}
28+
{% if config.show_symbol_type_heading %}<code class="doc-symbol doc-symbol-heading doc-symbol-class"></code>{% endif %}
29+
{% if config.separate_signature %}
30+
<span class="doc doc-object-name doc-class-name">{{ class_name }}</span>
31+
{% else %}
32+
<code>{{ class_name }}</code>
33+
{% endif %}
34+
{% endblock heading %}
35+
36+
{% endfilter %}
37+
38+
{% else %}
39+
{% if config.show_root_toc_entry %}
40+
{% filter heading(heading_level,
41+
role="class",
42+
id=html_id,
43+
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-class"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + class.name,
44+
hidden=True,
45+
) %}
46+
{% endfilter %}
47+
{% endif %}
48+
{% set heading_level = heading_level - 1 %}
49+
{% endif %}
50+
51+
<div class="doc doc-contents {% if root %}first{% endif %}">
52+
{% block contents scoped %}
53+
{% block docstring scoped %}
54+
{% if class.comment %}
55+
{{ class.comment.markdown|convert_markdown(heading_level, html_id) }}
56+
{% endif %}
57+
{% endblock docstring %}
58+
{% block children scoped %}
59+
{% set root = False %}
60+
{% set heading_level = heading_level + 1 %}
61+
{% include "children.html.jinja" with context %}
62+
{% endblock children %}
63+
{% endblock contents %}
64+
</div>
65+
66+
{% endwith %}
67+
</div>
68+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{{ log.debug("Rendering " + constructor.path) }}
2+
3+
<div class="doc doc-object doc-constructor">
4+
{% with obj = constructor, html_id = constructor.path %}
5+
6+
{% if root %}
7+
{% set show_full_path = config.show_root_full_path %}
8+
{% set root_members = True %}
9+
{% elif root_members %}
10+
{% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %}
11+
{% set root_members = False %}
12+
{% else %}
13+
{% set show_full_path = config.show_object_full_path %}
14+
{% endif %}
15+
16+
{% set constructor_name = constructor.path if show_full_path else constructor.name %}
17+
18+
{% if not root or config.show_root_heading %}
19+
{% filter heading(
20+
heading_level,
21+
role="constructor",
22+
id=html_id,
23+
class="doc doc-heading",
24+
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-constructor"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + constructor.name,
25+
) %}
26+
27+
{% block heading scoped %}
28+
{% if config.show_symbol_type_heading %}<code class="doc-symbol doc-symbol-heading doc-symbol-constructor"></code>{% endif %}
29+
{% if config.separate_signature %}
30+
<span class="doc doc-object-name doc-constructor-name">{{ constructor_name }}</span>
31+
{% else %}
32+
<code>{{ constructor_name }}</code>
33+
{% endif %}
34+
{% endblock heading %}
35+
36+
{% endfilter %}
37+
38+
{% else %}
39+
{% if config.show_root_toc_entry %}
40+
{% filter heading(heading_level,
41+
role="constructor",
42+
id=html_id,
43+
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-constructor"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + constructor.name,
44+
hidden=True,
45+
) %}
46+
{% endfilter %}
47+
{% endif %}
48+
{% set heading_level = heading_level - 1 %}
49+
{% endif %}
50+
51+
<div class="doc doc-contents {% if root %}first{% endif %}">
52+
{% block contents scoped %}
53+
{% block docstring scoped %}
54+
{% if constructor.comment %}
55+
{{ constructor.comment.markdown|convert_markdown(heading_level, html_id) }}
56+
{% endif %}
57+
{% endblock docstring %}
58+
{% block children scoped %}
59+
{% set root = False %}
60+
{% set heading_level = heading_level + 1 %}
61+
{% include "children.html.jinja" with context %}
62+
{% endblock children %}
63+
{% endblock contents %}
64+
</div>
65+
66+
{% endwith %}
67+
</div>
68+
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,94 @@
11
{{ log.debug("Dispatching " ~ obj.kind.value) }}
22
{% if obj.kind.value == "project" %}
33
{% with project = obj %}
4-
{% include "project.html" with context %}
4+
{% include "project.html.jinja" with context %}
55
{% endwith %}
66
{% elif obj.kind.value == "module" and config.show_submodules %}
77
{% with module = obj %}
8-
{% include "module.html" with context %}
8+
{% include "module.html.jinja" with context %}
99
{% endwith %}
1010
{% elif obj.kind.value == "namespace" %}
1111
{% with namespace = obj %}
12-
{% include "namespace.html" with context %}
12+
{% include "namespace.html.jinja" with context %}
1313
{% endwith %}
1414
{% elif obj.kind.value == "enum" %}
1515
{% with enum = obj %}
16-
{% include "enum.html" with context %}
16+
{% include "enum.html.jinja" with context %}
1717
{% endwith %}
1818
{% elif obj.kind.value == "enum_member" %}
1919
{% with enum_member = obj %}
20-
{% include "enum_member.html" with context %}
20+
{% include "enum_member.html.jinja" with context %}
2121
{% endwith %}
2222
{% elif obj.kind.value == "variable" %}
2323
{% with variable = obj %}
24-
{% include "variable.html" with context %}
24+
{% include "variable.html.jinja" with context %}
2525
{% endwith %}
2626
{% elif obj.kind.value == "function" %}
2727
{% with function = obj %}
28-
{% include "function.html" with context %}
28+
{% include "function.html.jinja" with context %}
2929
{% endwith %}
3030
{% elif obj.kind.value == "class" %}
3131
{% with class = obj %}
32-
{% include "class.html" with context %}
32+
{% include "class.html.jinja" with context %}
3333
{% endwith %}
3434
{% elif obj.kind.value == "interface" %}
3535
{% with interface = obj %}
36-
{% include "interface.html" with context %}
36+
{% include "interface.html.jinja" with context %}
3737
{% endwith %}
3838
{% elif obj.kind.value == "constructor" %}
3939
{% with constructor = obj %}
40-
{% include "constructor.html" with context %}
40+
{% include "constructor.html.jinja" with context %}
4141
{% endwith %}
4242
{% elif obj.kind.value == "property" %}
4343
{% with property = obj %}
44-
{% include "property.html" with context %}
44+
{% include "property.html.jinja" with context %}
4545
{% endwith %}
4646
{% elif obj.kind.value == "method" %}
4747
{% with method = obj %}
48-
{% include "method.html" with context %}
48+
{% include "method.html.jinja" with context %}
4949
{% endwith %}
5050
{% elif obj.kind.value == "call_signature" %}
5151
{% with call_signature = obj %}
52-
{% include "call_signature.html" with context %}
52+
{% include "call_signature.html.jinja" with context %}
5353
{% endwith %}
5454
{% elif obj.kind.value == "index_signature" %}
5555
{% with index_signature = obj %}
56-
{% include "index_signature.html" with context %}
56+
{% include "index_signature.html.jinja" with context %}
5757
{% endwith %}
5858
{% elif obj.kind.value == "constructor_signature" %}
5959
{% with constructor_signature = obj %}
60-
{% include "constructor_signature.html" with context %}
60+
{% include "constructor_signature.html.jinja" with context %}
6161
{% endwith %}
6262
{% elif obj.kind.value == "parameter" %}
6363
{% with parameter = obj %}
64-
{% include "parameter.html" with context %}
64+
{% include "parameter.html.jinja" with context %}
6565
{% endwith %}
6666
{% elif obj.kind.value == "type_literal" %}
6767
{% with type_literal = obj %}
68-
{% include "type_literal.html" with context %}
68+
{% include "type_literal.html.jinja" with context %}
6969
{% endwith %}
7070
{% elif obj.kind.value == "type_parameter" %}
7171
{% with type_parameter = obj %}
72-
{% include "type_parameter.html" with context %}
72+
{% include "type_parameter.html.jinja" with context %}
7373
{% endwith %}
7474
{% elif obj.kind.value == "accessor" %}
7575
{% with accessor = obj %}
76-
{% include "accessor.html" with context %}
76+
{% include "accessor.html.jinja" with context %}
7777
{% endwith %}
7878
{% elif obj.kind.value == "get_signature" %}
7979
{% with get_signature = obj %}
80-
{% include "get_signature.html" with context %}
80+
{% include "get_signature.html.jinja" with context %}
8181
{% endwith %}
8282
{% elif obj.kind.value == "set_signature" %}
8383
{% with set_signature = obj %}
84-
{% include "set_signature.html" with context %}
84+
{% include "set_signature.html.jinja" with context %}
8585
{% endwith %}
8686
{% elif obj.kind.value == "type_alias" %}
8787
{% with type_alias = obj %}
88-
{% include "type_alias.html" with context %}
88+
{% include "type_alias.html.jinja" with context %}
8989
{% endwith %}
9090
{% elif obj.kind.value == "reference" %}
9191
{% with reference = obj %}
92-
{% include "reference.html" with context %}
92+
{% include "reference.html.jinja" with context %}
9393
{% endwith %}
9494
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{{ log.debug("Rendering " + enum.path) }}
2+
3+
<div class="doc doc-object doc-enum">
4+
{% with obj = enum, html_id = enum.path %}
5+
6+
{% if root %}
7+
{% set show_full_path = config.show_root_full_path %}
8+
{% set root_members = True %}
9+
{% elif root_members %}
10+
{% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %}
11+
{% set root_members = False %}
12+
{% else %}
13+
{% set show_full_path = config.show_object_full_path %}
14+
{% endif %}
15+
16+
{% set enum_name = enum.path if show_full_path else enum.name %}
17+
18+
{% if not root or config.show_root_heading %}
19+
{% filter heading(
20+
heading_level,
21+
role="enum",
22+
id=html_id,
23+
class="doc doc-heading",
24+
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-enum"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + enum.name,
25+
) %}
26+
27+
{% block heading scoped %}
28+
{% if config.show_symbol_type_heading %}<code class="doc-symbol doc-symbol-heading doc-symbol-enum"></code>{% endif %}
29+
{% if config.separate_signature %}
30+
<span class="doc doc-object-name doc-enum-name">{{ enum_name }}</span>
31+
{% else %}
32+
<code>{{ enum_name }}</code>
33+
{% endif %}
34+
{% endblock heading %}
35+
36+
{% endfilter %}
37+
38+
{% else %}
39+
{% if config.show_root_toc_entry %}
40+
{% filter heading(heading_level,
41+
role="enum",
42+
id=html_id,
43+
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-enum"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + enum.name,
44+
hidden=True,
45+
) %}
46+
{% endfilter %}
47+
{% endif %}
48+
{% set heading_level = heading_level - 1 %}
49+
{% endif %}
50+
51+
<div class="doc doc-contents {% if root %}first{% endif %}">
52+
{% block contents scoped %}
53+
{% block docstring scoped %}
54+
{% if enum.comment %}
55+
{{ enum.comment.markdown|convert_markdown(heading_level, html_id) }}
56+
{% endif %}
57+
{% endblock docstring %}
58+
{% block children scoped %}
59+
{% set root = False %}
60+
{% set heading_level = heading_level + 1 %}
61+
{% include "children.html.jinja" with context %}
62+
{% endblock children %}
63+
{% endblock contents %}
64+
</div>
65+
66+
{% endwith %}
67+
</div>
68+

0 commit comments

Comments
 (0)