diff --git a/Makefile b/Makefile index ef1e7887fb0b03ee09dc3f6a13f4a77514110311..f78376fbdc3010b7ec3094f5acdf53d32217bf35 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 9887ef33bfd9b7a9b475d98cf5695b8d6dd794fb..91cc3736fee7d03a5bf2d65431c5d3b85b973bca 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 {