new-horizons/docs/content/base/content.jinja2
2022-03-02 23:24:17 -05:00

121 lines
4.9 KiB
Django/Jinja

{% from "macro_restriction.jinja2" import restriction with context %}
{% macro tabbed_section(operator, current_node) %}
{% include "tabbed_section.jinja2" %}
{% endmacro %}
{% macro content(schema, skip_headers=False) %}
{% set keys = schema.keywords %}
{# Resolve type #}
{% set type_name = schema.type_name %}
{% if not skip_headers %}
{% if config.show_breadcrumbs %}
{% include "breadcrumbs.jinja2" %}
{% endif %}
{# Display type #}
{% if not schema is combining %}
<div class="row">
<div class="col">
<span class="badge bg-secondary">Type: {{ type_name }}</span>
</div>
</div>
{% endif %}
{# Display default #}
{% set default_value = schema.default_value %}
{% if default_value %}
<div class="row">
<div class="col">
{{ " " }}<span class="badge bg-secondary">Default: {{ default_value }}</span>
</div>
</div>
{% endif %}
<br/>
{% set description = (schema | get_description) %}
{% include "section_description.jinja2" %}
{% endif %}
{% if schema.should_be_a_link(config) %}
<a href="#{{ schema.links_to.html_id }}" onclick="anchorLink('{{ schema.links_to.html_id }}')" class="ref-link">Same definition as {{ schema.links_to.link_name }}</a>
{% elif schema.refers_to %}
{{ content(schema.refers_to_merged, True) }}
{% else %}
{# Handle having oneOf or allOf with only one condition #}
{% if schema.kw_all_of and (schema.kw_all_of.array_items | length) == 1 %}
{{ content(schema.kw_all_of.array_items[0]) }}
{% elif schema.kw_any_of and (schema.kw_any_of.array_items | length) == 1 %}
{{ content(schema.kw_any_of.array_items[0]) }}
{% else %}
{% if schema.explicit_no_additional_properties %}
{{ " " }}<span class="badge bg-info no-additional">No Additional Properties</span>
{% endif %}
{# Combining: allOf, anyOf, oneOf, not #}
{% if schema.kw_all_of %}
<div class="all-of-value" id="{{ schema.kw_all_of.html_id }}">{{ tabbed_section("allOf", schema.kw_all_of) }}</div>
{% endif %}
{% if schema.kw_any_of %}
<div class="any-of-value" id="{{ schema.kw_any_of.html_id }}">{{ tabbed_section("anyOf", schema.kw_any_of) }}</div>
{% endif %}
{% if schema.kw_one_of %}
<div class="one-of-value" id="{{ schema.kw_one_of.html_id }}">{{ tabbed_section("oneOf", schema.kw_one_of) }}</div>
{% endif %}
{% if schema.kw_not %}
{% include "section_not.jinja2" %}
{% endif %}
{# Enum and const #}
{% if schema.kw_enum %}
<div class="enum-value" id="{{ schema.kw_enum.html_id }}">
<h4>Must be one of:</h4>
<ul class="list-group">
{% for enum_choice in schema.kw_enum.array_items %}
<li class="list-group-item enum-item">{{ enum_choice.literal | python_to_json }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% if schema.kw_const %}
<span class="const-value" id="{{ schema.kw_const.html_id }}">Specific value: <code>{{ schema.kw_const.raw | python_to_json }}</code></span>
{% endif %}
{# Pattern (Regular Expression) #}
{% if schema.kw_pattern %}
<span class="pattern-value" id="{{ schema.kw_pattern.html_id }}">Must match regular expression: <code>{{ schema.kw_pattern.literal | escape }}</code></span>
{% endif %}
{# Conditional subschema, or if-then-else section #}
{% if schema.has_conditional %}
{% include "section_conditional_subschema.jinja2" %}
{% endif %}
{# Required properties that are not defined under "properties". They will only be listed #}
{% include "section_undocumented_required_properties.jinja2" %}
{# Show the requested type(s) #}
{% include "badge_type.jinja2" %}
{# Show array restrictions #}
{% if type_name.startswith("array") %}
{% include "section_array.jinja2" %}
{% endif %}
{# Display examples #}
{% set examples = schema.examples %}
{% if examples %}
{% include "section_examples.jinja2" %}
{% endif %}
{# Properties, pattern properties, additional properties #}
{% for sub_property in schema.iterate_properties %}
{% include "section_properties.jinja2" %}
{% endfor %}
{% endif %}
{% endif %}
{% endmacro %}