aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-06-03 19:54:50 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2023-06-03 19:54:50 +0200
commit28e25d5682c9212709a3478ef080eb9d076bd99a (patch)
treedc50f9e4d6a10251fe375e1ff612e0a4c85e531f
parentIntroduce lookup. (diff)
downloadmuppet-strings-28e25d5682c9212709a3478ef080eb9d076bd99a.tar.gz
muppet-strings-28e25d5682c9212709a3478ef080eb9d076bd99a.tar.xz
Introduce summaries for class list.
-rw-r--r--muppet/__main__.py29
-rw-r--r--static/style.css4
-rw-r--r--templates/module_index.html5
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>