aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-06-17 03:36:47 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2023-06-17 03:36:47 +0200
commit4872c9527d19891f984f5d880ed8a691a4d3bb1c (patch)
tree17dc5827f230866dc70f22f900ece4512deaba13
parentInclude module documentation files. (diff)
downloadmuppet-strings-4872c9527d19891f984f5d880ed8a691a4d3bb1c.tar.gz
muppet-strings-4872c9527d19891f984f5d880ed8a691a4d3bb1c.tar.xz
Simplify index generation.
-rw-r--r--Makefile2
-rw-r--r--muppet/output.py64
2 files changed, 34 insertions, 32 deletions
diff --git a/Makefile b/Makefile
index ef1e788..f78376f 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ all: output
DOC_OUTPUT = doc.rendered
OUTPUT_FLAGS = --path-base /code/muppet-strings/output \
- --env ~/puppet/generated-environments/test/modules/
+ --env ~/puppet/generated-environments/production/modules/
output:
python -m muppet $(OUTPUT_FLAGS)
diff --git a/muppet/output.py b/muppet/output.py
index 9887ef3..91cc373 100644
--- a/muppet/output.py
+++ b/muppet/output.py
@@ -78,6 +78,35 @@ class IndexCategory(TypedDict):
list: Iterable[IndexSubcategory]
+def index_item(obj: dict) -> IndexItem:
+ """
+ Format a puppet type declaration into an index entry.
+
+ :param obj:
+ A dictionary at least containing the keys 'name' and 'file',
+ and optionally containing 'docstring'. If docstring is present
+ then a summary tag is searched for, and added to the resulting
+ object.
+ """
+ name = obj['name']
+ summary = lookup(obj) \
+ .ref('docstring') \
+ .ref('tags') \
+ .find(Ref('tag_name') == 'summary') \
+ .ref('text') \
+ .value()
+
+ out: IndexItem = {
+ 'file': os.path.splitext(obj['file'])[0],
+ 'name': name,
+ }
+
+ if summary:
+ out['summary'] = commonmark(summary)
+
+ return out
+
+
def class_index(class_list: list) -> IndexCategory:
"""Prepage class index list."""
groups = group_by(isprivate, class_list)
@@ -85,38 +114,15 @@ 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': sublist,
+ 'list': (index_item(i) for i in publics),
})
if privates := groups.get(True):
lst.append({
'title': 'Private Classes',
- 'list': ({'name': i['name'],
- 'file': os.path.splitext(i['file'])[0]}
- for i in privates),
+ 'list': (index_item(i) for i in privates),
})
return {
@@ -139,17 +145,13 @@ def defined_types_index(defined_list: list) -> IndexCategory:
if publics := groups.get(False):
lst.append({
'title': 'Public Defined Types',
- 'list': ({'name': i['name'],
- 'file': os.path.splitext(i['file'])[0]}
- for i in publics),
+ 'list': (index_item(i) for i in publics),
})
if privates := groups.get(True):
lst.append({
'title': 'Private Defined Types',
- 'list': ({'name': i['name'],
- 'file': os.path.splitext(i['file'])[0]}
- for i in privates),
+ 'list': (index_item(i) for i in privates),
})
return {