{# Autodoc Header Partial Renders the header section: badges, title, description, stats, source link. Works for all autodoc types (Python, CLI, OpenAPI). Required: element (DocElement) Optional: show_stats (bool, default true), show_source (bool, default true) #} {% let show_stats = show_stats ?? true, show_source = show_source ?? true, meta = element?.metadata ?? {}, children = element?.children ?? [] %}
{# Badges #} {% let badges = [] %} {% if meta?.is_deprecated %}{% set _ = badges.append('deprecated') %}{% end %} {% if meta?.is_async %}{% set _ = badges.append('async') %}{% end %} {% if meta?.is_abstract %}{% set _ = badges.append('abstract') %}{% end %} {% if meta?.is_dataclass %}{% set _ = badges.append('dataclass') %}{% end %} {% if meta?.is_classmethod %}{% set _ = badges.append('classmethod') %}{% end %} {% if meta?.is_staticmethod %}{% set _ = badges.append('staticmethod') %}{% end %} {% if meta?.is_property %}{% set _ = badges.append('property') %}{% end %} {% if badges | length > 0 %}
{% for badge in badges %} {{ badge | title }} {% end %}
{% end %} {# Title #}

{% with meta?.method as method %} {% if element?.element_type == 'endpoint' and method %} {{ method | upper }} {% end %} {% end %} {{ element?.qualified_name ?? element?.name }}

{# Description #} {% if element?.description %}
{{ element.description | markdownify | safe }}
{% end %} {# Stats row #} {% if show_stats %} {% let stat_config = [ {'type': 'option', 'label': 'Options'}, {'type': 'argument', 'label': 'Arguments'}, {'type': 'method', 'label': 'Methods'}, {'type': 'function', 'label': 'Functions'}, {'type': 'class', 'label': 'Classes'}, {'type': 'attribute', 'label': 'Attributes'} ] %} {% let stats = [] %} {% for item in stat_config %} {% let count = children |> selectattr('element_type', 'eq', item.type) |> list |> length %} {% if count > 0 %} {% set _ = stats.append({'value': count, 'label': item.label}) %} {% end %} {% end %} {# Subcommands (command or command-group) #} {% let subcommands_count = children |> selectattr('element_type', 'match', '^command(-group)?$') |> list |> length %} {% if subcommands_count > 0 %} {% set _ = stats.append({'value': subcommands_count, 'label': 'Subcommands'}) %} {% end %} {# Parameters #} {% let parameters = meta?.args ?? meta?.parameters ?? [] %} {% if parameters | length > 0 %} {% set _ = stats.append({'value': parameters | length, 'label': 'Parameters'}) %} {% end %} {% if stats | length > 0 %}
{% for stat in stats %} {{ stat.value }} {{ stat.label }} {% end %}
{% end %} {% end %} {# Source link - build the GitHub blob URL inline from `config` (see #441). The old template read `meta?.source_url`, which nothing ever populates, so every link fell back to '#'. We now resolve github_repo / github_branch the same way the autodoc config normalizer does: prefer the [autodoc] section, fall back to the top level, and expand `owner/repo` shorthand to a full URL. `config` may be a Config accessor (use its `.raw` dict for predictable `| get` semantics) or an already-normalized dict. #} {% let _cfg = config?.raw ?? config %} {% let _autodoc = _cfg | get('autodoc', {}) %} {% let _repo = (_autodoc | get('github_repo', '')) or (_cfg | get('github_repo', '')) %} {% let _repo = _repo | string %} {% let source_file = element?.display_source_file ?? element?.source_file %} {% if show_source and source_file and _repo %} {% let github_repo = _repo if _repo.startswith('http') else ('https://github.com/' ~ _repo) %} {% let _branch = (_autodoc | get('github_branch', '')) or (_cfg | get('github_branch', '')) %} {% let branch = (_branch | string) if _branch else 'main' %} {% let line_anchor = '#L' ~ element.line_number if element?.line_number else '' %} {% let source_url = github_repo ~ '/blob/' ~ branch ~ '/' ~ source_file ~ line_anchor %} View source {% end %}