diff --git a/muppet/__main__.py b/muppet/__main__.py index d2c4eeed6723ddd184286410aa2117acec015194..d2880cab7bb3210bc2c8fae6887bfefa38efbd63 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 01ca608250a9a9f47fa82be10d393cac9a671b4d..43e414463086ecfc7359477e81074ee8f7d06ab9 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 41119eeebcbff29ad9a13f3dd754d4623f2da207..41765941700e2000151f7ca0c566b7cde92edda7 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 %} + — {{ item['summary'] }} + {%- endif -%} </li> {% endfor %} </ul>