From d54a1afc1de9e4d3f9a6301ea9e2e15feb57dd39 Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Mon, 13 Apr 2015 22:04:04 -0400 Subject: [PATCH] Changing `` parsing to separate `keys` & `items` --- doc/global.html | 2 +- doc/index.html | 2 +- doc/module-tenso.html | 4 ++-- doc/modules.list.html | 2 +- lib/tenso.es6.js | 6 +++--- lib/tenso.js | 6 +++--- package.json | 2 +- template.html | 22 +++++++++++++--------- 8 files changed, 25 insertions(+), 21 deletions(-) diff --git a/doc/global.html b/doc/global.html index e84c9be3..4a0c39cf 100644 --- a/doc/global.html +++ b/doc/global.html @@ -1826,7 +1826,7 @@
Returns:
Documentation generated by JSDoc 3.2.2 - on 2015-04-13T21:34:13-04:00 using the DocStrap template. diff --git a/doc/index.html b/doc/index.html index a020cc44..ecf1ba43 100644 --- a/doc/index.html +++ b/doc/index.html @@ -390,7 +390,7 @@

License

Documentation generated by JSDoc 3.2.2 - on 2015-04-13T21:34:13-04:00 using the DocStrap template. diff --git a/doc/module-tenso.html b/doc/module-tenso.html index f15f67a6..95e5b8f1 100644 --- a/doc/module-tenso.html +++ b/doc/module-tenso.html @@ -125,7 +125,7 @@

Version:
    -
  • 1.4.5
  • +
  • 1.4.6
@@ -344,7 +344,7 @@

Type:
Documentation generated by JSDoc 3.2.2 - on 2015-04-13T21:34:13-04:00 using the DocStrap template. diff --git a/doc/modules.list.html b/doc/modules.list.html index 59fc49f6..efcd3bd0 100644 --- a/doc/modules.list.html +++ b/doc/modules.list.html @@ -188,7 +188,7 @@

Documentation generated by JSDoc 3.2.2 - on 2015-04-13T21:34:13-04:00 using the DocStrap template. diff --git a/lib/tenso.es6.js b/lib/tenso.es6.js index d12fb8f9..e4248718 100644 --- a/lib/tenso.es6.js +++ b/lib/tenso.es6.js @@ -6,10 +6,10 @@ * @license BSD-3 * @link http://avoidwork.github.io/tenso * @module tenso - * @version 1.4.5 + * @version 1.4.6 */ const CONFIG = require( __dirname + "/../config.json" ); -const VERSION = "1.4.5"; +const VERSION = "1.4.6"; const SERVER = "tenso/" + VERSION; let keigai = require( "keigai" ), @@ -1142,7 +1142,7 @@ let renderers = { } ).join( "\n" ) ) .replace( "{{body}}", JSON.stringify( arg, null, 2 ) ) .replace( "{{year}}", new Date().getFullYear() ) - .replace( "{{version}}", "1.4.5" ) + .replace( "{{version}}", "1.4.6" ) .replace( "{{allow}}", headers[ "allow" ] ) .replace( "{{methods}}", string.explode( headers[ "allow" ].replace( "GET, HEAD, OPTIONS", "" ) ).filter( function ( i ) { return i !== ""; diff --git a/lib/tenso.js b/lib/tenso.js index 6da8fb87..5239dd12 100644 --- a/lib/tenso.js +++ b/lib/tenso.js @@ -12,10 +12,10 @@ var _classCallCheck = function (instance, Constructor) { if (!(instance instance * @license BSD-3 * @link http://avoidwork.github.io/tenso * @module tenso - * @version 1.4.5 + * @version 1.4.6 */ var CONFIG = require(__dirname + "/../config.json"); -var VERSION = "1.4.5"; +var VERSION = "1.4.6"; var SERVER = "tenso/" + VERSION; var keigai = require("keigai"), @@ -1193,7 +1193,7 @@ var renderers = { return "" + i + "" + sanitize(headers[i]) + ""; }).join("\n")).replace("{{formats}}", req.server.config.renderers.map(function (i) { return ""; - }).join("\n")).replace("{{body}}", JSON.stringify(arg, null, 2)).replace("{{year}}", new Date().getFullYear()).replace("{{version}}", "1.4.5").replace("{{allow}}", headers.allow).replace("{{methods}}", string.explode(headers.allow.replace("GET, HEAD, OPTIONS", "")).filter(function (i) { + }).join("\n")).replace("{{body}}", JSON.stringify(arg, null, 2)).replace("{{year}}", new Date().getFullYear()).replace("{{version}}", "1.4.6").replace("{{allow}}", headers.allow).replace("{{methods}}", string.explode(headers.allow.replace("GET, HEAD, OPTIONS", "")).filter(function (i) { return i !== ""; }).map(function (i) { return ""; diff --git a/package.json b/package.json index b7694d32..12b08935 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tenso", "description": "Tensō is a REST API facade for node.js, designed to simplify the implementation of APIs.", - "version": "1.4.5", + "version": "1.4.6", "homepage": "http://avoidwork.github.io/tenso", "author": { "name": "Jason Mulligan", diff --git a/template.html b/template.html index 4076f807..08b0a566 100644 --- a/template.html +++ b/template.html @@ -287,7 +287,7 @@ width: 1.1em; } - .item { + .key { font-weight: bold; } @@ -495,6 +495,7 @@

Result

regex = util.regex, render = util.render, request = util.request, + string = util.string, code = $( "code" )[ 0 ], formats = $( "select" )[ 0 ], observable = util.observer(), @@ -504,19 +505,22 @@

Result

// Stage 1 of prettifying a function prepare ( html ) { - var matches, replaces; + var keys, matches, replaces; // Preparing to change
 into Elements
-			matches = array.unique( html.match( /([^\s*]+)/g ).filter( function ( i ) {
-				return !/(\{|\[|\]|\})/.test( i ) && /\"/.test( i );
-			} ) );
-
+			keys = html.match(/\".*":/g);
+			matches = keys.concat( html.match( /:\s(\".*\"|\d{3,3}|null)/g ) );
 			replaces = matches.map( function ( i ) {
-				return i.replace( /(\".*\")/, "$1" );
+				if ( keys.indexOf( i ) > -1 ) {
+					return i.replace( /(\".*\")/, "$1" );
+				}
+				else {
+					return i.replace( /(\".*\"|\d{3,3}|null)/, "$1" );
+				}
 			} );
 
 			array.each( matches, function ( i, idx ) {
-				html = html.replace( new RegExp( i, "g" ), replaces[ idx ] )
+				html = html.replace( new RegExp( string.escape( i ), "g" ), replaces[ idx ] )
 			} );
 
 			return html;
@@ -532,7 +536,7 @@ 

Result

// Changing URIs into anchors array.each( $( ".item" ), function ( i ) { var html = i.innerHTML, - val = html.replace( /(^\"|\"$)/g, "" ); + val = html.replace( /(^\"|\"$)/g, "" ); if ( val.indexOf( "://" ) > -1 ) { html = html.replace( val, "" + val + "" );