Major refactoring, add better debug build flags. Utilize npm run
This commit is contained in:
1 parent
b6bc5af534
commit
69fb368c75
5 files changed
+179
-42
No files matched your search
@@ -7,4 +7,9 @@ http://lint.neo.yt
|
|||||||
### Installation Instructions
|
### Installation Instructions
|
||||||
* `git clone`
|
* `git clone`
|
||||||
* ensure `public_html` is in your vhost document root
|
* ensure `public_html` is in your vhost document root
|
||||||
* run `npm run-script build`
|
* run `npm run build`
|
||||||
|
|
||||||
|
|
||||||
|
### Debugging Instructions
|
||||||
|
* `git clone`
|
||||||
|
* run `npm run build:dev`
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
/**
|
||||||
|
* Created by apanesar on 3/17/17.
|
||||||
|
*/
|
||||||
|
|
||||||
|
window.doTheDebugDo = true;
|
||||||
+15
-6
@@ -19,12 +19,21 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="navbar" class="collapse navbar-collapse">
|
<div id="navbar" class="collapse navbar-collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li id="html_tab" class="active"><a href="#">HTML</a></li>
|
<li id="html_tab" data-name="HTML Linter" class="active"><a href="#">HTML</a></li>
|
||||||
<li id="json_tab"><a href="#">JSON</a></li>
|
<li id="json_tab" data-name="JSON Linter"><a href="#">JSON</a></li>
|
||||||
<li id="xml_tab"><a href="#">XML</a></li>
|
<li id="xml_tab" data-name="XML Linter"><a href="#">XML</a></li>
|
||||||
<li id="js_tab"><a href="#">JavaScript</a></li>
|
<li id="js_tab" data-name="JavaScript Linter"><a href="#">JavaScript</a></li>
|
||||||
<li id="css_tab"><a href="#">CSS</a></li>
|
<li id="css_tab" data-name="CSS Linter"><a href="#">CSS</a></li>
|
||||||
<li id="sql_tab"><a href="#">SQL</a></li>
|
<li id="sql_tab" data-name="SQL Linter"><a href="#">SQL</a></li>
|
||||||
|
<li id="encode_decode_tab" class="dropdown">
|
||||||
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="true">Encode/Decode <span class="caret"></span></a>
|
||||||
|
<ul class="dropdown-menu" role="menu">
|
||||||
|
<li id="urlencode_tab" data-extra-highlight="encode_decode_tab" data-name="URL Encoder"><a href="#">URLEncode</a></li>
|
||||||
|
<li id="urldecode_tab" data-extra-highlight="encode_decode_tab" data-name="URL Decoder"><a href="#">URLDecode</a></li>
|
||||||
|
<li id="base64encode_tab" data-extra-highlight="encode_decode_tab" data-name="Base64 Encoder"><a href="#">Base64Encode</a></li>
|
||||||
|
<li id="base64decode_tab" data-extra-highlight="encode_decode_tab" data-name="Base64 Decoder"><a href="#">Base64Decode</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div><!-- /.nav-collapse -->
|
</div><!-- /.nav-collapse -->
|
||||||
</div><!-- /.container -->
|
</div><!-- /.container -->
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ require('bootstrap');
|
|||||||
// use hasher for application page management
|
// use hasher for application page management
|
||||||
var hasher = require('hasher');
|
var hasher = require('hasher');
|
||||||
hasher.prependHash = '!';
|
hasher.prependHash = '!';
|
||||||
|
hasher.separator = '/';
|
||||||
|
|
||||||
// include/configure highlight.js
|
// include/configure highlight.js
|
||||||
var hljs = require('highlight.js');
|
var hljs = require('highlight.js');
|
||||||
@@ -34,11 +35,32 @@ var beautify_xml = require('xml-beautifier');
|
|||||||
// sql-formatter library
|
// sql-formatter library
|
||||||
var beautify_sql = require('sql-formatter');
|
var beautify_sql = require('sql-formatter');
|
||||||
|
|
||||||
|
// debugging assistance
|
||||||
|
var debug = (window.doTheDebugDo) ? {
|
||||||
|
log: window.console.log.bind(window.console, '%s'),
|
||||||
|
type: window.console.log.bind(window.console, '%s: %s'),
|
||||||
|
error: window.console.error.bind(window.console, 'error: %s'),
|
||||||
|
info: window.console.info.bind(window.console, 'info: %s'),
|
||||||
|
warn: window.console.warn.bind(window.console, 'warn: %s')
|
||||||
|
} : {
|
||||||
|
log: function() {},
|
||||||
|
type: function() {},
|
||||||
|
error: function() {},
|
||||||
|
warn: function() {},
|
||||||
|
info: function() {}
|
||||||
|
};
|
||||||
|
|
||||||
$('window').ready(function () {
|
$('window').ready(function () {
|
||||||
|
|
||||||
// JSON linting!
|
// main I/O
|
||||||
var jsonLint = function (json) {
|
var input = $('#input');
|
||||||
|
var output = $('#output');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON linting!
|
||||||
|
* @param json
|
||||||
|
*/
|
||||||
|
var jsonLint = function(json) {
|
||||||
if (typeof json !== 'string') {
|
if (typeof json !== 'string') {
|
||||||
return JSON.stringify(json, undefined, 4);
|
return JSON.stringify(json, undefined, 4);
|
||||||
} else {
|
} else {
|
||||||
@@ -46,8 +68,20 @@ $('window').ready(function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// hasher page changer function
|
/**
|
||||||
var changeType = function(type) {
|
* hasher page changer function
|
||||||
|
* @param type
|
||||||
|
* @param setHash
|
||||||
|
*/
|
||||||
|
var changeType = function(type, setHash)
|
||||||
|
{
|
||||||
|
setHash = typeof setHash === 'undefined' ? true : setHash;
|
||||||
|
|
||||||
|
var hash = hasher.getHashAsArray();
|
||||||
|
|
||||||
|
var code = hash[1];
|
||||||
|
code = typeof code === 'undefined' ? '' : code;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'html':
|
case 'html':
|
||||||
case 'xml':
|
case 'xml':
|
||||||
@@ -55,53 +89,84 @@ $('window').ready(function () {
|
|||||||
case 'js':
|
case 'js':
|
||||||
case 'css':
|
case 'css':
|
||||||
case 'sql':
|
case 'sql':
|
||||||
$('#navbar').find('>ul>li.active').removeClass('active');
|
case 'urlencode':
|
||||||
$('#'+type+'_tab').addClass('active');
|
case 'urldecode':
|
||||||
|
case 'base64encode':
|
||||||
|
case 'base64decode':
|
||||||
|
debug.type('changeType()', type);
|
||||||
|
|
||||||
$('#header').text(type.toUpperCase() + ' Linter');
|
$('#navbar').find('.active').removeClass('active');
|
||||||
|
var tab = $('#'+type+'_tab');
|
||||||
|
tab.addClass('active');
|
||||||
|
|
||||||
hasher.setHash(type);
|
if (tab.data('extra-highlight') !== '') {
|
||||||
|
$('#'+tab.data('extra-highlight')).addClass('active');
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#header').text(tab.data('name'));
|
||||||
|
|
||||||
|
if (setHash) {
|
||||||
|
debug.type('changeType()', 'Calling hasher.sethash with {'+ type +'} : {'+ code +'}');
|
||||||
|
hasher.setHash(type, code);
|
||||||
|
} else {
|
||||||
|
debug.type('changeType()', 'Not calling hasher.sethash');
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
hasher.setHash('html');
|
debug.type('changeType()', 'Default Case: Calling hasher.sethash with {html} : {'+ code +'}');
|
||||||
|
hasher.setHash('html', code);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// hasher setup (now that the function exists)
|
/**
|
||||||
hasher.changed.add(changeType);
|
* Beautify! Call all our syntax beautifiers
|
||||||
hasher.initialized.add(changeType);
|
* @param type
|
||||||
hasher.init();
|
* @param code
|
||||||
|
*/
|
||||||
var beautify = function (type) {
|
var beautify = function (type, code) {
|
||||||
var stringIn = input.val();
|
code = typeof code === 'undefined' ? '' : code;
|
||||||
var stringOut = '';
|
var stringOut = '';
|
||||||
try {
|
try {
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case 'html':
|
case 'html':
|
||||||
htmlLint(stringIn).then(function (lintOutput) {
|
htmlLint(code).then(function (lintOutput) {
|
||||||
console.log(lintOutput);
|
debug.log(lintOutput);
|
||||||
}, function(e) {
|
}, function(e) {
|
||||||
console.log(e);
|
debug.log(e);
|
||||||
}).catch(function (e) {
|
}).catch(function (e) {
|
||||||
console.log(e);
|
debug.log(e);
|
||||||
});
|
});
|
||||||
stringOut = hljs.highlightAuto(beautify_html(stringIn)).value;
|
stringOut = hljs.highlightAuto(beautify_html(code)).value;
|
||||||
break;
|
break;
|
||||||
case 'xml':
|
case 'xml':
|
||||||
stringOut = hljs.highlightAuto(beautify_xml(stringIn)).value;
|
stringOut = hljs.highlightAuto(beautify_xml(code)).value;
|
||||||
break;
|
break;
|
||||||
case 'json':
|
case 'json':
|
||||||
stringOut = hljs.highlightAuto(jsonLint(stringIn)).value;
|
stringOut = hljs.highlightAuto(jsonLint(code)).value;
|
||||||
break;
|
break;
|
||||||
case 'js':
|
case 'js':
|
||||||
stringOut = hljs.highlightAuto(beautify_js(stringIn)).value;
|
stringOut = hljs.highlightAuto(beautify_js(code)).value;
|
||||||
break;
|
break;
|
||||||
case 'css':
|
case 'css':
|
||||||
stringOut = hljs.highlightAuto(beautify_css(stringIn)).value;
|
stringOut = hljs.highlightAuto(beautify_css(code)).value;
|
||||||
break;
|
break;
|
||||||
case 'sql':
|
case 'sql':
|
||||||
stringOut = hljs.highlightAuto(beautify_sql.format(stringIn)).value;
|
stringOut = hljs.highlightAuto(beautify_sql.format(code)).value;
|
||||||
|
break;
|
||||||
|
case 'urlencode':
|
||||||
|
stringOut = hljs.highlightAuto(encodeURIComponent(code)).value;
|
||||||
|
break;
|
||||||
|
case 'urldecode':
|
||||||
|
stringOut = hljs.highlightAuto(decodeURIComponent(code)).value;
|
||||||
|
break;
|
||||||
|
case 'base64encode':
|
||||||
|
stringOut = hljs.highlightAuto(btoa(code)).value;
|
||||||
|
break;
|
||||||
|
case 'base64decode':
|
||||||
|
stringOut = hljs.highlightAuto(atob(code)).value;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
stringOut = 'Error: Unable to parse ' + type + '<br>' + e;
|
stringOut = 'Error: Unable to parse ' + type + '<br>' + e;
|
||||||
@@ -109,20 +174,69 @@ $('window').ready(function () {
|
|||||||
output.html(stringOut);
|
output.html(stringOut);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// hasher setup (now that the function exists)
|
||||||
|
hasher.changed.add(function(newVal, oldVal) {
|
||||||
|
debug.type('hasher.changed()', 'Old Val: ' + oldVal + ' New Val: ' + newVal);
|
||||||
|
|
||||||
|
var doChangeType = true;
|
||||||
|
|
||||||
|
if (oldVal.split(hasher.separator, 1)[0] === newVal.split(hasher.separator, 1)[0]) {
|
||||||
|
doChangeType = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var hash = hasher.getHashAsArray();
|
||||||
|
var type = hash[0];
|
||||||
|
var code = hash[1];
|
||||||
|
|
||||||
|
changeType(type, doChangeType);
|
||||||
|
|
||||||
|
code = typeof code === 'undefined' ? '' : code;
|
||||||
|
code = decodeURIComponent(code);
|
||||||
|
|
||||||
|
debug.type('hasher.changed()', 'Set input value to {'+ code +'}');
|
||||||
|
input.val(code);
|
||||||
|
});
|
||||||
|
hasher.initialized.add(function() {
|
||||||
|
debug.type('hasher.initialized()', 'Start');
|
||||||
|
|
||||||
|
var hash = hasher.getHashAsArray();
|
||||||
|
var type = hash[0];
|
||||||
|
var code = hash[1];
|
||||||
|
|
||||||
|
changeType(type, false);
|
||||||
|
|
||||||
|
code = typeof code === 'undefined' ? '' : code;
|
||||||
|
code = decodeURIComponent(code);
|
||||||
|
|
||||||
|
input.val(code);
|
||||||
|
|
||||||
|
debug.type('hasher.initialized()', 'Calling beautify with {'+ type +'} : {'+ code +'}');
|
||||||
|
beautify(type, code)
|
||||||
|
});
|
||||||
|
hasher.init();
|
||||||
|
|
||||||
// hook into the navbar tabs and use hasher for them
|
// hook into the navbar tabs and use hasher for them
|
||||||
$('#navbar').find('>ul>li').click(function(e) {
|
var navbar = $('#navbar');
|
||||||
|
navbar.find('>ul>li:not(.dropdown)').click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
changeType(this.id.replace('_tab', ''));
|
||||||
|
});
|
||||||
|
navbar.find('.dropdown>ul>li').click(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
changeType(this.id.replace('_tab', ''));
|
changeType(this.id.replace('_tab', ''));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// main I/O
|
|
||||||
var input = $('#input');
|
|
||||||
var output = $('#output');
|
|
||||||
|
|
||||||
// function main ()
|
// function main ()
|
||||||
input.change(function() {
|
input.change(function(e) {
|
||||||
beautify(hasher.getHash())
|
var hash = hasher.getHashAsArray();
|
||||||
|
|
||||||
|
var type = hash[0];
|
||||||
|
var code = input.val();
|
||||||
|
code = typeof code === 'undefined' ? '' : code;
|
||||||
|
|
||||||
|
debug.type('input.change', 'Calling beautify with {'+ type +'} : {'+ code +'}');
|
||||||
|
|
||||||
|
beautify(type, code);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
+5
-1
@@ -6,7 +6,10 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"prebuild": "npm install",
|
"prebuild": "npm install",
|
||||||
"build": "browserify -g uglifyify -o app.js index.js",
|
"build": "browserify -g uglifyify -o app.js index.js",
|
||||||
"postbuild": "mkdir -p public_html/ && cp app.js public_html/ && cp index.html public_html/"
|
"postbuild": "mkdir -p public_html/ && cp app.js public_html/ && cp index.html public_html/",
|
||||||
|
"prebuild:dev": "npm run prebuild",
|
||||||
|
"build:dev": "browserify -o app.js debug.js index.js",
|
||||||
|
"postbuild:dev": "npm run postbuild"
|
||||||
},
|
},
|
||||||
"author": "Amrit Panesar <neo@neo.yt>",
|
"author": "Amrit Panesar <neo@neo.yt>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -18,6 +21,7 @@
|
|||||||
"browserify-css": "^0.10.0",
|
"browserify-css": "^0.10.0",
|
||||||
"browserify-shim": "^3.8.13",
|
"browserify-shim": "^3.8.13",
|
||||||
"bulkify": "^1.4.2",
|
"bulkify": "^1.4.2",
|
||||||
|
"crypto-js": "^3.1.9-1",
|
||||||
"hasher": "^1.2.0",
|
"hasher": "^1.2.0",
|
||||||
"highlight.js": "^9.9.0",
|
"highlight.js": "^9.9.0",
|
||||||
"html": "^1.0.0",
|
"html": "^1.0.0",
|
||||||
|
|||||||
Reference in new issue
Block a user