Skip to content

Commit 7612f85

Browse files
working on the documentation generator
1 parent cfe5f02 commit 7612f85

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ jse.boxing_primitive // DEFAULT: true - always try to convert any type t to a l
163163

164164
## Authors
165165
Zachary Ferguson,
166+
Zhongshi Jiang,
166167
Teseo Schneider,
167168
Daniele Panozzo
168169

docs/main.mako

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
## _*_ coding: utf-8 _*_
2+
<!DOCTYPE HTML>
3+
4+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
5+
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
6+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
7+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
8+
9+
<%def name="render_pointer(pointer_name)">
10+
${make_rules(rs = ijson.rules_from_pointer(pointer_name))}
11+
</%def>
12+
13+
<%def name="make_rules(rs)">
14+
<% ## get a unique id
15+
attributes['count'] = attributes['count'] + 1
16+
local_count = attributes['count']
17+
%>
18+
% if len(rs) == 1: ## single rules for a pointer use a cell
19+
${make_rule(r=rs[0])}
20+
% endif
21+
% if len(rs) > 1: ## multiple rules use a collapsible block
22+
<div id="accordion${local_count}">
23+
<div class="card">
24+
<div class="card-header" id="heading${local_count}">
25+
<h5 class="mb-0">
26+
<button class="btn btn-link" data-toggle="collapse" data-target="#collapse${local_count}" aria-expanded="true" aria-controls="collapse${local_count}">
27+
${rs[0]['pointer']}
28+
</button>
29+
</h5>
30+
</div>
31+
<div id="collapse${local_count}" class="collapse show" aria-labelledby="heading${local_count}" data-parent="#accordion${local_count}">
32+
% for r in rs:
33+
${make_rule(r=rs[0])}
34+
% endfor
35+
</div>
36+
</div>
37+
</div>
38+
% endif
39+
</%def>
40+
41+
<%def name="make_rule(r)">
42+
<%
43+
attributes['count'] = attributes['count'] + 1
44+
local_count = attributes['count']
45+
%>
46+
% if r['type'] == "object": ## Object
47+
<div id="accordion${local_count}">
48+
<div class="card">
49+
<div class="card-header" id="heading${local_count}">
50+
<h5 class="mb-0">
51+
<button class="btn btn-link" data-toggle="collapse" data-target="#collapse${local_count}" aria-expanded="true" aria-controls="collapse${local_count}">
52+
${r['pointer']}, Object
53+
</button>
54+
</h5>
55+
</div>
56+
<div id="collapse${local_count}" class="collapse hide" aria-labelledby="heading${local_count}" data-parent="#accordion${local_count}">
57+
58+
% if 'required' in r:
59+
<div class="container">
60+
<div class="row">
61+
<div class="auto">
62+
Required
63+
</div>
64+
<div class="col-sm">
65+
% for fname in r['required']:
66+
${render_pointer(pointer_name = (r['pointer']+fname) if r['pointer'] == '/' else (r['pointer']+'/'+fname))}
67+
% endfor
68+
</div>
69+
</div>
70+
</div>
71+
% endif
72+
% if 'optional' in r:
73+
<div class="container">
74+
<div class="row">
75+
<div class="auto">
76+
Optional
77+
</div>
78+
<div class="col-sm">
79+
% for fname in r['optional']:
80+
${render_pointer(pointer_name = (r['pointer']+fname) if r['pointer'] == '/' else (r['pointer']+'/'+fname))}
81+
% endfor
82+
</div>
83+
</div>
84+
</div>
85+
% endif
86+
87+
</div>
88+
</div>
89+
</div>
90+
% endif
91+
% if r['type'] == "list": ## List
92+
${render_pointer(pointer_name = (r['pointer']+'*') if r['pointer'] == '/' else (r['pointer']+'/'+'*'))}
93+
% endif
94+
</%def>
95+
96+
<html>
97+
<body>
98+
${render_pointer(pointer_name='/')}
99+
</body>
100+
</html>

docs/spec2html.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from unittest import skip
2+
from mako.template import Template
3+
from mako.lookup import TemplateLookup
4+
import argparse
5+
import json
6+
7+
class json_navigator:
8+
def __init__(self,ijson):
9+
self.ijson = ijson
10+
11+
def rules_from_pointer(self,pointer):
12+
return [x for x in self.ijson if x['pointer'] == pointer]
13+
14+
if __name__ == "__main__":
15+
parser = argparse.ArgumentParser()
16+
parser.add_argument("--input", help="Path to the input specification", required=True)
17+
parser.add_argument("--output", help="Path to the output html file", required=True)
18+
args = parser.parse_args()
19+
20+
# Template Lookup
21+
mylookup = TemplateLookup(directories=['.'])
22+
23+
print("01 - Loading specification")
24+
with open(args.input) as input_file:
25+
input = json.load(input_file)
26+
27+
# print(input)
28+
29+
print("02 - Templating")
30+
mako_template = Template(filename='docs/main.mako')
31+
body = mako_template.render(ijson=json_navigator(input),attributes={"count":0})
32+
33+
print("03 - Writing to output")
34+
with open(args.output, 'w') as f:
35+
f.write(body)
36+

tags.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
* required: list of fields required for this object to be valid
2626
* optional: list of fields that are optional. Every optional field must have at least one rule with a default
27+
* type-name: the object must have a type field with the same name
2728

2829
## list
2930

0 commit comments

Comments
 (0)