This repository has been archived by the owner on Feb 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raml-docs-response-panel.html
196 lines (180 loc) · 7.37 KB
/
raml-docs-response-panel.html
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
<!--
@license
Copyright 2016 The Advanced REST client authors <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-styles/paper-styles.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../paper-item/paper-item.html">
<link rel="import" href="../paper-menu/paper-menu.html">
<link rel="import" href="../marked-element/marked-element.html">
<link rel="import" href="../markdown-styles/markdown-styles.html">
<link rel="import" href="../docs-parameters-table/docs-body-parameters-table.html">
<link rel="import" href="../docs-parameters-table/docs-headers-table.html">
<link rel="import" href="raml-docs-response-status-selector.html">
<!--
`<raml-docs-response-panel>` Element that displays response documentation for RAML
This element is used in `<raml-docs-method-viewer>` element.
See it's demo for demo.
### Example
```
<raml-docs-response-panel responses="[[raml.responses]]"></raml-docs-response-panel>
```
The `raml.responses` is a list of responses for current method. It can be
obtained using a `raml-path-to-object` element or by passing method Definition
from RAML's JSON structure.
Note, you have to use ARC's `<raml-js-parser>` since it is also responsoble
for transformind parser JSON output to internal data structure.
## Element's width and overflow
The code blocks generated by the element can be wide. This is why this element
has the CSS `overflow` property set to `auto` by default. In this case you can
set the `max-width` or `width` propety on this element (or any parent element)
and it will be respected.
### Styling
`<raml-docs-response-panel>` provides the following custom properties and mixins for styling:
Custom property | Description | Default
----------------|-------------|----------
`--raml-docs-response-panel` | Mixin applied to the element | `{}`
`--arc-status-code-color-200` | Color of the 200 status code (ARC theme option) | `rgba(56, 142, 60, 1)` |
`--arc-status-code-color-300` | Color of the 300 status code (ARC theme option) | `rgba(48, 63, 159, 1)` |
`--arc-status-code-color-400` | Color of the 400 status code (ARC theme option) | `rgba(245, 124, 0, 1)` |
`--arc-status-code-color-500` | Color of the 500 status code (ARC theme option) | `rgba(211, 47, 47, 1)` |
`--arc-status-code-bgcolor-200` | Background color of the 200 status code | `rgba(56, 142, 60, 0.12)` |
`--arc-status-code-bgcolor-300` | Background color of the 300 status code | `rgba(48, 63, 159, 0.12)` |
`--arc-status-code-bgcolor-400` | Background color of the 400 status code | `rgba(245, 124, 0, 0.12)` |
`--arc-status-code-bgcolor-500` | Background color of the 500 status code | `rgba(211, 47, 47, 0.12)` |
`--raml-docs-response-panel-codes-border-color` | Border color of the response codes column | `rgba(0, 161, 223, 0.24)`
`--no-info-message` | A mixin applied to the "missing type" paragraph. | `{}` |
`--raml-docs-response-panel-container` | A mixin applied to the element's main container | `{}`
`--raml-docs-response-panel-codes-content` | A mixin applied to the element's status codes container | `{}`
`--raml-docs-response-panel-docs-content` | A mixin applied to the element's documentation content container | `{}`
@group RAML Elements
@element raml-docs-response-panel
@demo demo/index.html
-->
<dom-module id="raml-docs-response-panel">
<template>
<style include="markdown-styles"></style>
<style>
:host {
display: block;
@apply(--raml-docs-response-panel);
}
h4 {
@apply(--raml-docs-response-panel-headers-title);
}
.container {
@apply(--layout-horizontal);
@apply(--raml-docs-response-panel-container);
}
.docs {
@apply(--layout-flex);
@apply(--paper-font-body1);
margin-left: 16px;
overflow: auto;
@apply(--raml-docs-response-panel-docs-content);
}
.no-data-info {
@apply(--no-info-message);
}
</style>
<div class="container">
<raml-docs-response-status-selector responses="[[responses]]" selected-response="{{selectedResponse}}" selected="{{selected}}"></raml-docs-response-status-selector>
<div class="docs">
<section>
<template is="dom-if" if="[[selectedResponse.description]]">
<marked-element markdown="[[selectedResponse.description]]">
<div class="markdown-html"></div>
</marked-element>
</template>
<p class="no-data-info" hidden$="[[hasProperties]]">No description provided.</p>
<template is="dom-if" if="[[_hasProperty(selectedResponse, 'headers')]]">
<h4 class="sub-title">Response headers</h4>
<docs-headers-table headers="[[selectedResponse.headers]]"></docs-headers-table>
</template>
<template is="dom-if" if="[[_hasProperty(selectedResponse, 'body')]]">
<docs-body-parameters-table body="[[selectedResponse.body]]"></docs-body-parameters-table>
</template>
</section>
</div>
</div>
</template>
<script>
Polymer({
is: 'raml-docs-response-panel',
properties: {
// List of responses - RAML definition (JSON)
responses: Array,
// Computed value if currently panel has anything to display
hasResponses: {
type: Boolean,
notify: true,
readOnly: true,
value: false,
computed: '_computeHasResponses(responses)'
},
/**
* Computed value, true if selected response has description or
* body declaration.
* It is used to display empty data message if none of this properties
* are set.
*/
hasProperties: {
type: Boolean,
computed: '_computeHasProperties(selectedResponse)'
},
/**
* Selected response's index.
* This will be set to default (0, zero) value when `responses`
* array change.
*/
selected: Number
},
// Computes `hasResponses` property.
_computeHasResponses: function(responses) {
// var responses = record && record.base;
return !!(responses && responses.length);
},
/**
* Checks if given `obj` has a `property`.
*
* @param {Object} obj Object to check
* @param {String} property Property name of the object
* @return {Boolean} True if the `obj` contains a `property`.
*/
_hasProperty: function(obj, property) {
if (!obj) {
return false;
}
return property in obj;
},
/**
* Computes `hasProperties` value.
*
* @param {Object} response Currently selected response.
* @return {Boolean} True if the response has description or body.
*/
_computeHasProperties: function(response) {
if (!response) {
return false;
}
if (response.description) {
return true;
}
if (response.body && response.body.length) {
return true;
}
return false;
}
});
</script>
</dom-module>