Skip to content

Commit 7bed21c

Browse files
committed
feat: Example of building docs directly from specification data
1 parent b3a93a2 commit 7bed21c

17 files changed

+178
-22
lines changed

docs/Earthfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ IMPORT github.com/input-output-hk/catalyst-ci/earthly/docs:v3.3.0 AS docs-ci
44

55

66
IMPORT .. AS repo
7+
IMPORT ../specs AS specs
78

89
# Copy all the source we need to build the docs
910
src:
@@ -13,6 +14,9 @@ src:
1314
# Now copy into that any artifacts we pull from the builds.
1415
COPY --dir repo+repo-docs/repo /docs/includes
1516

17+
# Copy our generated Signed Document Specification data.
18+
COPY specs+src/signed_doc.json /docs/includes
19+
1620

1721
# Build the docs here.
1822
docs:

docs/macros/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from .include import inc_file
2+
from .signed_docs import (doc_type_summary, doc_type_details)
3+
4+
def define_env(env):
5+
"""
6+
This is the hook for defining variables, macros and filters
7+
"""
8+
9+
@env.macro
10+
def include_file(filename, start_line=0, end_line=None, indent=None):
11+
# Provided by the base mkdocs config.
12+
return inc_file(env, filename, start_line, end_line, indent)
13+
14+
@env.macro
15+
def insert_doc_type_summary():
16+
return doc_type_summary(env)
17+
18+
@env.macro
19+
def insert_doc_type_details():
20+
return doc_type_details(env)

docs/macros/signed_docs.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import os
2+
import re
3+
import textwrap
4+
import json
5+
6+
#SIGNED_DOCS_SPECS="signed_doc.json"
7+
SIGNED_DOCS_SPECS="includes/signed_doc.json"
8+
9+
def uuid_as_cbor(uuid):
10+
return f"37(h'{uuid.replace('-', '')}')"
11+
12+
13+
def get_signed_doc_data(env):
14+
"""
15+
Load the Signed Document Data from its json file.
16+
"""
17+
full_filename = os.path.join(env.project_dir, SIGNED_DOCS_SPECS)
18+
19+
with open(full_filename, "r") as f:
20+
return json.load(f)
21+
22+
def doc_type_summary(env):
23+
"""
24+
Generate a Document Base Type Summary from the Document Specifications Data
25+
"""
26+
27+
try:
28+
doc_data = get_signed_doc_data(env)
29+
doc_types = doc_data["base_types"]
30+
31+
doc_type_summary = """
32+
| Base Type | [UUID] | [CBOR] |
33+
| :--- | :--- | :--- |
34+
"""
35+
36+
for k in doc_types:
37+
doc_type_summary += f"| {k} | `{doc_types[k]}` | `{uuid_as_cbor(doc_types[k])}` |\n"
38+
39+
return doc_type_summary
40+
except Exception as exc:
41+
return f"{exc}"
42+
43+
44+
def name_for_uuid(doc_types, uuid):
45+
"""
46+
Get the name for a document base type, given its uuid
47+
"""
48+
for k in doc_types:
49+
if doc_types[k] == uuid:
50+
return k
51+
return "Unknown"
52+
53+
54+
def name_to_spec_link(name,ref=None):
55+
"""
56+
Create a link to a document type, and an optional ref inside the document.
57+
"""
58+
link = "./../catalyst_docs/"+name.lower().replace(' ','_') + ".md"
59+
if ref is not None:
60+
link += f"#{ref}"
61+
return link
62+
63+
def base_types(docs, doc_types, name):
64+
types = docs[name]["type"]
65+
type_names = ""
66+
for sub_type in types:
67+
type_names += name_for_uuid(doc_types, sub_type) + "/"
68+
return type_names[:-1]
69+
70+
def types_as_cbor(docs, name):
71+
types = docs[name]["type"]
72+
type_names = "["
73+
for sub_type in types:
74+
type_names += uuid_as_cbor(sub_type) + ",<br/>"
75+
return type_names[:-6] + "]"
76+
77+
78+
def doc_type_details(env):
79+
"""
80+
Generate a Document Type Detailed Summary from the Document Specifications Data
81+
"""
82+
83+
try:
84+
doc_data = get_signed_doc_data(env)
85+
doc_types = doc_data["base_types"]
86+
docs = doc_data["docs"]
87+
88+
doc_type_details = """
89+
| Document Type | Base Types | [CBOR] | Specification |
90+
| :--- | :--- | :--- | :--- |
91+
"""
92+
93+
for k in docs:
94+
doc_type_details += f"| {k} | {base_types(docs,doc_types,k)} | {types_as_cbor(docs,k)} | [Specification]({name_to_spec_link(k)}) | \n"
95+
96+
return doc_type_details
97+
except Exception as exc:
98+
return f"{exc}"
99+
100+
#class env:
101+
# project_dir = "/home/steven/Development/iohk/catalyst-libs/specs"
102+
103+
#if __name__ == '__main__':
104+
105+
# print(doc_type_details(env))
106+
# print(doc_type_summary(env))

docs/src/architecture/08_concepts/catalyst_docs/category_parameters.md

Whitespace-only changes.

docs/src/architecture/08_concepts/catalyst_docs/comment_action_document.md

Whitespace-only changes.

docs/src/architecture/08_concepts/catalyst_docs/proposal_comment.md

Whitespace-only changes.

docs/src/architecture/08_concepts/catalyst_docs/proposal_comment_meta_template.md

Whitespace-only changes.

docs/src/architecture/08_concepts/catalyst_docs/proposal_comment_template.md

Whitespace-only changes.

docs/src/architecture/08_concepts/catalyst_docs/proposal_meta_template.md

Whitespace-only changes.

docs/src/architecture/08_concepts/catalyst_docs/proposal_moderation_action.md

Whitespace-only changes.

0 commit comments

Comments
 (0)