Skip to content

Commit acad4bf

Browse files
authored
fix: Introduce new macros to keep reusable tag navigation items (#81)
1 parent 45bc473 commit acad4bf

File tree

4 files changed

+61
-119
lines changed

4 files changed

+61
-119
lines changed

partials/operations/by_tags.html

+8-60
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{% from "./tag_nav_item_sub.html" import tagNavItemSub %}
2+
{% from "./tag_nav_item_pub.html" import tagNavItemPub %}
3+
14
{% if asyncapi.hasTags() %}
25
{% for categorytags in asyncapi.tags() %}
36
<div class="mt-4 {% if open %}is-open{% endif %}">
@@ -13,41 +16,12 @@
1316

1417
<div class="children">
1518
{% for channelName, channel in asyncapi.channels() %}
16-
{% if channel.publish() and channel.publish().hasTags() and channel.publish() | containTags(categorytags) %}
17-
<a class="js-menu-item flex break-words no-underline text-grey-darkest mt-8 sm:mt-8 md:mt-3" href="#operation-publish-{{ channelName }}">
18-
<span class="bg-blue-dark font-bold h-6 no-underline text-white uppercase p-1 mr-2 rounded" style="height: 21px;font-size: 11px;" title="Publish">
19-
Pub
20-
</span>
21-
{% if channel.publish().summary() %}
22-
<span style="padding-top: 2px;">
23-
{{ channel.publish().summary() }}
24-
</span>
25-
{% else %}
26-
<div style="display:inline-block;">
27-
{{ slicedString(channelName, 'padding-top: 2px;') }}
28-
</div>
29-
{% endif %}
30-
</a>
19+
{% if channel.publish() and channel.publish().hasTags() and channel.publish() | containTags(categorytags) %}
20+
{{ tagNavItemPub(channel, channelName) }}
3121
{% endif %}
3222

3323
{% if channel.subscribe() and channel.subscribe().hasTags() and channel.subscribe() | containTags(categorytags) %}
34-
<a class="js-menu-item flex break-words no-underline text-grey-darkest mt-8 sm:mt-8 md:mt-3" href="#operation-subscribe-{{ channelName }}">
35-
{% if channel.deprecated %}
36-
<span title="Deprecated"></span>
37-
{% endif %}
38-
<span class="bg-green-dark font-bold no-underline text-white uppercase p-1 mr-2 rounded" style="height: 21px;font-size: 11px;" title="Subscribe">
39-
Sub
40-
</span>
41-
{% if channel.subscribe().summary() %}
42-
<span style="padding-top: 2px;">
43-
{{ channel.subscribe().summary() }}
44-
</span>
45-
{% else %}
46-
<div style="display:inline-block;">
47-
{{ slicedString(channelName, 'padding-top: 2px;') }}
48-
</div>
49-
{% endif %}
50-
</a>
24+
{{ tagNavItemSub(channel, channelName) }}
5125
{% endif %}
5226
{% endfor %}
5327
</div>
@@ -72,37 +46,11 @@
7246
<div class="children">
7347
{% for channelName, channel in asyncapi.channels() %}
7448
{% if channel.hasPublish() and (not channel.publish().hasTags() or not channel.publish() | containTags(asyncapi.tags())) %}
75-
<a class="js-menu-item flex break-words no-underline text-grey-darkest mt-8 sm:mt-8 md:mt-3" href="#operation-publish-{{ channelName }}">
76-
<span class="bg-blue-dark font-bold h-6 no-underline text-white uppercase p-1 mr-2 rounded" style="height: 21px;font-size: 11px;" title="Publish">
77-
Pub
78-
</span>
79-
{% if channel.publish().summary() %}
80-
<span style="padding-top: 2px;">
81-
{{ channel.publish().summary() }}
82-
</span>
83-
{% else %}
84-
<div style="display:inline-block;">
85-
{{ slicedString(channelName, 'padding-top: 2px;') }}
86-
</div>
87-
{% endif %}
88-
</a>
49+
{{ tagNavItemPub(channel, channelName) }}
8950
{% endif %}
9051

9152
{% if channel.hasSubscribe() and (not channel.subscribe().hasTags() or not channel.subscribe() | containTags(asyncapi.tags())) %}
92-
<a class="js-menu-item flex break-words no-underline text-grey-darkest mt-8 sm:mt-8 md:mt-3" href="#operation-subscribe-{{ channelName }}">
93-
<span class="bg-green-dark font-bold no-underline text-white uppercase p-1 mr-2 rounded" style="height: 21px;font-size: 11px;" title="Subscribe">
94-
Sub
95-
</span>
96-
{% if channel.subscribe().summary() %}
97-
<span style="padding-top: 2px;">
98-
{{ channel.subscribe().summary() }}
99-
</span>
100-
{% else %}
101-
<div style="display:inline-block;">
102-
{{ slicedString(channelName, 'padding-top: 2px;') }}
103-
</div>
104-
{% endif %}
105-
</a>
53+
{{ tagNavItemSub(channel, channelName) }}
10654
{% endif %}
10755
{% endfor %}
10856
</div>

partials/operations/by_tags_no_root.html

+7-59
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{% from "./tag_nav_item_sub.html" import tagNavItemSub %}
2+
{% from "./tag_nav_item_pub.html" import tagNavItemPub %}
3+
14
{% for tag in asyncapi | operationsTags %}
25
<div class="mt-4 {% if open %}is-open{% endif %}">
36
<div class="js-prop cursor-pointer py-2 flex property">
@@ -14,40 +17,11 @@
1417
<div class="children">
1518
{% for channelName, channel in asyncapi.channels() %}
1619
{% if channel.publish() and channel.publish().hasTags() and channel.publish() | containTags(tag) %}
17-
<a class="js-menu-item flex break-words no-underline text-grey-darkest mt-8 sm:mt-8 md:mt-3" href="#operation-publish-{{ channelName }}">
18-
<span class="bg-blue-dark font-bold h-6 no-underline text-white uppercase p-1 mr-2 rounded" style="height: 21px;font-size: 11px;" title="Publish">
19-
Pub
20-
</span>
21-
{% if channel.publish().summary() %}
22-
<span style="padding-top: 2px;">
23-
{{ channel.publish().summary() }}
24-
</span>
25-
{% else %}
26-
<div style="display:inline-block;">
27-
{{ slicedString(channelName, 'padding-top: 2px;') }}
28-
</div>
29-
{% endif %}
30-
</a>
20+
{{ tagNavItemPub(channel, channelName) }}
3121
{% endif %}
3222

3323
{% if channel.subscribe() and channel.subscribe().hasTags() and channel.subscribe() | containTags(tag) %}
34-
<a class="js-menu-item flex break-words no-underline text-grey-darkest mt-8 sm:mt-8 md:mt-3" href="#operation-subscribe-{{ channelName }}">
35-
{% if channel.deprecated %}
36-
<span title="Deprecated"></span>
37-
{% endif %}
38-
<span class="bg-green-dark font-bold no-underline text-white uppercase p-1 mr-2 rounded" style="height: 21px;font-size: 11px;" title="Subscribe">
39-
Sub
40-
</span>
41-
{% if channel.subscribe().summary() %}
42-
<span style="padding-top: 2px;">
43-
{{ channel.subscribe().summary() }}
44-
</span>
45-
{% else %}
46-
<div style="display:inline-block;">
47-
{{ slicedString(channelName, 'padding-top: 2px;') }}
48-
</div>
49-
{% endif %}
50-
</a>
24+
{{ tagNavItemSub(channel, channelName) }}
5125
{% endif %}
5226
{% endfor %}
5327
</div>
@@ -70,37 +44,11 @@
7044
<div class="children">
7145
{% for channelName, channel in asyncapi.channels() %}
7246
{% if channel.hasPublish() and (not channel.publish().hasTags() or not channel.publish() | containTags(asyncapi | operationsTags())) %}
73-
<a class="js-menu-item flex break-words no-underline text-grey-darkest mt-8 sm:mt-8 md:mt-3" href="#operation-publish-{{ channelName }}">
74-
<span class="bg-blue-dark font-bold h-6 no-underline text-white uppercase p-1 mr-2 rounded" style="height: 21px;font-size: 11px;" title="Publish">
75-
Pub
76-
</span>
77-
{% if channel.publish().summary() %}
78-
<span style="padding-top: 2px;">
79-
{{ channel.publish().summary() }}
80-
</span>
81-
{% else %}
82-
<div style="display:inline-block;">
83-
{{ slicedString(channelName, 'padding-top: 2px;') }}
84-
</div>
85-
{% endif %}
86-
</a>
47+
{{ tagNavItemPub(channel, channelName) }}
8748
{% endif %}
8849

8950
{% if channel.hasSubscribe() and (not channel.subscribe().hasTags() or not channel.subscribe() | containTags(asyncapi | operationsTags())) %}
90-
<a class="js-menu-item flex break-words no-underline text-grey-darkest mt-8 sm:mt-8 md:mt-3" href="#operation-subscribe-{{ channelName }}">
91-
<span class="bg-green-dark font-bold no-underline text-white uppercase p-1 mr-2 rounded" style="height: 21px;font-size: 11px;" title="Subscribe">
92-
Sub
93-
</span>
94-
{% if channel.subscribe().summary() %}
95-
<span style="padding-top: 2px;">
96-
{{ channel.subscribe().summary() }}
97-
</span>
98-
{% else %}
99-
<div style="display:inline-block;">
100-
{{ slicedString(channelName, 'padding-top: 2px;') }}
101-
</div>
102-
{% endif %}
103-
</a>
51+
{{ tagNavItemSub(channel, channelName) }}
10452
{% endif %}
10553
{% endfor %}
10654
</div>
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{% from "../sliced-string.html" import slicedString %}
2+
3+
4+
{% macro tagNavItemPub(channel, channelName) %}
5+
6+
<a class="js-menu-item flex break-words no-underline text-grey-darkest mt-8 sm:mt-8 md:mt-3"
7+
href="#operation-publish-{{ channelName }}">
8+
<span class="bg-blue-dark font-bold h-6 no-underline text-white uppercase p-1 mr-2 rounded"
9+
style="height: 21px;font-size: 11px;" title="Publish">
10+
Pub
11+
</span>
12+
{% if channel.publish().summary() %}
13+
<span style="padding-top: 2px;">
14+
{{ channel.publish().summary() }}
15+
</span>
16+
{% else %}
17+
<div style="display:inline-block;">
18+
{{ slicedString(channelName, 'padding-top: 2px;') }}
19+
</div>
20+
{% endif %}
21+
</a>
22+
23+
{% endmacro %}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{% from "../sliced-string.html" import slicedString %}
2+
3+
4+
{% macro tagNavItemSub(channel, channelName) %}
5+
6+
<a class="js-menu-item flex break-words no-underline text-grey-darkest mt-8 sm:mt-8 md:mt-3"
7+
href="#operation-subscribe-{{ channelName }}">
8+
<span class="bg-green-dark font-bold no-underline text-white uppercase p-1 mr-2 rounded"
9+
style="height: 21px;font-size: 11px;" title="Subscribe">
10+
Sub
11+
</span>
12+
{% if channel.subscribe().summary() %}
13+
<span style="padding-top: 2px;">
14+
{{ channel.subscribe().summary() }}
15+
</span>
16+
{% else %}
17+
<div style="display:inline-block;">
18+
{{ slicedString(channelName, 'padding-top: 2px;') }}
19+
</div>
20+
{% endif %}
21+
</a>
22+
23+
{% endmacro %}

0 commit comments

Comments
 (0)