{# ================================================================================ Function Member Macro (Kida-Native) ================================================================================ 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) KIDA FEATURES USED: - Optional chaining (?.) for safe attribute access - Null coalescing (??) for defaults - {% let %} for template-scoped caching ================================================================================ #} {% def function_member(func, is_first=false) %} {# Pre-compute all values with null-safety #} {% let func_meta = func?.metadata ?? {}, func_params = func_meta?.args ?? func_meta?.parameters ?? [], func_return = func_meta?.return_type ?? func_meta?.returns ?? '', func_signature = func_meta?.signature ?? '', is_async = func_meta?.is_async ?? false, func_name = func?.name ?? 'unknown', func_desc = func?.description ?? '', func_raises = func_meta?.raises ?? [], return_desc = func_meta?.return_description ?? '' %}
{# 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, '…') }} {% end %} {# Toggle indicator #}
{# Description preview (for scanning) #} {% if func_desc %} {{ func_desc | striptags | truncate(80, True, '…') }} {% end %}
{# Badges #} {% if is_async %} async {% end %}
{# Signature (copy-paste ready) #} {% if func_signature %}
{{ func_signature }}
{% end %} {# Full description - only show if truncated in header #} {% set desc_stripped = func_desc | striptags | trim if func_desc else '' %} {% if func_desc and desc_stripped | length > 77 %}
{{ func_desc | markdownify | safe }}
{% end %} {# Function parameters - args is a list of dicts with name, type, docstring, default #} {% if func_params | length > 0 %}
Parameters
{% for param in func_params %} {# Extract param properties with null-safety #} {% set param_name = param?.name ?? 'unknown' %} {% set param_type = param?.type ?? '' %} {% set param_desc = param?.docstring ?? '' %} {% set param_default = param?.default %} {% end %}
Name Type Description
{{ param_name }} {{ param_type if param_type else '—' }} {{ param_desc | markdownify | safe if param_desc else '' }} {% if param_default is not none and param_default != '' %} Default: {{ param_default }} {% end %}
{% end %} {# Return type (detailed) - only show if has description OR non-trivial type #} {# Trivial types (None) are already visible in header badge + signature #} {% set is_nontrivial_return = func_return and func_return not in ('None', 'none', 'void', '') %} {% if return_desc or is_nontrivial_return %}
Returns
{{ func_return }} {% if return_desc %} {{ return_desc }} {% end %}
{% end %} {# Raises #} {% if func_raises | length > 0 %}
{% for exc in func_raises %}
{{ exc?.type ?? 'Exception' }}
{{ exc?.description ?? '' }}
{% end %}
{% end %}
{% end %}