-
Notifications
You must be signed in to change notification settings - Fork 6
/
helpers.py
111 lines (94 loc) · 3.2 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""Jinja format helpers."""
import warnings
from jinja2 import Environment, BaseLoader
def config(k, v, container):
s = """
<p class="tab30">
<b>{{ k }}</b> ({{ v["type"] }})
{% if "default" in v.keys() %}<i>default: {{ v["default"] }}</i>{% endif %}
<br>
{% if "doc" in v.keys() %} {{ v["doc"] }} <br> {% endif %}
{% if "origin" in v.keys() %}
<i>{{ container.format_origin(v["origin"]) }}</i>
{% endif %}
{% if "addendum" in v.keys() %}
<br> <i>addendum by {{container.name}}:</i><br>
{{ v["addendum"] }}
{% endif %}
</p>
"""
template = Environment(loader=BaseLoader).from_string(s)
return template.render(k=k, v=v, container=container)
def h2(s):
return f"<h2 id='{s.lower()}'>{s}<a href='#{s.lower()}'> ¶</a></h2>"
def message(k, v, container):
s = """
<p class="tab30">
<b>{{ k }}</b>
{% if "response" in v.keys() %} ➜ {{ v["response"] }} {% endif %}
<br>
{% if "doc" in v.keys() %} {{ v["doc"] }} <br> {% endif %}
{% if "origin" in v.keys() %}
<i>{{ container.format_origin(v["origin"]) }}</i> <br>
{% endif %}
{% if v["request"] %}
parameters: <br>
</p>
{% for r in v["request"] %}
<p class="tab60">
<b>{{ r["name"] }}</b> ({{ r["type"] }})
{% if "default" in r.keys() %}<i>default: {{ r["default"] }}</i>{% endif %}
<br>
{% if "doc" in r.keys() %} {{ r["doc"] }} <br> {% endif %}
</p>
{% endfor %}
{% else %} </p>
{% endif %}
"""
template = Environment(loader=BaseLoader).from_string(s)
return template.render(k=k, v=v, container=container)
def state(k, v, container):
s = """
<p class="tab30">
<b>{{ k }}</b> ({{ v["type"] }}) <br>
{% if "doc" in v.keys() %} {{ v["doc"] }} <br> {% endif %}
{% if "origin" in v.keys() %}
<i>{{ container.format_origin(v["origin"]) }}</i>
{% endif %}
</p>
"""
template = Environment(loader=BaseLoader).from_string(s)
return template.render(k=k, v=v, container=container)
def type_(ty, container):
s = """
<p class="tab30">
<b>{{ ty.name }}</b> ({{ ty["type"] }}) <br>
{% if "default" in ty.keys() %} default: {{ ty["default"] }} <br> {% endif %}
{% if "doc" in ty.keys() %} {{ ty["doc"] }} <br> {% endif %}
{% if "symbols" in ty.keys() %} symbols: {{ ty["symbols"] }} <br> {% endif %}
{% if "fields" in ty.keys() %}
fields: <br>
{% for f in ty["fields"] %}
<p class="tab60">
<b>{{ f["name"] }}</b> ({{ f["type"] }})
{% if "default" in f.keys() %}<i>default: {{ f["default"] }}</i>{% endif %}
<br>
{% if "doc" in f.keys() %} {{ f["doc"] }} <br> {% endif %}
</p>
{% endfor %}
{% endif %}
{% if "origin" in ty.keys() %}
<i>{{ container.format_origin(ty["origin"]) }}</i>
{% endif %}
</p>
"""
if ty["type"] not in ("enum", "record"):
warnings.warn(f"Unhandled type: {ty['type']}")
template = Environment(loader=BaseLoader).from_string(s)
return template.render(ty=ty, container=container)
helpers = dict()
helpers["config"] = config
helpers["h2"] = h2
helpers["message"] = message
helpers["state"] = state
helpers["type"] = type_