From 9a7041806271b2430aaedbfa8160f3f531b29012 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 6 Jul 2013 18:37:52 +0100 Subject: [PATCH 1/6] Updated web.js --- web.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.js b/web.js index 0b54a06391..85b78bea24 100644 --- a/web.js +++ b/web.js @@ -3,7 +3,7 @@ var express = require('express'); var app = express.createServer(express.logger()); app.get('/', function(request, response) { - response.send('Hello World!'); + response.send('Hello World2!'); }); var port = process.env.PORT || 5000; From 8595cdcaffadda5ac5b5834ecbe984690e6e326b Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 6 Jul 2013 18:40:17 +0100 Subject: [PATCH 2/6] Added index.html --- index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 0000000000..0361081776 --- /dev/null +++ b/index.html @@ -0,0 +1 @@ +Hello World from index.html From 3bf3f9c1895b7d9442584c6e7b50a0c110b63026 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 6 Jul 2013 18:46:59 +0100 Subject: [PATCH 3/6] Modified web.js --- web.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web.js b/web.js index 85b78bea24..acf5278948 100644 --- a/web.js +++ b/web.js @@ -1,9 +1,10 @@ var express = require('express'); +var fs = require('fs'); var app = express.createServer(express.logger()); app.get('/', function(request, response) { - response.send('Hello World2!'); + response.send(fs.readFileSync('./index.html').toString()); }); var port = process.env.PORT || 5000; From c852d62a35f454202700875a2d029cf5a10c49d0 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 6 Jul 2013 18:55:54 +0100 Subject: [PATCH 4/6] Changed index.html --- index.html | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 0361081776..fbdf2f63b7 100644 --- a/index.html +++ b/index.html @@ -1 +1,102 @@ -Hello World from index.html + + + + + My First Bitstarter + + + + +
+ +
+
+

Bitstarter Title

+
+
+
+
+

This is my first bitstarter project.

+
+
+
+
+ Video +
+
+
+ Thermometer +
+
+ Order +
+ +
+
+
+
+ Marketing Section 1 +
+
+
+
+ Marketing Section 2 +
+
+
+
+ FAQ +
+
+ +
+ + \ No newline at end of file From 89ae6473ff0fa184828874a43470d9c18e02bb45 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 6 Jul 2013 19:03:07 +0100 Subject: [PATCH 5/6] Initial version of grader and checks --- checks.json | 2 ++ grader.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 checks.json create mode 100755 grader.js diff --git a/checks.json b/checks.json new file mode 100644 index 0000000000..710dcfc1e8 --- /dev/null +++ b/checks.json @@ -0,0 +1,2 @@ +["h1", + ".navigation"] diff --git a/grader.js b/grader.js new file mode 100755 index 0000000000..8d51e4b203 --- /dev/null +++ b/grader.js @@ -0,0 +1,74 @@ +#!/usr/bin/env node +/* +Automatically grade files for the presence of specified HTML tags/attributes. +Uses commander.js and cheerio. Teaches command line application development +and basic DOM parsing. + +References: + + + cheerio + - https://github.com/MatthewMueller/cheerio + - http://encosia.com/cheerio-faster-windows-friendly-alternative-jsdom/ + - http://maxogden.com/scraping-with-node.html + + + commander.js + - https://github.com/visionmedia/commander.js + - http://tjholowaychuk.com/post/9103188408/commander-js-nodejs-command-line-interfaces-made-easy + + + JSON + - http://en.wikipedia.org/wiki/JSON + - https://developer.mozilla.org/en-US/docs/JSON + - https://developer.mozilla.org/en-US/docs/JSON#JSON_in_Firefox_2 +*/ + +var fs = require('fs'); +var program = require('commander'); +var cheerio = require('cheerio'); +var HTMLFILE_DEFAULT = "index.html"; +var CHECKSFILE_DEFAULT = "checks.json"; + +var assertFileExists = function(infile) { + var instr = infile.toString(); + if(!fs.existsSync(instr)) { + console.log("%s does not exist. Exiting.", instr); + process.exit(1); // http://nodejs.org/api/process.html#process_process_exit_code + } + return instr; +}; + +var cheerioHtmlFile = function(htmlfile) { + return cheerio.load(fs.readFileSync(htmlfile)); +}; + +var loadChecks = function(checksfile) { + return JSON.parse(fs.readFileSync(checksfile)); +}; + +var checkHtmlFile = function(htmlfile, checksfile) { + $ = cheerioHtmlFile(htmlfile); + var checks = loadChecks(checksfile).sort(); + var out = {}; + for(var ii in checks) { + var present = $(checks[ii]).length > 0; + out[checks[ii]] = present; + } + return out; +}; + +var clone = function(fn) { + // Workaround for commander.js issue. + // http://stackoverflow.com/a/6772648 + return fn.bind({}); +}; + +if(require.main == module) { + program + .option('-c, --checks ', 'Path to checks.json', clone(assertFileExists), CHECKSFILE_DEFAULT) + .option('-f, --file ', 'Path to index.html', clone(assertFileExists), HTMLFILE_DEFAULT) + .parse(process.argv); + var checkJson = checkHtmlFile(program.file, program.checks); + var outJson = JSON.stringify(checkJson, null, 4); + console.log(outJson); +} else { + exports.checkHtmlFile = checkHtmlFile; +} From 7570b754894b87a1c4725024307a716739b302ef Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 6 Jul 2013 19:06:39 +0100 Subject: [PATCH 6/6] last version of checks.json --- checks.json | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/checks.json b/checks.json index 710dcfc1e8..b87591ef7d 100644 --- a/checks.json +++ b/checks.json @@ -1,2 +1,17 @@ ["h1", - ".navigation"] + ".navigation", + ".logo", + ".blank", + ".about", + ".heading", + ".subheading", + ".pitch", + ".video", + ".thermometer", + ".order", + ".social", + ".section1", + ".section2", + ".faq", + ".footer"] +