Skip to content

Commit 4790b56

Browse files
authored
feat: support spec extension rendering for messages (#181)
1 parent 52ddbaf commit 4790b56

File tree

5 files changed

+60
-42
lines changed

5 files changed

+60
-42
lines changed

partials/extensions.html

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{% macro extension(obj, odd = false, indent = false) %}
2+
3+
{% set extensions = obj | nonParserExtensions%}
4+
{% if extensions.size > 0 %}
5+
<p class="{% if indent %}pl-6{% endif %} mb-2 mt-4 text-sm font-bold text-gray-700">
6+
Specification Extensions:
7+
</p>
8+
9+
{% for extensionName, extensionValue in extensions %}
10+
<div class="{% if odd %}bg-gray-100{% else %}bg-gray-200{% endif %} {% if indent %}pl-6{% endif %}">
11+
{% if extensionValue | isObject %}
12+
<div class="{% if open %}is-open{% endif %}">
13+
<div class="js-prop cursor-pointer py-2 property">
14+
<div class="pr-4" style="margin-top: -2px; min-width: 25%">
15+
<span class="text-sm" style="word-break: break-word">
16+
{{ extensionName }}
17+
</span>
18+
<svg
19+
class="expand inline align-baseline"
20+
version="1.1"
21+
viewBox="0 0 24 24"
22+
x="0"
23+
xmlns="http://www.w3.org/2000/svg"
24+
y="0"
25+
>
26+
<polygon
27+
points="17.3 8.3 12 13.6 6.7 8.3 5.3 9.7 12 16.4 18.7 9.7 "
28+
></polygon>
29+
</svg>
30+
</div>
31+
</div>
32+
<div class="children">
33+
<div class="{% if odd %}bg-gray-200{% else %}bg-gray-100{% endif %} {% if not root %}pl-8 pr-8{% endif %} rounded">
34+
<pre class="text-sm whitespace-pre-wrap">{{ extensionValue | dump(2) }}</pre>
35+
</div>
36+
</div>
37+
</div>
38+
{% else %}
39+
<div class="text-sm">{{ extensionName }}: {{ extensionValue }}</div>
40+
{% endif %}
41+
</div>
42+
{% endfor %}
43+
44+
{% endif %}
45+
46+
{% endmacro %}

partials/message.html

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{% from "./schema.html" import schema %}
22
{% from "./tags.html" import tags %}
33
{% from "./protocols.html" import bindings %}
4+
{% from "./extensions.html" import extension %}
45

56
{% macro message(msg, showIndex=false, index=0, open=false) %}
67

@@ -42,6 +43,7 @@
4243
{% endif %}
4344

4445
{{ bindings("Message", msg, odd=true) }}
46+
{{ extension(msg) }}
4547

4648
</div>
4749

partials/schema-prop.html

+3-42
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{% from "./type.html" import type %} {% from "./schema-item.html" import
1+
{% from "./extensions.html" import extension %}
2+
{% from "./type.html" import type %} {% from "./schema-item.html" import
23
schemaItem %} {% from "./description.html" import getDescription %} {% macro
34
schemaProp(prop, propName, open=false, root=false, odd=false, specialName=false,
45
required=false, altDescription=null, circularPropsParent) %}
@@ -156,47 +157,7 @@
156157
circularPropsParent | includes(pName) %} {% if isPropCircular === true %}
157158
{{ schemaItem(pName, odd) }} {% else %} {{ schemaProp(p, pName, odd=(not
158159
odd), required=(prop.required() | includes(pName)), circProps) }} {% endif
159-
%} {% endfor %} {% endif %} {% set extensions = prop | nonParserExtensions
160-
%} {% if extensions.size > 0 %}
161-
<p class="pl-6 mb-2 mt-4 text-sm font-bold text-gray-700">
162-
Specification Extensions:
163-
</p>
164-
{% for extensionName, extensionValue in extensions %}
165-
<div class="{% if odd %}bg-gray-100{% else %}bg-gray-200{% endif %} pl-6">
166-
{% if extensionValue | isObject %}
167-
<div class="{% if open %}is-open{% endif %}">
168-
<div class="js-prop cursor-pointer py-2 property">
169-
<div class="pr-4" style="margin-top: -2px; min-width: 25%">
170-
<span class="text-sm" style="word-break: break-word"
171-
>{{ extensionName }}</span
172-
>
173-
<svg
174-
class="expand inline align-baseline"
175-
version="1.1"
176-
viewBox="0 0 24 24"
177-
x="0"
178-
xmlns="http://www.w3.org/2000/svg"
179-
y="0"
180-
>
181-
<polygon
182-
points="17.3 8.3 12 13.6 6.7 8.3 5.3 9.7 12 16.4 18.7 9.7 "
183-
></polygon>
184-
</svg>
185-
</div>
186-
</div>
187-
<div class="children">
188-
<div
189-
class="{% if odd %}bg-gray-200{% else %}bg-gray-100{% endif %} {% if not root %}pl-8 pr-8{% endif %} rounded"
190-
>
191-
<pre class="text-sm">{{ extensionValue | dump(2) }}</pre>
192-
</div>
193-
</div>
194-
</div>
195-
{% else %}
196-
<div class="text-sm">{{ extensionName }}: {{ extensionValue }}</div>
197-
{% endif %}
198-
</div>
199-
{% endfor %} {% endif %} {% if prop.type() === 'array' %} {% set
160+
%} {% endfor %} {% endif %} {{ extension(prop, odd = true, indent = true) }} {% if prop.type() === 'array' %} {% set
200161
arrayItemsProps = prop.items().properties() if prop.items() and not
201162
prop.items() | isArray else null %} {% if prop.items() and arrayItemsProps
202163
| isEmpty %}

template/css/main.css

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ a:hover {
125125
transform: rotate(0deg);
126126
}
127127

128+
pre > * { white-space: pre-wrap; }
129+
128130
/* EXAMPLES */
129131

130132
.examples-payload-tab:checked + label {

template/css/main.min.css

+7
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,10 @@ video {
10831083
vertical-align: baseline;
10841084
}
10851085

1086+
.whitespace-pre-wrap {
1087+
white-space: pre-wrap;
1088+
}
1089+
10861090
.break-words {
10871091
overflow-wrap: break-word;
10881092
}
@@ -1287,6 +1291,9 @@ a:hover {
12871291
transform: rotate(0deg);
12881292
}
12891293

1294+
pre > * { white-space: pre-wrap;
1295+
}
1296+
12901297
/* EXAMPLES */
12911298

12921299
.examples-payload-tab:checked + label {

0 commit comments

Comments
 (0)