Skip to content

Commit

Permalink
updates for displays of response samples
Browse files Browse the repository at this point in the history
  • Loading branch information
jclausen committed Mar 18, 2016
1 parent 7229943 commit 5aea603
Show file tree
Hide file tree
Showing 19 changed files with 245 additions and 47 deletions.
9 changes: 9 additions & 0 deletions Gruntfile.js
Expand Up @@ -14,6 +14,15 @@ module.exports = function(grunt) {
jsModel: {
files: ['includes/jsdev/models/*.js'],
tasks: ['uglify:modelJS']
},

jsGlobals: {
files: [
'includes/jsdev/app.js',
'includes/jsdev/globals.js',
'includes/jsdev/udf.js'
],
tasks: ['requirejs:compile','uglify:viewJS','uglify:modelJS']
}
},
sass: {
Expand Down
72 changes: 72 additions & 0 deletions includes/jsdev/udf.js
Expand Up @@ -11,6 +11,31 @@ function openRemoteModal( url, params ){
$remoteModal.modal( "show" );
}

function formatAPIExample( example, mimetype ){
switch( mimetype ){
case "application/xml":
case "text/xml":
case "xml":

return escapeHtml( formatXML(example) );

case "application/json":
case "application/jsonp":
case "application/jsont":
if( typeof( example ) === 'object' ){
return formatJSONRaw( JSON.stringify( example ) ).trim();
} else {
return formatJSONRaw( example ).trim();
}
default:
if( typeof( example ) === 'object' || typeof( example ) === 'array' ){
return formatJSONRaw( JSON.stringify( example ) ).trim();
} else {
return example;
}
}
}

function formatJSON( id ){
$( "#" + id ).val( formatJSONRaw( $( "#" + id ).val() ) );
}
Expand All @@ -32,6 +57,53 @@ function formatJSONRaw( jsonData ){
}
}

function formatXML(xml) {
var formatted = '';
var reg = /(>)(<)(\/*)/g;
xml = xml.replace(reg, '$1\r\n$2$3');
var pad = 0;
$.each(xml.split('\r\n'), function(index, node) {
var indent = 0;
if (node.match( /.+<\/\w[^>]*>$/ )) {
indent = 0;
} else if (node.match( /^<\/\w/ )) {
if (pad != 0) {
pad -= 1;
}
} else if (node.match( /^<\w[^>]*[^\/]>.*$/ )) {
indent = 1;
} else {
indent = 0;
}

var padding = '';
for (var i = 0; i < pad; i++) {
padding += ' ';
}

formatted += padding + node + '\r\n';
pad += indent;
});

return formatted.trim();
}


var entityMap = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;'
};

function escapeHtml(string) {
return String(string).replace(/[&<>"'\/]/g, function (s) {
return entityMap[s];
});
}

function toggleResource(id){
var $div = $( "#resource_" + id );
$div.slideToggle();
Expand Down
2 changes: 0 additions & 2 deletions includes/jsdev/views/export.html.js
Expand Up @@ -56,8 +56,6 @@ define([
            * ----------------------------------------------
            */
,setupDefaults:function(){
console.log( Messenger );
//this.Messenger = new Messenger();

return this;
}
Expand Down
1 change: 0 additions & 1 deletion includes/jsdev/views/relax.relaxer.js
Expand Up @@ -211,7 +211,6 @@ define([
var index = $("#requestHistory").val();
if( index != "null" ){
var item = reqHistory[index].DATA;
//console.log(item);

$("#advancedSettings").slideDown();
// main options
Expand Down
2 changes: 0 additions & 2 deletions includes/jsdev/views/widgets/sidebar.js
Expand Up @@ -100,8 +100,6 @@ define([
,onSelectAPI: function( e ){
var _this = this;
var $select = $( e.currentTarget );
console.log( $select.length );
console.log( $select.val() );
var selectedAPI = $select.val();
_this.ViewModel.set( 'id', selectedAPI );
_this.View.renderLoaderMessage();
Expand Down
2 changes: 1 addition & 1 deletion modules/relax/ModuleConfig.cfc
Expand Up @@ -146,7 +146,7 @@ component{
// Default Config Structure
configStruct.relax = {
APILocation = "#moduleMapping#.models.resources",
defaultAPI = "petstore",
defaultAPI = "myapi",
maxHistory = 10,
sessionsEnabled = getApplicationMetadata().sessionManagement
};
Expand Down
2 changes: 1 addition & 1 deletion modules/relax/includes/js/models/RelaxAPI.js
@@ -1,4 +1,4 @@
/*! Copyright 2016 - Ortus Solutions (Compiled: 14-03-2016) */
/*! Copyright 2016 - Ortus Solutions (Compiled: 18-03-2016) */
define([ "Backbone" ], function(Backbone) {
"use strict";
var Model = Backbone.Model.extend({
Expand Down
72 changes: 72 additions & 0 deletions modules/relax/includes/js/udf.js
Expand Up @@ -11,6 +11,31 @@ function openRemoteModal( url, params ){
$remoteModal.modal( "show" );
}

function formatAPIExample( example, mimetype ){
switch( mimetype ){
case "application/xml":
case "text/xml":
case "xml":

return escapeHtml( formatXML(example) );

case "application/json":
case "application/jsonp":
case "application/jsont":
if( typeof( example ) === 'object' ){
return formatJSONRaw( JSON.stringify( example ) ).trim();
} else {
return formatJSONRaw( example ).trim();
}
default:
if( typeof( example ) === 'object' || typeof( example ) === 'array' ){
return formatJSONRaw( JSON.stringify( example ) ).trim();
} else {
return example;
}
}
}

function formatJSON( id ){
$( "#" + id ).val( formatJSONRaw( $( "#" + id ).val() ) );
}
Expand All @@ -32,6 +57,53 @@ function formatJSONRaw( jsonData ){
}
}

function formatXML(xml) {
var formatted = '';
var reg = /(>)(<)(\/*)/g;
xml = xml.replace(reg, '$1\r\n$2$3');
var pad = 0;
$.each(xml.split('\r\n'), function(index, node) {
var indent = 0;
if (node.match( /.+<\/\w[^>]*>$/ )) {
indent = 0;
} else if (node.match( /^<\/\w/ )) {
if (pad != 0) {
pad -= 1;
}
} else if (node.match( /^<\w[^>]*[^\/]>.*$/ )) {
indent = 1;
} else {
indent = 0;
}

var padding = '';
for (var i = 0; i < pad; i++) {
padding += ' ';
}

formatted += padding + node + '\r\n';
pad += indent;
});

return formatted.trim();
}


var entityMap = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;'
};

function escapeHtml(string) {
return String(string).replace(/[&<>"'\/]/g, function (s) {
return entityMap[s];
});
}

function toggleResource(id){
var $div = $( "#resource_" + id );
$div.slideToggle();
Expand Down
3 changes: 1 addition & 2 deletions modules/relax/includes/js/views/export.html.js
@@ -1,4 +1,4 @@
/*! Copyright 2016 - Ortus Solutions (Compiled: 15-03-2016) */
/*! Copyright 2016 - Ortus Solutions (Compiled: 18-03-2016) */
define([ "Backbone", "clipboard", "messenger", "views/home.index" ], function(Backbone, Clipboard, Messenger, APIView) {
"use strict";
var View = Backbone.View.extend({
Expand All @@ -20,7 +20,6 @@ define([ "Backbone", "clipboard", "messenger", "views/home.index" ], function(Ba
return this;
},
setupDefaults: function() {
console.log(Messenger);
return this;
},
render: function() {
Expand Down
2 changes: 1 addition & 1 deletion modules/relax/includes/js/views/home.index.js
@@ -1,4 +1,4 @@
/*! Copyright 2016 - Ortus Solutions (Compiled: 15-03-2016) */
/*! Copyright 2016 - Ortus Solutions (Compiled: 18-03-2016) */
define([ "Backbone", "views/widgets/relaxer", "views/widgets/sidebar", "models/RelaxAPI" ], function(Backbone, Relaxer, SidebarWidget, APIModel) {
"use strict";
var View = Backbone.View.extend({
Expand Down
2 changes: 1 addition & 1 deletion modules/relax/includes/js/views/home.openapidocs.js
@@ -1,4 +1,4 @@
/*! Copyright 2016 - Ortus Solutions (Compiled: 15-03-2016) */
/*! Copyright 2016 - Ortus Solutions (Compiled: 18-03-2016) */
define([ "Backbone" ], function(Backbone) {
"use strict";
var View = Backbone.View.extend({
Expand Down
2 changes: 1 addition & 1 deletion modules/relax/includes/js/views/relax.relaxer.js
@@ -1,4 +1,4 @@
/*! Copyright 2016 - Ortus Solutions (Compiled: 15-03-2016) */
/*! Copyright 2016 - Ortus Solutions (Compiled: 18-03-2016) */
define([ "Backbone", "views/widgets/relaxer", "models/RelaxAPI" ], function(Backbone, RelaxerWidget, APIModel) {
"use strict";
var View = Backbone.View.extend({
Expand Down
2 changes: 1 addition & 1 deletion modules/relax/includes/js/views/widgets/relaxer.js
@@ -1,4 +1,4 @@
/*! Copyright 2016 - Ortus Solutions (Compiled: 15-03-2016) */
/*! Copyright 2016 - Ortus Solutions (Compiled: 18-03-2016) */
define([ "Backbone" ], function(Backbone) {
"use strict";
var View = Backbone.View.extend({
Expand Down
4 changes: 1 addition & 3 deletions modules/relax/includes/js/views/widgets/sidebar.js
@@ -1,4 +1,4 @@
/*! Copyright 2016 - Ortus Solutions (Compiled: 15-03-2016) */
/*! Copyright 2016 - Ortus Solutions (Compiled: 18-03-2016) */
define([ "Backbone", "models/RelaxAPI" ], function(Backbone, APIModel) {
"use strict";
var View = Backbone.View.extend({
Expand Down Expand Up @@ -55,8 +55,6 @@ define([ "Backbone", "models/RelaxAPI" ], function(Backbone, APIModel) {
onSelectAPI: function(e) {
var _this = this;
var $select = $(e.currentTarget);
console.log($select.length);
console.log($select.val());
var selectedAPI = $select.val();
_this.ViewModel.set("id", selectedAPI);
_this.View.renderLoaderMessage();
Expand Down
4 changes: 1 addition & 3 deletions modules/relax/layouts/inc/HTMLHead.cfm
Expand Up @@ -24,14 +24,12 @@
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,900,300italic,400italic,600italic,700italic,900italic' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>

<!-- Feature detection -->
<script src="#prc.root#/includes/js/modernizr.js"></script>

<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="#prc.root#/includes/js/html5shiv.js"></script>
<script src="#prc.root#/includes/js/respond.min.js"></script>
<![endif]-->

<cfoutput>
<!--- <cfdump var="#event#" abort> --->
<script type="application/javascript">
Expand Down
43 changes: 24 additions & 19 deletions modules/relax/views/apidoc/_template/method.html
Expand Up @@ -36,25 +36,30 @@ <h4 class="panel-subtitle text-primary">Parameters:</h4>
<hr>
<% } %>

<h4 class="panel-subtitle text-primary">Responses:</h4>
<%
_.each( _.keys(method.responses), function( responseKey ){
if( !isNaN( responseKey ) || responseKey === 'default' ){
%>
<%= responseTemplate(
{
"resourceId": method["x-resourceId"] ,
"path":key,
"key":responseKey,
"response":method.responses[ responseKey ]
}
) %>

<%
}

});
%>
<% if( _.keys( method.responses ).length ) { %>

<h4 class="panel-subtitle text-primary">Responses:</h4>
<%
_.each( _.keys(method.responses), function( responseKey ){
if( !isNaN( responseKey ) || responseKey === 'default' ){
%>
<%= responseTemplate(
{
"resourceId": method["x-resourceId"] ,
"path":key,
"key":responseKey,
"response":method.responses[ responseKey ]
}
) %>

<%
}

});
%>

<% } %>


</div>
</div>
Expand Down

0 comments on commit 5aea603

Please sign in to comment.