-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathAPIDetails.vue
223 lines (198 loc) · 6.05 KB
/
APIDetails.vue
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<template>
<div>
<p>
<code>{{endpoint.method}} {{endpoint.url}}</code>
<span v-if=endpoint.endpoint_deprecated class="endpoint-details-deprecated">DEPRECATED</span>
</p>
<p v-if=endpoint.deprecated_url>
<code>{{endpoint.method}} {{endpoint.deprecated_url}}</code>
<span class="endpoint-details-deprecated">DEPRECATED</span>
</p>
<slot name="description">
<p>{{endpoint.description}}</p>
</slot>
<button
class="collapsible"
:class="{ 'active': expand }"
@click="toggle"
>
{{ expand ? 'Hide details' : 'Show details'}}
</button>
<div class="section-container content" ref="content">
<div class="details-content">
<h4 class="details-heading">Required Parameters</h4>
<div class="param-section">
<div
v-for="param in requiredParams"
:key="endpoint.name + param.name"
class="endpoint-details"
>
<div class="endpoint-details-heading">
<span class="endpoint-details-name">{{param.name}}</span>
<span class="endpoint-details-type">{{param.type}}</span>
<span v-if="param.deprecated" class="endpoint-details-deprecated">DEPRECATED</span>
</div>
<div v-if="typeof param.default !== 'undefined'" class="endpoint-details-default">
Default: {{param.default}}
</div>
<div
v-if="typeof param.deprecated_message !== 'undefined'"
class="endpoint-details-deprecated-message"
v-html="transform(param.deprecated_message)"
></div>
<div class="endpoint-details-description" v-html="transform(param.description)">
</div>
</div>
</div>
<slot name="required-parameters-notes"></slot>
<template v-if="optionalParams.length > 0">
<h4 class="details-heading">Optional Parameters</h4>
<div class="param-section">
<div
v-for="param in optionalParams" :key="endpoint.name + param.name"
class="endpoint-details"
>
<div class="endpoint-details-heading">
<span class="endpoint-details-name">{{param.name}}</span>
<span class="endpoint-details-type">{{param.type}}</span>
<span v-if="param.deprecated" class="endpoint-details-deprecated">DEPRECATED</span>
</div>
<div v-if="typeof param.default !== 'undefined'" class="endpoint-details-default">
<span class="heading">Defaults to: </span>
<span>{{param.default}}</span>
</div>
<div
v-if="typeof param.deprecated_message !== 'undefined'"
class="endpoint-details-deprecated-message"
v-html="transform(param.deprecated_message)"
></div>
<div class="endpoint-details-description" v-html="transform(param.description)">
</div>
</div>
</div>
<slot name="optional-parameters-notes"></slot>
</template>
<h4 class="details-heading">Response</h4>
<slot name="response">
<p>{{endpoint.response}}</p>
</slot>
</div>
<div class="example-content">
<h4 v-if="$slots.example" class="details-heading">Example</h4>
<slot name="example"></slot>
</div>
</div>
</div>
</template>
<script>
export default {
props: {
endpoint: {
required: true,
type: Object,
},
},
data() {
return {
expand: false,
};
},
computed: {
requiredParams() {
return this.endpoint.params.filter(p => p.required);
},
optionalParams() {
return this.endpoint.params.filter(p => !p.required);
},
},
methods: {
transform(description) {
// replace code
description = description.replace (/`(.*?)`/g, "<code>$1</code>");
// replace links
description = description.replace (/\[(.*?)\]\((.*?)\)/g, '<a href="$2">$1</a>');
return description
},
to_array(s) {
return s.split(',')
},
toggle() {
this.expand = !this.expand;
if (this.$refs.content.style.maxHeight){
this.$refs.content.style.maxHeight = null;
} else {
// We add an extra 500px here to cater for python examples being longer.
// Since it is `max-height` this wan't make a difference to the rendered layout,
// but if there is a cleaner way, feel free to replace this hastily put together
// hack.
this.$refs.content.style.maxHeight = this.$refs.content.scrollHeight + 500 + "px";
}
}
}
}
</script>
<style lang="stylus" scoped>
.details-heading
text-transform: uppercase
padding-top: 15px
.endpoint-details
border-bottom: 1px solid lighten($borderColor, 10%)
padding-top: 10px
padding-bottom: 10px
.theme-dark .endpoint-details
border-bottom: 1px solid darken($borderColor, 40%)
.endpoint-details-name
font-weight: bold
font-size: 1.1em
.endpoint-details-type
font-style: italic
font-size: 0.8em
.endpoint-details-default
color: $badgeWarningColor
font-size: 0.8em
& .heading
font-style: italic
.endpoint-details-deprecated
color: $badgeErrorColor
font-size: 0.8em
.endpoint-details-deprecated-message
color: $badgeErrorColor
font-size: 0.8em
font-style: italic
margin-top: 1em
margin-bottom: 1em
.endpoint-details-description
font-size: 0.9em
button:focus
outline:0
.collapsible
cursor: pointer
display: inline-block
padding: 5px
border-radius: 6px
color: $textColor
border: none
box-shadow: $boxShadow
font-size: 12px
width 100px
.content
max-height: 0
overflow: hidden
transition: max-height 0.4s ease-out
.collapsible:after
content: '\02795'
font-size: 9px
color: #ccc
float: right
margin-left: 5px
.active:after
content: '\2796'
.theme-dark
.collapsible
box-shadow: none;
border-style: solid;
border-width: 1px;
background-color: $nightBgcolor
&:hover
color: lighten($nightFontcolor, 5%)
</style>