{# ================================================================================ Class Member Macro (Kida-Native v2) ================================================================================ Renders a class as a collapsible card with status dot, count badge, and description. Uses the unified autodoc design system. USAGE: {% from 'autodoc/partials/_macros/class-member.html' import class_member %} {{ class_member(cls, is_first=loop.first) }} ARGS: cls: Class DocElement to render (required) is_first: Whether this is the first item (to auto-open) KIDA FEATURES SHOWCASED: - {% let %} multi-assignment for template-scoped caching - {% match %} for pluralization and conditional dispatch - {% unless %} for negative conditionals - Optional chaining (?.) for safe attribute access - Null coalescing (??) for defaults - Pipeline operators (|>) for filter chains - {% spaceless %} for clean badge output ================================================================================ #} {% def class_member(cls, is_first=false) %} {# Pre-compute all values with null-safety (using multi-let) #} {% let cls_children = cls?.children ?? [], cls_methods = cls_children |> selectattr('element_type', 'eq', 'method') |> list, cls_attrs = cls_children |> selectattr('element_type', 'eq', 'attribute') |> list, cls_props = cls_children |> selectattr('element_type', 'eq', 'property') |> list, all_attrs = cls_attrs + cls_props, total_members = (cls_methods | length) + (all_attrs | length), cls_meta = cls?.metadata ?? {}, is_dataclass = cls_meta?.is_dataclass ?? false, is_abstract = cls_meta?.is_abstract ?? false, is_mixin = cls_meta?.is_mixin ?? false, cls_name = cls?.name ?? 'Unknown', cls_desc = cls?.description ?? '' %}
{# Status dot (yellow/amber for classes) #} {# Content wrapper #}
{{ cls_name }} {# Count badge with smart pluralization using match #} {% spaceless %} {{ total_members }} {% end %} {# Toggle indicator #}
{# Description preview #} {% with cls_desc as desc %} {{ desc |> truncate(100, true, '…') }} {% end %}
{# Badges - using data-driven approach with match for badge rendering #} {% let badge_flags = [ {'key': 'dataclass', 'active': is_dataclass}, {'key': 'abstract', 'active': is_abstract}, {'key': 'mixin', 'active': is_mixin} ] %} {% let active_badges = badge_flags |> selectattr('active') |> list %} {% if active_badges | length > 0 %} {% spaceless %} {% for badge in active_badges %} {{ badge.key }} {% end %} {% end %} {% end %}
{% with cls_desc as desc %}
{{ desc |> markdownify |> safe }}
{% end %} {# Class attributes (from children with element_type='attribute' or 'property') #} {% if all_attrs | length > 0 %}

Attributes

{% for attr in all_attrs %} {# Use let instead of set for Kida-native syntax #} {% let attr_meta = attr?.metadata ?? {}, attr_type = attr_meta?.annotation, attr_name = attr?.name ?? 'unknown', attr_desc = attr?.description ?? '' %} {% end %}
Name Type Description
{{ attr_name }} {% match attr_type %} {% case type if type %}{{ type }} {% case _ %}— {% end %} {% match attr_desc %} {% case desc if desc %}{{ desc |> markdownify |> safe }} {% case _ %}— {% end %}
{% end %} {# Class methods - use unified members partial with let #} {% if cls_methods | length > 0 %}

Methods

{% let members = cls_methods %} {% let title = '' %} {% let member_type = 'method' %} {% let first_open = false %} {% include 'autodoc/partials/members.html' %}
{% end %}
{% end %}