diff --git a/README.md b/README.md index d07bbb1..d9d194f 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,9 @@ http://lint.neo.yt ### Installation Instructions * `git clone` * 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` diff --git a/debug.js b/debug.js new file mode 100644 index 0000000..e1d6f41 --- /dev/null +++ b/debug.js @@ -0,0 +1,5 @@ +/** + * Created by apanesar on 3/17/17. + */ + +window.doTheDebugDo = true; \ No newline at end of file diff --git a/index.html b/index.html index d0c4ca6..0c8fdcc 100644 --- a/index.html +++ b/index.html @@ -19,12 +19,21 @@
diff --git a/index.js b/index.js index 3472ce5..6694e35 100644 --- a/index.js +++ b/index.js @@ -13,6 +13,7 @@ require('bootstrap'); // use hasher for application page management var hasher = require('hasher'); hasher.prependHash = '!'; +hasher.separator = '/'; // include/configure highlight.js var hljs = require('highlight.js'); @@ -34,11 +35,32 @@ var beautify_xml = require('xml-beautifier'); // sql-formatter library 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 () { - // JSON linting! - var jsonLint = function (json) { + // main I/O + var input = $('#input'); + var output = $('#output'); + + /** + * JSON linting! + * @param json + */ + var jsonLint = function(json) { if (typeof json !== 'string') { return JSON.stringify(json, undefined, 4); } 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) { case 'html': case 'xml': @@ -55,53 +89,84 @@ $('window').ready(function () { case 'js': case 'css': case 'sql': - $('#navbar').find('>ul>li.active').removeClass('active'); - $('#'+type+'_tab').addClass('active'); + case 'urlencode': + 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; 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); - hasher.initialized.add(changeType); - hasher.init(); - - var beautify = function (type) { - var stringIn = input.val(); + /** + * Beautify! Call all our syntax beautifiers + * @param type + * @param code + */ + var beautify = function (type, code) { + code = typeof code === 'undefined' ? '' : code; var stringOut = ''; try { switch(type) { case 'html': - htmlLint(stringIn).then(function (lintOutput) { - console.log(lintOutput); + htmlLint(code).then(function (lintOutput) { + debug.log(lintOutput); }, function(e) { - console.log(e); + debug.log(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; case 'xml': - stringOut = hljs.highlightAuto(beautify_xml(stringIn)).value; + stringOut = hljs.highlightAuto(beautify_xml(code)).value; break; case 'json': - stringOut = hljs.highlightAuto(jsonLint(stringIn)).value; + stringOut = hljs.highlightAuto(jsonLint(code)).value; break; case 'js': - stringOut = hljs.highlightAuto(beautify_js(stringIn)).value; + stringOut = hljs.highlightAuto(beautify_js(code)).value; break; case 'css': - stringOut = hljs.highlightAuto(beautify_css(stringIn)).value; + stringOut = hljs.highlightAuto(beautify_css(code)).value; break; 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) { stringOut = 'Error: Unable to parse ' + type + '