From 28e25d5682c9212709a3478ef080eb9d076bd99a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= <hugo@lysator.liu.se>
Date: Sat, 3 Jun 2023 19:54:50 +0200
Subject: [PATCH] Introduce summaries for class list.

---
 muppet/__main__.py          | 29 ++++++++++++++++++++++++++---
 static/style.css            |  4 ++++
 templates/module_index.html |  5 ++++-
 3 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/muppet/__main__.py b/muppet/__main__.py
index d2c4eee..d2880ca 100644
--- a/muppet/__main__.py
+++ b/muppet/__main__.py
@@ -17,6 +17,7 @@ from typing import (
     TypeVar,
     Callable,
     TypedDict,
+    NotRequired,
 )
 from collections.abc import (
     Iterable,
@@ -29,6 +30,8 @@ from .format import (
     format_class,
     format_type_alias,
 )
+from .lookup import lookup, Ref
+from commonmark import commonmark
 
 jinja = Environment(
     loader=FileSystemLoader('templates'),
@@ -180,6 +183,7 @@ class IndexItem(TypedDict):
 
     name: str
     file: str
+    summary: NotRequired[str]
 
 
 class IndexSubcategory(TypedDict):
@@ -203,11 +207,30 @@ def class_index(class_list: list) -> IndexCategory:
     lst: list[IndexSubcategory] = []
 
     if publics := groups.get(False):
+        # print(publics[0]['docstring']['tags'])
+        sublist: list[IndexItem] = []
+        for i in publics:
+            name = i['name']
+            summary = lookup(i) \
+                .ref('docstring') \
+                .ref('tags') \
+                .find(Ref('tag_name') == 'summary') \
+                .ref('text') \
+                .value()
+
+            obj: IndexItem = {
+                'file': os.path.splitext(i['file'])[0],
+                'name': name,
+            }
+
+            if summary:
+                obj['summary'] = commonmark(summary)
+
+            sublist.append(obj)
+
         lst.append({
             'title': 'Public Classes',
-            'list': ({'name': i['name'],
-                      'file': os.path.splitext(i['file'])[0]}
-                     for i in publics),
+            'list': sublist,
         })
 
     if privates := groups.get(True):
diff --git a/static/style.css b/static/style.css
index 01ca608..43e4144 100644
--- a/static/style.css
+++ b/static/style.css
@@ -53,3 +53,7 @@ code.json {
 :target {
 	background-color: yellow;
 }
+
+.overview-list p {
+	display: inline;
+}
diff --git a/templates/module_index.html b/templates/module_index.html
index 41119ee..4176594 100644
--- a/templates/module_index.html
+++ b/templates/module_index.html
@@ -6,10 +6,13 @@
 	<h2>{{ entry['title'] }}</h2>
 	{% for subentry in entry['list'] %}
 		<h3>{{ subentry['title'] }}</h3>
-		<ul>
+		<ul class="overview-list">
 			{% for item in subentry['list'] %}
 				<li>
 					<a href="{{ item['file'] }}">{{ item['name'] }}</a>
+					{%- if 'summary' in item %}
+						&mdash; {{ item['summary'] }}
+					{%- endif -%}
 				</li>
 		{% endfor %}
 		</ul>
-- 
GitLab