Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added quizCount to the return values from parse
- Loading branch information
Jon Sullivan
committed
Feb 12, 2014
1 parent
00d4fd9
commit 4bf4474
Showing
5 changed files
with
49 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,34 @@ | ||
"use strict"; | ||
|
||
var xpath = require('xpath'); | ||
var dom = require('xmldom').DOMParser; | ||
var fs = require('fs'); | ||
var _ = require('lodash'); | ||
var async = require('async'); | ||
|
||
module.exports = function(manifestJSON, cb) { | ||
async.series({ | ||
scoHtmlHref: getScoHtmlHref | ||
}, function (err, result) { | ||
if(err) cb(err); | ||
cb(null, result); | ||
}); | ||
module.exports = function(params, cb) { | ||
var params = params || {}; | ||
if (!params.pathToExtractZip) return cb('Requires a path in which to find the SCO manifest XML'); | ||
|
||
fs.readFile(params.pathToExtractZip + '/imsmanifest.xml', 'ascii', function(err, data) { | ||
if (err) return cb(err); | ||
|
||
function getScoHtmlHref(cb) { | ||
var scoResource = getScoResource(manifestJSON); | ||
if(!scoResource) return cb(null); | ||
var href = scoResource.href; | ||
if(!href || href == '') return cb(null); | ||
cb(null, href); | ||
} | ||
var doc = new dom().parseFromString(data.substring(2, data.length)); | ||
|
||
function getScoResource(json) { | ||
if(!json) return null; | ||
var manifest = json.manifest; | ||
if(!manifest) return null; | ||
var resources = manifest.resources; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
function findIndexFile() { | ||
var nodes = xpath.select("(//resource[@href])[1]", doc); | ||
var attr = nodes[0].attributes; | ||
var filename = attr[_.findKey(attr, { 'name': 'href' })].value; | ||
return filename; | ||
} | ||
|
||
var scoResource = null; | ||
_.each(resources, function(resourcesItem) { | ||
if(!resourcesItem) return; | ||
_.each(resourcesItem, function (resourceItem) { | ||
if(!resourceItem) return; | ||
_.each(resourceItem, function (resourceInfoItem) { | ||
if(!resourceInfoItem) return; | ||
var resource = resourceInfoItem.$; | ||
if(!resource) return; | ||
var type = resource.type ? resource.type.toLowerCase() : null; | ||
var scormType = resource['adlcp:scormtype'] ? resource['adlcp:scormtype'].toLowerCase() : null; | ||
if(type != 'webcontent' || scormType != 'sco') return; | ||
scoResource = resource; | ||
}); | ||
}); | ||
function findQuizCount() { | ||
var nodes = xpath.select("//*[name()='adlcp:masteryscore']", doc); | ||
return nodes.length; | ||
} | ||
|
||
return cb(null, { | ||
scoHtmlHref: findIndexFile(), | ||
quizCount: findQuizCount() | ||
}); | ||
return scoResource; | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,28 @@ | ||
var test = require('tap').test; | ||
var parseManifestXml = require('../parseManifestXml.js'); | ||
var readManifestXml = require('../readManifestXml.js'); | ||
|
||
test('Finds SCO HTML file href in Articulate SCO', function(t) { | ||
var manifestJSON; | ||
|
||
t.test('Reads SCO XML file', function (t) { | ||
t.test('Finds quiz in SCO', function (t) { | ||
var params = {pathToExtractZip: 'testFiles/parseManifestXmlTests/articulate/scoWithQuiz'}; | ||
readManifestXml(params, function (err, result) { | ||
t.notOk(err, 'Should not error'); | ||
t.ok(result, 'Should receive XML JSONified'); | ||
manifestJSON = result; | ||
t.end(); | ||
}); | ||
}); | ||
|
||
t.test('Finds SCO HTML file href in read XML', function (t) { | ||
parseManifestXml(manifestJSON, function (err, result) { | ||
parseManifestXml(params, function (err, result) { | ||
t.notOk(err, 'Should not error'); | ||
t.ok(result, 'Should receive information parsed from the manifest XML'); | ||
t.equal(result.scoHtmlHref, 'index_lms.html', 'Should receive the SCO\'s start-up HTML file from the manifest'); | ||
t.equal(result.scoHtmlHref, 'index_lms.html', 'got a starting point'); | ||
t.equal(result.quizCount, 1, 'Recognize that a quiz exists in the sco'); | ||
t.end(); | ||
}); | ||
}); | ||
t.end(); | ||
}); | ||
|
||
test('Finds SCO HTML file href in Captivate SCO', function(t) { | ||
var manifestJSON; | ||
|
||
t.test('Reads SCO XML file', function (t) { | ||
t.test('Finds no quiz in SCO', function (t) { | ||
var params = {pathToExtractZip: 'testFiles/parseManifestXmlTests/captivate/scoWithNoQuizAndSwfAndHtml5Outputs'}; | ||
readManifestXml(params, function (err, result) { | ||
t.notOk(err, 'Should not error'); | ||
t.ok(result, 'Should receive XML JSONified'); | ||
manifestJSON = result; | ||
t.end(); | ||
}); | ||
}); | ||
|
||
t.test('Finds SCO HTML file href in read XML', function (t) { | ||
parseManifestXml(manifestJSON, function (err, result) { | ||
parseManifestXml(params, function (err, result) { | ||
t.notOk(err, 'Should not error'); | ||
t.ok(result, 'Should receive information parsed from the manifest XML'); | ||
t.equal(result.scoHtmlHref, 'multiscreen.html', 'Should receive the SCO\'s start-up HTML file from the manifest'); | ||
t.equal(result.scoHtmlHref, 'multiscreen.html', 'got a starting point'); | ||
t.equal(result.quizCount, 0, 'Finds no quizzes in the sco'); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
t.end(); | ||
}); |
Defining a function inside the
fs.readFile
cb isn't wrong, but it's not what one would expect.