Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fuller grader, with URL checking.

  • Loading branch information...
commit 0ea1b0ffdef7ec45416c11a49467ab768339ba48 1 parent 35bd328
@jest authored
Showing with 46 additions and 11 deletions.
  1. +18 −2 checks.json
  2. +28 −9 grader.js
View
20 checks.json
@@ -1,3 +1,19 @@
-["h1",
- ".navigation"]
+[
+ "h1",
+ ".navigation",
+ ".logo",
+ ".blank",
+ ".about",
+ ".heading",
+ ".subheading",
+ ".pitch",
+ ".video",
+ ".thermometer",
+ ".order",
+ ".social",
+ ".section1",
+ ".section2",
+ ".faq",
+ ".footer"
+]
View
37 grader.js
@@ -22,6 +22,7 @@ References:
*/
var fs = require('fs');
+var rest = require('restler');
var program = require('commander');
var cheerio = require('cheerio');
var HTMLFILE_DEFAULT = "index.html";
@@ -36,16 +37,12 @@ var assertFileExists = function(infile) {
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 checkString = function(str, checksfile) {
+ $ = cheerio.load(str)
var checks = loadChecks(checksfile).sort();
var out = {};
for(var ii in checks) {
@@ -55,6 +52,23 @@ var checkHtmlFile = function(htmlfile, checksfile) {
return out;
};
+var checkHtmlFile = function(htmlfile, checksfile) {
+ return checkString(fs.readFileSync(htmlfile), checksfile);
+};
+var checkUrl = function(url, checksfile) {
+ var resu = {'a':1};
+ rest.get(url).on('complete', function(result, response) {
+ if (result instanceof Error) {
+ console.error('Error: ' + util.format(response.message));
+ } else {
+ resu = checkString(result, checksfile);
+ var outJson = JSON.stringify(resu, null, 4);
+ console.log(outJson);
+ }
+ });
+};
+
+
var clone = function(fn) {
// Workaround for commander.js issue.
// http://stackoverflow.com/a/6772648
@@ -65,10 +79,15 @@ if(require.main == module) {
program
.option('-c, --checks <check_file>', 'Path to checks.json', clone(assertFileExists), CHECKSFILE_DEFAULT)
.option('-f, --file <html_file>', 'Path to index.html', clone(assertFileExists), HTMLFILE_DEFAULT)
+ .option('-u, --url <url>', 'URL to checked resource', null, null)
.parse(process.argv);
- var checkJson = checkHtmlFile(program.file, program.checks);
- var outJson = JSON.stringify(checkJson, null, 4);
- console.log(outJson);
+ if (program.url === null) {
+ var checkJson = checkHtmlFile(program.file, program.checks);
+ var outJson = JSON.stringify(checkJson, null, 4);
+ console.log(outJson);
+ } else {
+ checkUrl(program.url, program.checks);
+ }
} else {
exports.checkHtmlFile = checkHtmlFile;
}
Please sign in to comment.
Something went wrong with that request. Please try again.