Skip to content

Commit 873f8ec

Browse files
committed
Added main.md.mako
1 parent 93d74f7 commit 873f8ec

File tree

3 files changed

+117
-1
lines changed

3 files changed

+117
-1
lines changed
File renamed without changes.

docs/main.md.mako

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
## _*_ coding: utf-8 _*_
2+
<!--Automatically generated using JSON Spec Engine-->
3+
<%def name="render_pointer(pointer_name, prefix)">
4+
${make_rules(rs=ijson.rules_from_pointer(pointer_name), prefix=prefix)}
5+
</%def>
6+
##
7+
##
8+
<%def name="make_rules(rs, prefix)">
9+
<%
10+
if len(rs) > 0:
11+
rs[0]['pointer_last'] = rs[0]['pointer'].rsplit('/', 1)[-1]
12+
if rs[0]['pointer_last'] == '*':
13+
tmp = rs[0]['pointer'].replace('/*','')
14+
rs[0]['pointer_last'] = tmp.rsplit('/', 1)[-1]
15+
%>
16+
##
17+
% if len(rs) == 1: ## single rules for a pointer use a cell
18+
${make_rule(r=rs[0], prefix=prefix)}
19+
% endif
20+
##
21+
% if len(rs) > 1: ## multiple rules use a collapsible block
22+
${prefix}${"!!!" if len(prefix) == 0 else "???"} summary "`${rs[0]['pointer']}`"
23+
${prefix} ```
24+
${prefix} ${rs[0]['pointer']}
25+
${prefix} ```
26+
% for rule in rs:
27+
${make_rule(r=rule, prefix=prefix + " ")}
28+
% endfor
29+
% endif
30+
</%def>
31+
##
32+
##
33+
<%def name="make_rule(r, prefix)">
34+
<%
35+
if not 'doc' in r:
36+
r['doc'] = '<span class="todo">FIXME:</span> Missing documentation in the specification'
37+
if r["doc"] == "TODO":
38+
r["doc"] = '<span class="todo">TODO</span>'
39+
r['pointer_last'] = r['pointer'].rsplit('/', 1)[-1]
40+
if r['pointer_last'] == '*':
41+
tmp = r['pointer'].replace('/*','')
42+
r['pointer_last'] = tmp.rsplit('/', 1)[-1]
43+
r['pointer_short'] = r['pointer']
44+
%>
45+
## ----------------------------------------------------------------------------
46+
% if r['type'] == "object": ## Object
47+
${prefix}${"!!!" if len(prefix) == 0 else "???"} summary "${r.get("type_name", f"`{r['pointer_short']}` (`{r['type']}`)")}"
48+
${prefix} ```
49+
${prefix} ${r['pointer']}
50+
${prefix} ```
51+
${prefix} ${"##"} Description
52+
${prefix} ${r['doc']}
53+
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54+
% if "type_name" in r:
55+
${prefix}
56+
${prefix} **Type**: ${r["type_name"]}
57+
% endif
58+
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
59+
% if "default" in r:
60+
${prefix}
61+
${prefix} **Default**: ${repr(r["default"])}
62+
% endif
63+
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
64+
% if 'required' in r:
65+
${prefix} ${"##"} Required
66+
% for fname in r['required']:
67+
${render_pointer(
68+
pointer_name = (r['pointer']+fname) if r['pointer'] == '/' else (r['pointer']+'/'+fname),
69+
prefix = prefix + " ")}
70+
% endfor
71+
% endif
72+
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73+
% if 'optional' in r:
74+
${prefix} ${"##"} Optional
75+
% for fname in r['optional']:
76+
${render_pointer(
77+
pointer_name = (r['pointer']+fname) if r['pointer'] == '/' else (r['pointer']+'/'+fname),
78+
prefix = prefix + " ")}
79+
% endfor
80+
% endif
81+
## ----------------------------------------------------------------------------
82+
% elif r['type'] == "list": ## List
83+
${render_pointer(
84+
pointer_name = (r['pointer']+'*') if r['pointer'] == '/' else (r['pointer']+'/'+'*'),
85+
prefix = prefix)}
86+
## ----------------------------------------------------------------------------
87+
% else:
88+
${prefix}${"!!!" if len(prefix) == 0 else "???"} summary "`${r['pointer_short']}` (`${r["type"]}`)"
89+
${prefix} ```
90+
${prefix} ${r['pointer']}
91+
${prefix} ```
92+
${prefix} ${"##"} Description
93+
${prefix} ${r['doc']}
94+
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
95+
% if "min" in r or "max" in r:
96+
${prefix}
97+
${prefix} **Range:** `(${r.get("min", "-inf")}, ${r.get("max", "inf")})`
98+
% endif
99+
% if "default" in r:
100+
${prefix}
101+
${prefix} **Default**: `${repr(r["default"])}`
102+
% endif
103+
% if "extensions" in r:
104+
${prefix}
105+
${prefix} **Extensions:** `${r["extensions"]}`
106+
% endif
107+
% if "options" in r:
108+
${prefix}
109+
${prefix} **Options:** `${r["options"]}`
110+
% endif
111+
% endif
112+
</%def>
113+
${render_pointer(pointer_name='/', prefix='')}

docs/spec2html.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ def rules_from_pointer(self, pointer):
3535
# print(input)
3636

3737
print("02 - Templating")
38-
mako_file = pathlib.Path(__file__).parent.absolute() / "main.mako"
38+
if args.output.endswith(".md"):
39+
mako_file = pathlib.Path(__file__).parent.absolute() / "main.md.mako"
40+
else:
41+
mako_file = pathlib.Path(__file__).parent.absolute() / "main.html.mako"
3942
mako_template = Template(filename=str(mako_file))
4043
body = mako_template.render(
4144
title=args.title, ijson=json_navigator(input), attributes={"count": 0})

0 commit comments

Comments
 (0)