Skip to content

Commit

Permalink
refactor: Update *.html base templates to extend their `*.html.jinj…
Browse files Browse the repository at this point in the history
…a` counterpart, while overriding the `logs` block to issue a logging message (info) stating that extending `*.html` templates is deprecated

Issue-151: #151
  • Loading branch information
pawamoy committed Apr 28, 2024
1 parent 7c14924 commit e6f1b9c
Show file tree
Hide file tree
Showing 43 changed files with 460 additions and 1,804 deletions.
Original file line number Diff line number Diff line change
@@ -1,80 +1,11 @@
{{ log.debug("Rendering " + attribute.path) }}

<div class="doc doc-object doc-attribute">
{% with obj = attribute, html_id = attribute.path %}

{% if root %}
{% set show_full_path = config.show_root_full_path %}
{% set root_members = True %}
{% elif root_members %}
{% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %}
{% set root_members = False %}
{% else %}
{% set show_full_path = config.show_object_full_path %}
{% endif %}

{% set attribute_name = attribute.path if show_full_path else attribute.name %}

{% if not root or config.show_root_heading %}
{% filter heading(
heading_level,
role="data" if attribute.parent.kind.value == "module" else "attr",
id=html_id,
class="doc doc-heading",
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-attribute"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + attribute.name,
) %}

{% block heading scoped %}
{% if config.show_symbol_type_heading %}<code class="doc-symbol doc-symbol-heading doc-symbol-attribute"></code>{% endif %}
{% if config.separate_signature %}
<span class="doc doc-object-name doc-attribute-name">{{ attribute_name }}</span>
{% else %}
{%+ filter highlight(language="python", inline=True) %}
{{ attribute_name }}{% if attribute.annotation %}: {{ attribute.annotation }}{% endif %}
{% if attribute.value %} = {{ attribute.value }}{% endif %}
{% endfilter %}
{% endif %}
{% endblock heading %}

{% block labels scoped %}
{% with labels = attribute.labels %}
{% include "labels.html" with context %}
{% endwith %}
{% endblock labels %}

{% endfilter %}

{% block signature scoped %}
{% if config.separate_signature %}
{% filter format_attribute(attribute, config.line_length, crossrefs=config.signature_crossrefs) %}
{{ attribute.name }}
{% endfilter %}
{% endif %}
{% endblock signature %}

{% else %}

{% if config.show_root_toc_entry %}
{% filter heading(heading_level,
role="data" if attribute.parent.kind.value == "module" else "attr",
id=html_id,
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-attribute"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + attribute.name,
hidden=True,
) %}
{% endfilter %}
{% endif %}
{% set heading_level = heading_level - 1 %}
{% endif %}

<div class="doc doc-contents {% if root %}first{% endif %}">
{% block contents scoped %}
{% block docstring scoped %}
{% with docstring_sections = attribute.docstring.parsed %}
{% include "docstring.html" with context %}
{% endwith %}
{% endblock docstring %}
{% endblock contents %}
</div>

{% endwith %}
</div>
{% extends "_base/attribute.html.jinja" %}

{% block logs scoped %}
{{ super() }}
{# TODO: Switch to a warning after some time. #}
{{ log.info(
"DeprecationWarning: Extending '_base/attribute.html' is deprecated, extend '_base/attribute.html.jinja' instead. " ~
"After some time, this message will be logged as a warning, causing strict builds to fail.",
once=True,
) }}
{% endblock logs %}
165 changes: 11 additions & 154 deletions src/mkdocstrings_handlers/python/templates/material/_base/children.html
Original file line number Diff line number Diff line change
@@ -1,154 +1,11 @@
{% if obj.members %}
{{ log.debug("Rendering children of " + obj.path) }}

<div class="doc doc-children">

{% if root_members %}
{% set members_list = config.members %}
{% else %}
{% set members_list = none %}
{% endif %}

{% if config.group_by_category %}

{% with %}

{% if config.show_category_heading %}
{% set extra_level = 1 %}
{% else %}
{% set extra_level = 0 %}
{% endif %}

{% with attributes = obj.attributes|filter_objects(
filters=config.filters,
members_list=members_list,
inherited_members=config.inherited_members,
keep_no_docstrings=config.show_if_no_docstring,
) %}
{% if attributes %}
{% if config.show_category_heading %}
{% filter heading(heading_level, id=html_id ~ "-attributes") %}Attributes{% endfilter %}
{% endif %}
{% with heading_level = heading_level + extra_level %}
{% for attribute in attributes|order_members(config.members_order, members_list) %}
{% if members_list is not none or attribute.is_public(check_name=False) %}
{% include attribute|get_template with context %}
{% endif %}
{% endfor %}
{% endwith %}
{% endif %}
{% endwith %}

{% with classes = obj.classes|filter_objects(
filters=config.filters,
members_list=members_list,
inherited_members=config.inherited_members,
keep_no_docstrings=config.show_if_no_docstring,
) %}
{% if classes %}
{% if config.show_category_heading %}
{% filter heading(heading_level, id=html_id ~ "-classes") %}Classes{% endfilter %}
{% endif %}
{% with heading_level = heading_level + extra_level %}
{% for class in classes|order_members(config.members_order, members_list) %}
{% if members_list is not none or class.is_public(check_name=False) %}
{% include class|get_template with context %}
{% endif %}
{% endfor %}
{% endwith %}
{% endif %}
{% endwith %}

{% with functions = obj.functions|filter_objects(
filters=config.filters,
members_list=members_list,
inherited_members=config.inherited_members,
keep_no_docstrings=config.show_if_no_docstring,
) %}
{% if functions %}
{% if config.show_category_heading %}
{% filter heading(heading_level, id=html_id ~ "-functions") %}Functions{% endfilter %}
{% endif %}
{% with heading_level = heading_level + extra_level %}
{% for function in functions|order_members(config.members_order, members_list) %}
{% if not (obj.kind.value == "class" and function.name == "__init__" and config.merge_init_into_class) %}
{% if members_list is not none or function.is_public(check_name=False) %}
{% include function|get_template with context %}
{% endif %}
{% endif %}
{% endfor %}
{% endwith %}
{% endif %}
{% endwith %}

{% if config.show_submodules %}
{% with modules = obj.modules|filter_objects(
filters=config.filters,
members_list=members_list,
inherited_members=config.inherited_members,
keep_no_docstrings=config.show_if_no_docstring,
) %}
{% if modules %}
{% if config.show_category_heading %}
{% filter heading(heading_level, id=html_id ~ "-modules") %}Modules{% endfilter %}
{% endif %}
{% with heading_level = heading_level + extra_level %}
{% for module in modules|order_members(config.members_order.alphabetical, members_list) %}
{% if members_list is not none or module.is_public(check_name=False) %}
{% include module|get_template with context %}
{% endif %}
{% endfor %}
{% endwith %}
{% endif %}
{% endwith %}
{% endif %}

{% endwith %}

{% else %}

{% for child in obj.all_members
|filter_objects(
filters=config.filters,
members_list=members_list,
inherited_members=config.inherited_members,
keep_no_docstrings=config.show_if_no_docstring,
)
|order_members(config.members_order, members_list)
%}

{% if not (obj.is_class and child.name == "__init__" and config.merge_init_into_class) %}

{% if members_list is not none or child.is_public(check_name=False) %}
{% if child.is_attribute %}
{% with attribute = child %}
{% include attribute|get_template with context %}
{% endwith %}

{% elif child.is_class %}
{% with class = child %}
{% include class|get_template with context %}
{% endwith %}

{% elif child.is_function %}
{% with function = child %}
{% include function|get_template with context %}
{% endwith %}

{% elif child.is_module and config.show_submodules %}
{% with module = child %}
{% include module|get_template with context %}
{% endwith %}

{% endif %}
{% endif %}

{% endif %}

{% endfor %}

{% endif %}

</div>

{% endif %}
{% extends "_base/children.html.jinja" %}

{% block logs scoped %}
{{ super() }}
{# TODO: Switch to a warning after some time. #}
{{ log.info(
"DeprecationWarning: Extending '_base/children.html' is deprecated, extend '_base/children.html.jinja' instead. " ~
"After some time, this message will be logged as a warning, causing strict builds to fail.",
once=True,
) }}
{% endblock logs %}
Loading

0 comments on commit e6f1b9c

Please sign in to comment.