{# Function Member Macro Renders a function as a collapsible card with status dot, param count, and return type. Uses the unified autodoc design system. Usage: {% from 'autodoc/partials/_macros/function-member.html' import function_member %} {{ function_member(func, is_first=loop.first) }} Args: func: Function DocElement to render (required) is_first: Whether this is the first item (to auto-open) #} {% macro function_member(func, is_first=false) %} {# Parameters can be in metadata.args (from extractor) or metadata.parameters #} {% set func_params = func.metadata.args or func.metadata.parameters or [] %} {% set func_return = func.metadata.return_type or func.metadata.returns or '' %} {% set func_signature = func.metadata.signature or '' %} {% set is_async = func.metadata.is_async | default(false) %}
{# Status dot (green for functions) #} {# Content wrapper #}
{{ func.name }} {# Parameter count badge #} {{ func_params | length }} {# Return type with arrow #} {% if func_return %} {{ func_return | truncate(25, True, '…') }} {% endif %} {# Toggle indicator #}
{# Description preview (for scanning) #} {% if func.description %} {{ func.description | striptags | truncate(80, True, '…') }} {% endif %}
{# Badges #} {% if is_async %} async {% endif %}
{# Signature (copy-paste ready) #} {% if func_signature %}
{{ func_signature }}
{% endif %} {# Full description - only show if truncated in header #} {% set desc_stripped = func.description | striptags | trim if func.description else '' %} {% if func.description and desc_stripped | length > 77 %}
{{ func.description | markdownify | safe }}
{% endif %} {# Function parameters - args is a list of dicts with name, type, docstring, default #} {% if func_params %}
Parameters
{% for param in func_params %} {# Handle both dict and object access patterns #} {% set param_name = param.get('name', '') if param.get else (param.name if param.name is defined else '') %} {% set param_type = param.get('type', '') if param.get else (param.type if param.type is defined else '') %} {# docstring is the description from parsed docstring #} {% set param_desc = param.get('docstring', '') if param.get else (param.docstring if param.docstring is defined else '') %} {% set param_default = param.get('default') if param.get else (param.default if param.default is defined else none) %} {% endfor %}
Name Type Description
{{ param_name }} {{ param_type or '—' }} {{ param_desc | markdownify | safe }} {% if param_default is not none and param_default != '' %} Default: {{ param_default }} {% endif %}
{% endif %} {# Return type (detailed) - only show if has description OR non-trivial type #} {# Trivial types (None) are already visible in header badge + signature #} {% set has_return_desc = func.metadata.return_description %} {% set is_nontrivial_return = func_return and func_return not in ('None', 'none', 'void', '') %} {% if has_return_desc or is_nontrivial_return %}
Returns
{{ func_return }} {% if has_return_desc %} {{ has_return_desc }} {% endif %}
{% endif %} {# Raises #} {% if func.metadata.raises %}
{% for exc in func.metadata.raises %}
{{ exc.type | default(exc.get('type', '')) }}
{{ exc.description | default(exc.get('description', '')) }}
{% endfor %}
{% endif %}
{% endmacro %}