From 5b73ee74fe5c18a1ef3cf6a46ca0177642deaae3 Mon Sep 17 00:00:00 2001 From: Amrit Panesar Date: Tue, 7 Mar 2017 19:46:56 -0800 Subject: [PATCH] Initial Commit! Working Code! --- .gitignore | 5 ++ README.md | 8 +++ app.css | 23 +++++++++ index.html | 52 +++++++++++++++++++ index.js | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 43 ++++++++++++++++ 6 files changed, 268 insertions(+) create mode 100644 app.css create mode 100644 index.html create mode 100644 index.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index a8f0296..5baeacd 100644 --- a/.gitignore +++ b/.gitignore @@ -182,3 +182,8 @@ xcuserdata/ *.moved-aside *.xccheckout *.xcscmblueprint + + +app.js + +public_html diff --git a/README.md b/README.md index 46394ce..d07bbb1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # lint-neo-yt Linter! + +### Live Demo +http://lint.neo.yt + +### Installation Instructions +* `git clone` +* ensure `public_html` is in your vhost document root +* run `npm run-script build` diff --git a/app.css b/app.css new file mode 100644 index 0000000..e7d4c1c --- /dev/null +++ b/app.css @@ -0,0 +1,23 @@ +/** +CSS Boilerplate +*/ + +@import url('./node_modules/bootstrap/dist/css/bootstrap.min.css'); +@import url('./node_modules/bootswatch/darkly/bootstrap.min.css'); +@import url('./node_modules/highlight.js/styles/default.css'); +@import url('./node_modules/highlight.js/styles/monokai-sublime.css'); + +pre { + outline: 1px solid #767676; + padding: 0; + margin: 0; +} + +body { + padding-top: 50px; +} + +textarea#input, code#output { + width: 100%; + height: 25em; +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..2a09d15 --- /dev/null +++ b/index.html @@ -0,0 +1,52 @@ + + + + + Lint! + + + + + +
+
+
+

HTML Lint

+
+
+

+

+ +
+
+
+
+
+

+
+
+ +
+ + + + diff --git a/index.js b/index.js new file mode 100644 index 0000000..5c2d813 --- /dev/null +++ b/index.js @@ -0,0 +1,137 @@ +/** + * Created by neo on 3/6/17. + * @function require + */ + +// can't get browserify-shim to work right +// let's just make it work here +window.$ = window.jQuery = require('jquery'); + +// include bootstrap css and javascript +require('./app.css'); +require('bootstrap'); + + +$('window').ready(function () { + // use hasher for application page management + var hasher = require('hasher'); + + // include highlight.js for display purposes + var hljs = require('highlight.js'); + hljs.configure({ + tabReplace: ' ' + }); + + // use HTML Lint (will display later) + var htmlLint = require('htmllint'); + + // JSON linting! + var jsonLint = function (json) { + if (typeof json != 'string') { + return JSON.stringify(json, undefined, 4); + } else { + return jsonLint(JSON.parse(json)); + } + }; + + // (x|ht)ml beautifying! + // function stolen from https://gist.github.com/sente/1083506 + var xmlBeautify = function(xml) { + var formatted = ''; + var reg = /(>)(<)(\/*)/g; + var pad = 0; + + xml.replace("\t", ' '); + xml = xml.replace(reg, '$1\r\n$2$3'); + + $.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; + }; + + // hasher page changer function + var changeType = function(type) { + if (type == '') { + hasher.setHash('html'); + } + switch (type) { + case "html": + case "xml": + case "json": + $("#navbar").find(">ul>li.active").removeClass("active"); + $("#"+type+"_tab").addClass('active'); + + $("#header").text(type.toUpperCase() + ' Linter'); + + hasher.setHash(type); + break; + } + }; + + // hasher setup (now that the functions exist) + hasher.prependHash = "!"; + hasher.changed.add(changeType); + hasher.initialized.add(changeType); + hasher.init(); + + // hook into the navbar tabs and use hasher for them + $("#navbar").find(">ul>li").click(function(e) { + e.preventDefault(); + changeType(this.id.replace('_tab', '')); + }); + + + // main I/O + var input = $('#input'); + var output = $('#output'); + + // function main () + input.change(function() { + switch(hasher.getHash()) { + case "html": + case "xml": + try { + output.html(hljs.highlightAuto(xmlBeautify(input.val())).value); + } catch (e) { + output.html("Error: Unable to parse " + hasher.getHash() + "
" + e); + } + htmlLint(input.val()).then(function (out) { + console.log(out); + }, function(error) { + console.log(error); + }).catch(function (error) { + console.log(error); + }); + break; + case "json": + try { + output.html(hljs.highlightAuto(jsonLint(input.val())).value); + } catch (e) { + output.html("Error: Unable to parse JSON
" + e); + } + break; + } + }); + +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..2151fe8 --- /dev/null +++ b/package.json @@ -0,0 +1,43 @@ +{ + "name": "lint-neo-yt", + "version": "1.0.0", + "description": "Neo's Linter", + "main": "js/app.js", + "scripts": { + "prebuild": "npm install", + "build": "browserify -g uglifyify -o app.js index.js", + "postbuild": "mkdir -p public_html/ && cp app.js public_html/ && cp index.html public_html/" + }, + "author": "Amrit Panesar ", + "license": "MIT", + "repository": "https://github.com/Neo-Desktop/lint-neo-yt", + "devDependencies": { + "bootstrap": "^3.3.7", + "bootswatch": "^3.3.7", + "browserify": "^14.1.0", + "browserify-css": "^0.10.0", + "browserify-shim": "^3.8.13", + "bulkify": "^1.4.2", + "hasher": "^1.2.0", + "highlight.js": "^9.9.0", + "htmllint": "^0.6.0", + "jquery": "^3.1.1", + "uglifyify": "^3.0.4" + }, + "browserify": { + "transform": [ + "browserify-css", + "browserify-shim" + ] + }, + "browserify-css": { + "autoInject": true, + "minify": true, + "rootDir": "./", + "autoInjectOptions": { + "verbose": true, + "insertAt": "bottom" + } + }, + "browserify-shim": {} +}