Skip to content
Browse files

Added scrollTo functionality and handle responseTypes from live reque…

…st that may be different from documented response
  • Loading branch information...
1 parent 5964573 commit 07476ffcf0f9ed8dd21127255d677d17a7b46b0e @TildeWill committed
View
16 example/public/docs/assets/javascripts/application.js
@@ -215,13 +215,23 @@ function Wurl(wurlForm) {
$('.response.headers', self.$wurlForm).html(jqXHR.getAllResponseHeaders());
- if(jqXHR.responseText.length > 1) {
+ contentType = jqXHR.getResponseHeader("content-type");
+ if (contentType.indexOf('json') >= 0 && jqXHR.responseText.length > 1) {
self.responseBodyMirror.setValue(JSON.stringify(JSON.parse(jqXHR.responseText), undefined, 2));
+ self.responseBodyMirror.setOption('mode', 'javascript');
+ self.responseBodyMirror.setOption('json', true);
+ } else if (contentType.indexOf('javascript') >= 0) {
+ self.responseBodyMirror.setValue(jqXHR.responseText);
+ self.responseBodyMirror.setOption('mode', 'javascript');
+ } else if (contentType.indexOf('xml') >= 0) {
+ self.responseBodyMirror.setValue(jqXHR.responseText);
+ self.responseBodyMirror.setOption('mode', 'xml');
} else {
- self.responseBodyMirror.setValue("");
+ self.responseBodyMirror.setValue(jqXHR.responseText);
+ self.responseBodyMirror.setOption('mode', 'htmlmixed');
}
$('.response', self.$wurlForm).effect("highlight", {}, 3000);
- $('a#response', self.$wurlForm).focus();
+ $('html,body').animate({ scrollTop:$('a.response_anchor', self.$wurlForm).offset().top }, { duration:'slow', easing:'swing'});
}
});
};
View
8 example/public/docs/orders/creating_an_order.html
@@ -239,14 +239,14 @@
</div>
</form>
- <h3><a name="response"></a>Response</h3>
+ <h3><a class="response_anchor"></a>Response</h3>
<h4>Headers</h4>
<pre class="response headers">Content-Type: application/json; charset=utf-8
Location: http://example.org/orders/1
X-UA-Compatible: IE=Edge,chrome=1
ETag: &quot;5fffd66f61cdd4ab8881584dbf5e72cf&quot;
Cache-Control: max-age=0, private, must-revalidate
-X-Runtime: 0.010868
+X-Runtime: 0.012315
Content-Length: 58</pre>
<h4>Status</h4>
@@ -415,13 +415,13 @@
</div>
</form>
- <h3><a name="response"></a>Response</h3>
+ <h3><a class="response_anchor"></a>Response</h3>
<h4>Headers</h4>
<pre class="response headers">Content-Type: application/json; charset=utf-8
X-UA-Compatible: IE=Edge,chrome=1
ETag: &quot;5fffd66f61cdd4ab8881584dbf5e72cf&quot;
Cache-Control: max-age=0, private, must-revalidate
-X-Runtime: 0.008403
+X-Runtime: 0.007060
Content-Length: 58</pre>
<h4>Status</h4>
View
2 example/public/docs/orders/creating_an_order.json
@@ -1 +1 @@
-{"resource":"Orders","description":"Creating an order","explanation":"First, create an order, then make a later request to get it back","parameters":[{"name":"name","description":"Name of order","required":true,"scope":"order"},{"name":"paid","description":"If the order has been paid for","required":true,"scope":"order"},{"name":"email","description":"Email of user that placed the order","scope":"order"}],"requests":[{"method":"post","route":"/orders","query_string":null,"request_body":"{\"order\":{\"name\":\"Order 1\",\"paid\":true,\"email\":\"email@example.com\"}}","request_content_type":"application/json","response_content_type":"application/json; charset=utf-8","request_headers":{"Accept":"application/json","Content-Type":"application/json","Host":"example.org","Cookie":""},"request_query_parameters":[],"response_status":"201 - Created","response_body":"{\"email\":\"email@example.com\",\"name\":\"Order 1\",\"paid\":true}","response_headers":{"Content-Type":"application/json; charset=utf-8","Location":"http://example.org/orders/1","X-UA-Compatible":"IE=Edge,chrome=1","ETag":"\"5fffd66f61cdd4ab8881584dbf5e72cf\"","Cache-Control":"max-age=0, private, must-revalidate","X-Runtime":"0.010868","Content-Length":"58"},"curl":"curl \"http://localhost:3000/orders\" -d \"{\"order\":{\"name\":\"Order 1\",\"paid\":true,\"email\":\"email@example.com\"}}\" -X POST -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Host: example.org\" -H \"Cookie: \""},{"method":"get","route":"/orders/1","query_string":null,"request_body":null,"request_content_type":"application/json","response_content_type":"application/json; charset=utf-8","request_headers":{"Accept":"application/json","Content-Type":"application/json","Host":"example.org","Cookie":""},"request_query_parameters":[],"response_status":"200 - OK","response_body":"{\"email\":\"email@example.com\",\"name\":\"Order 1\",\"paid\":true}","response_headers":{"Content-Type":"application/json; charset=utf-8","X-UA-Compatible":"IE=Edge,chrome=1","ETag":"\"5fffd66f61cdd4ab8881584dbf5e72cf\"","Cache-Control":"max-age=0, private, must-revalidate","X-Runtime":"0.008403","Content-Length":"58"},"curl":"curl \"http://localhost:3000/orders/1\" -X GET -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Host: example.org\" -H \"Cookie: \""}]}
+{"resource":"Orders","description":"Creating an order","explanation":"First, create an order, then make a later request to get it back","parameters":[{"name":"name","description":"Name of order","required":true,"scope":"order"},{"name":"paid","description":"If the order has been paid for","required":true,"scope":"order"},{"name":"email","description":"Email of user that placed the order","scope":"order"}],"requests":[{"method":"post","route":"/orders","query_string":null,"request_body":"{\"order\":{\"name\":\"Order 1\",\"paid\":true,\"email\":\"email@example.com\"}}","request_content_type":"application/json","response_content_type":"application/json; charset=utf-8","request_headers":{"Accept":"application/json","Content-Type":"application/json","Host":"example.org","Cookie":""},"request_query_parameters":[],"response_status":"201 - Created","response_body":"{\"email\":\"email@example.com\",\"name\":\"Order 1\",\"paid\":true}","response_headers":{"Content-Type":"application/json; charset=utf-8","Location":"http://example.org/orders/1","X-UA-Compatible":"IE=Edge,chrome=1","ETag":"\"5fffd66f61cdd4ab8881584dbf5e72cf\"","Cache-Control":"max-age=0, private, must-revalidate","X-Runtime":"0.012315","Content-Length":"58"},"curl":"curl \"http://localhost:3000/orders\" -d \"{\"order\":{\"name\":\"Order 1\",\"paid\":true,\"email\":\"email@example.com\"}}\" -X POST -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Host: example.org\" -H \"Cookie: \""},{"method":"get","route":"/orders/1","query_string":null,"request_body":null,"request_content_type":"application/json","response_content_type":"application/json; charset=utf-8","request_headers":{"Accept":"application/json","Content-Type":"application/json","Host":"example.org","Cookie":""},"request_query_parameters":[],"response_status":"200 - OK","response_body":"{\"email\":\"email@example.com\",\"name\":\"Order 1\",\"paid\":true}","response_headers":{"Content-Type":"application/json; charset=utf-8","X-UA-Compatible":"IE=Edge,chrome=1","ETag":"\"5fffd66f61cdd4ab8881584dbf5e72cf\"","Cache-Control":"max-age=0, private, must-revalidate","X-Runtime":"0.007060","Content-Length":"58"},"curl":"curl \"http://localhost:3000/orders/1\" -X GET -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Host: example.org\" -H \"Cookie: \""}]}
View
4 example/public/docs/orders/deleting_an_order.html
@@ -196,14 +196,14 @@
</div>
</form>
- <h3><a name="response"></a>Response</h3>
+ <h3><a class="response_anchor"></a>Response</h3>
<h4>Headers</h4>
<pre class="response headers">Content-Type: application/json; charset=utf-8
Location: http://example.org/orders
X-UA-Compatible: IE=Edge,chrome=1
ETag: &quot;99914b932bd37a50b983c5e7c90ae93b&quot;
Cache-Control: max-age=0, private, must-revalidate
-X-Runtime: 0.007347
+X-Runtime: 0.007077
Content-Length: 2</pre>
<h4>Status</h4>
View
2 example/public/docs/orders/deleting_an_order.json
@@ -1 +1 @@
-{"resource":"Orders","description":"Deleting an order","explanation":null,"parameters":[],"requests":[{"method":"delete","route":"/orders/1","query_string":null,"request_body":null,"request_content_type":"application/json","response_content_type":"application/json; charset=utf-8","request_headers":{"Accept":"application/json","Content-Type":"application/json","Host":"example.org","Cookie":""},"request_query_parameters":[],"response_status":"200 - OK","response_body":"{}","response_headers":{"Content-Type":"application/json; charset=utf-8","Location":"http://example.org/orders","X-UA-Compatible":"IE=Edge,chrome=1","ETag":"\"99914b932bd37a50b983c5e7c90ae93b\"","Cache-Control":"max-age=0, private, must-revalidate","X-Runtime":"0.007347","Content-Length":"2"},"curl":"curl \"http://localhost:3000/orders/1\" -d \"\" -X DELETE -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Host: example.org\" -H \"Cookie: \""}]}
+{"resource":"Orders","description":"Deleting an order","explanation":null,"parameters":[],"requests":[{"method":"delete","route":"/orders/1","query_string":null,"request_body":null,"request_content_type":"application/json","response_content_type":"application/json; charset=utf-8","request_headers":{"Accept":"application/json","Content-Type":"application/json","Host":"example.org","Cookie":""},"request_query_parameters":[],"response_status":"200 - OK","response_body":"{}","response_headers":{"Content-Type":"application/json; charset=utf-8","Location":"http://example.org/orders","X-UA-Compatible":"IE=Edge,chrome=1","ETag":"\"99914b932bd37a50b983c5e7c90ae93b\"","Cache-Control":"max-age=0, private, must-revalidate","X-Runtime":"0.007077","Content-Length":"2"},"curl":"curl \"http://localhost:3000/orders/1\" -d \"\" -X DELETE -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Host: example.org\" -H \"Cookie: \""}]}
View
4 example/public/docs/orders/getting_a_list_of_orders.html
@@ -226,13 +226,13 @@
</div>
</form>
- <h3><a name="response"></a>Response</h3>
+ <h3><a class="response_anchor"></a>Response</h3>
<h4>Headers</h4>
<pre class="response headers">Content-Type: application/json; charset=utf-8
X-UA-Compatible: IE=Edge,chrome=1
ETag: &quot;6cd5831e98b0090b64672b5604d9eb2a&quot;
Cache-Control: max-age=0, private, must-revalidate
-X-Runtime: 0.081830
+X-Runtime: 0.083445
Content-Length: 121</pre>
<h4>Status</h4>
View
2 example/public/docs/orders/getting_a_list_of_orders.json
@@ -1 +1 @@
-{"resource":"Orders","description":"Getting a list of orders","explanation":null,"parameters":[{"name":"page","description":"Current page of orders"}],"requests":[{"method":"get","route":"/orders","query_string":"?page=1","request_body":null,"request_content_type":"application/json","response_content_type":"application/json; charset=utf-8","request_headers":{"Accept":"application/json","Content-Type":"application/json","Host":"example.org","Cookie":""},"request_query_parameters":[{"name":"page","value":"1"}],"response_status":"200 - OK","response_body":"[{\"email\":\"email0@example.com\",\"name\":\"Order 0\",\"paid\":true},{\"email\":\"email1@example.com\",\"name\":\"Order 1\",\"paid\":true}]","response_headers":{"Content-Type":"application/json; charset=utf-8","X-UA-Compatible":"IE=Edge,chrome=1","ETag":"\"6cd5831e98b0090b64672b5604d9eb2a\"","Cache-Control":"max-age=0, private, must-revalidate","X-Runtime":"0.081830","Content-Length":"121"},"curl":"curl \"http://localhost:3000/orders?page=1\" -X GET -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Host: example.org\" -H \"Cookie: \""}]}
+{"resource":"Orders","description":"Getting a list of orders","explanation":null,"parameters":[{"name":"page","description":"Current page of orders"}],"requests":[{"method":"get","route":"/orders","query_string":"?page=1","request_body":null,"request_content_type":"application/json","response_content_type":"application/json; charset=utf-8","request_headers":{"Accept":"application/json","Content-Type":"application/json","Host":"example.org","Cookie":""},"request_query_parameters":[{"name":"page","value":"1"}],"response_status":"200 - OK","response_body":"[{\"email\":\"email0@example.com\",\"name\":\"Order 0\",\"paid\":true},{\"email\":\"email1@example.com\",\"name\":\"Order 1\",\"paid\":true}]","response_headers":{"Content-Type":"application/json; charset=utf-8","X-UA-Compatible":"IE=Edge,chrome=1","ETag":"\"6cd5831e98b0090b64672b5604d9eb2a\"","Cache-Control":"max-age=0, private, must-revalidate","X-Runtime":"0.083445","Content-Length":"121"},"curl":"curl \"http://localhost:3000/orders?page=1\" -X GET -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Host: example.org\" -H \"Cookie: \""}]}
View
4 example/public/docs/orders/getting_a_specific_order.html
@@ -196,13 +196,13 @@
</div>
</form>
- <h3><a name="response"></a>Response</h3>
+ <h3><a class="response_anchor"></a>Response</h3>
<h4>Headers</h4>
<pre class="response headers">Content-Type: application/json; charset=utf-8
X-UA-Compatible: IE=Edge,chrome=1
ETag: &quot;d9eaba14696a65b9dfc66bf203d25a13&quot;
Cache-Control: max-age=0, private, must-revalidate
-X-Runtime: 0.006956
+X-Runtime: 0.012546
Content-Length: 59</pre>
<h4>Status</h4>
View
2 example/public/docs/orders/getting_a_specific_order.json
@@ -1 +1 @@
-{"resource":"Orders","description":"Getting a specific order","explanation":null,"parameters":[],"requests":[{"method":"get","route":"/orders/1","query_string":null,"request_body":null,"request_content_type":"application/json","response_content_type":"application/json; charset=utf-8","request_headers":{"Accept":"application/json","Content-Type":"application/json","Host":"example.org","Cookie":""},"request_query_parameters":[],"response_status":"200 - OK","response_body":"{\"email\":\"email@example.com\",\"name\":\"Old Name\",\"paid\":true}","response_headers":{"Content-Type":"application/json; charset=utf-8","X-UA-Compatible":"IE=Edge,chrome=1","ETag":"\"d9eaba14696a65b9dfc66bf203d25a13\"","Cache-Control":"max-age=0, private, must-revalidate","X-Runtime":"0.006956","Content-Length":"59"},"curl":"curl \"http://localhost:3000/orders/1\" -X GET -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Host: example.org\" -H \"Cookie: \""}]}
+{"resource":"Orders","description":"Getting a specific order","explanation":null,"parameters":[],"requests":[{"method":"get","route":"/orders/1","query_string":null,"request_body":null,"request_content_type":"application/json","response_content_type":"application/json; charset=utf-8","request_headers":{"Accept":"application/json","Content-Type":"application/json","Host":"example.org","Cookie":""},"request_query_parameters":[],"response_status":"200 - OK","response_body":"{\"email\":\"email@example.com\",\"name\":\"Old Name\",\"paid\":true}","response_headers":{"Content-Type":"application/json; charset=utf-8","X-UA-Compatible":"IE=Edge,chrome=1","ETag":"\"d9eaba14696a65b9dfc66bf203d25a13\"","Cache-Control":"max-age=0, private, must-revalidate","X-Runtime":"0.012546","Content-Length":"59"},"curl":"curl \"http://localhost:3000/orders/1\" -X GET -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Host: example.org\" -H \"Cookie: \""}]}
View
4 example/public/docs/orders/updating_an_order.html
@@ -236,14 +236,14 @@
</div>
</form>
- <h3><a name="response"></a>Response</h3>
+ <h3><a class="response_anchor"></a>Response</h3>
<h4>Headers</h4>
<pre class="response headers">Content-Type: application/json; charset=utf-8
Location: http://example.org/orders/1
X-UA-Compatible: IE=Edge,chrome=1
ETag: &quot;99914b932bd37a50b983c5e7c90ae93b&quot;
Cache-Control: max-age=0, private, must-revalidate
-X-Runtime: 0.008171
+X-Runtime: 0.008473
Content-Length: 2</pre>
<h4>Status</h4>
View
2 example/public/docs/orders/updating_an_order.json
@@ -1 +1 @@
-{"resource":"Orders","description":"Updating an order","explanation":null,"parameters":[{"name":"name","description":"Name of order","scope":"order"},{"name":"paid","description":"If the order has been paid for","scope":"order"},{"name":"email","description":"Email of user that placed the order","scope":"order"}],"requests":[{"method":"put","route":"/orders/1","query_string":null,"request_body":"{\"order\":{\"name\":\"Updated Name\"}}","request_content_type":"application/json","response_content_type":"application/json; charset=utf-8","request_headers":{"Accept":"application/json","Content-Type":"application/json","Host":"example.org","Cookie":""},"request_query_parameters":[],"response_status":"200 - OK","response_body":"{}","response_headers":{"Content-Type":"application/json; charset=utf-8","Location":"http://example.org/orders/1","X-UA-Compatible":"IE=Edge,chrome=1","ETag":"\"99914b932bd37a50b983c5e7c90ae93b\"","Cache-Control":"max-age=0, private, must-revalidate","X-Runtime":"0.008171","Content-Length":"2"},"curl":"curl \"http://localhost:3000/orders/1\" -d \"{\"order\":{\"name\":\"Updated Name\"}}\" -X PUT -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Host: example.org\" -H \"Cookie: \""}]}
+{"resource":"Orders","description":"Updating an order","explanation":null,"parameters":[{"name":"name","description":"Name of order","scope":"order"},{"name":"paid","description":"If the order has been paid for","scope":"order"},{"name":"email","description":"Email of user that placed the order","scope":"order"}],"requests":[{"method":"put","route":"/orders/1","query_string":null,"request_body":"{\"order\":{\"name\":\"Updated Name\"}}","request_content_type":"application/json","response_content_type":"application/json; charset=utf-8","request_headers":{"Accept":"application/json","Content-Type":"application/json","Host":"example.org","Cookie":""},"request_query_parameters":[],"response_status":"200 - OK","response_body":"{}","response_headers":{"Content-Type":"application/json; charset=utf-8","Location":"http://example.org/orders/1","X-UA-Compatible":"IE=Edge,chrome=1","ETag":"\"99914b932bd37a50b983c5e7c90ae93b\"","Cache-Control":"max-age=0, private, must-revalidate","X-Runtime":"0.008473","Content-Length":"2"},"curl":"curl \"http://localhost:3000/orders/1\" -d \"{\"order\":{\"name\":\"Updated Name\"}}\" -X PUT -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Host: example.org\" -H \"Cookie: \""}]}
View
16 templates/assets/javascripts/application.js
@@ -215,13 +215,23 @@ function Wurl(wurlForm) {
$('.response.headers', self.$wurlForm).html(jqXHR.getAllResponseHeaders());
- if(jqXHR.responseText.length > 1) {
+ contentType = jqXHR.getResponseHeader("content-type");
+ if (contentType.indexOf('json') >= 0 && jqXHR.responseText.length > 1) {
self.responseBodyMirror.setValue(JSON.stringify(JSON.parse(jqXHR.responseText), undefined, 2));
+ self.responseBodyMirror.setOption('mode', 'javascript');
+ self.responseBodyMirror.setOption('json', true);
+ } else if (contentType.indexOf('javascript') >= 0) {
+ self.responseBodyMirror.setValue(jqXHR.responseText);
+ self.responseBodyMirror.setOption('mode', 'javascript');
+ } else if (contentType.indexOf('xml') >= 0) {
+ self.responseBodyMirror.setValue(jqXHR.responseText);
+ self.responseBodyMirror.setOption('mode', 'xml');
} else {
- self.responseBodyMirror.setValue("");
+ self.responseBodyMirror.setValue(jqXHR.responseText);
+ self.responseBodyMirror.setOption('mode', 'htmlmixed');
}
$('.response', self.$wurlForm).effect("highlight", {}, 3000);
- $('a#response', self.$wurlForm).focus();
+ $('html,body').animate({ scrollTop:$('a.response_anchor', self.$wurlForm).offset().top }, { duration:'slow', easing:'swing'});
}
});
};
View
2 templates/rspec_api_documentation/html_example.mustache
@@ -215,7 +215,7 @@
</div>
</form>
- <h3><a name="response"></a>Response</h3>
+ <h3><a class="response_anchor"></a>Response</h3>
<h4>Headers</h4>
<pre class="response headers">{{ response_headers_text }}</pre>

0 comments on commit 07476ff

Please sign in to comment.
Something went wrong with that request. Please try again.