Node.js __VERSION__ Manual & Documentation
++ Index | + View on single page | + View as JSON +
++
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..67fb6a0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/.bin/lab +node_modules/lab/ diff --git a/generate.js b/generate.js index 768f3b3..3fe7eb0 100755 --- a/generate.js +++ b/generate.js @@ -32,6 +32,7 @@ var args = process.argv.slice(2); var format = 'json'; var template = null; var inputFile = null; +var gtocPath = null; args.forEach(function (arg) { if (!arg.match(/^\-\-/)) { @@ -40,6 +41,8 @@ args.forEach(function (arg) { format = arg.replace(/^\-\-format=/, ''); } else if (arg.match(/^\-\-template=/)) { template = arg.replace(/^\-\-template=/, ''); + } else if (arg.match(/^\-\-gtoc=/)) { + gtocPath = arg.replace(/^\-\-gtoc=/, ''); } }) @@ -70,7 +73,7 @@ function next(er, input) { break; case 'html': - require('./html.js')(input, inputFile, template, function(er, html) { + require('./html.js')(input, inputFile, template, gtocPath, function(er, html) { if (er) throw er; console.log(html); }); diff --git a/html.js b/html.js index dd9efcb..3332841 100644 --- a/html.js +++ b/html.js @@ -26,19 +26,17 @@ var preprocess = require('./preprocess.js'); module.exports = toHTML; -// TODO(chrisdickinson): never stop vomitting / fix this. -var gtocPath = path.resolve(path.join(__dirname, '..', '..', 'doc', 'api', '_toc.markdown')); var gtocLoading = null; var gtocData = null; -function toHTML(input, filename, template, cb) { +function toHTML(input, filename, template, gtocPath, cb) { if (gtocData) { return onGtocLoaded(); } if (gtocLoading === null) { gtocLoading = [onGtocLoaded]; - return loadGtoc(function(err, data) { + return loadGtoc(gtocPath, function(err, data) { if (err) throw err; gtocData = data; gtocLoading.forEach(function(xs) { @@ -60,7 +58,7 @@ function toHTML(input, filename, template, cb) { } } -function loadGtoc(cb) { +function loadGtoc(gtocPath, cb) { fs.readFile(gtocPath, 'utf8', function(err, data) { if (err) return cb(err); @@ -106,7 +104,7 @@ function render(lexed, filename, template, cb) { // content has to be the last thing we do with // the lexed tokens, because it's destructive. - content = marked.parser(lexed); + var content = marked.parser(lexed); template = template.replace(/__CONTENT__/g, content); cb(null, template); diff --git a/package.json b/package.json index 89a9b60..5ad6946 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,15 @@ "engines": { "node": ">=0.6.10" }, + "scripts": { + "test": "lab -v" + }, "dependencies": { "marked": "~0.1.9" }, - "devDependencies": {}, + "devDependencies": { + "lab": "~5.2.1" + }, "optionalDependencies": {}, "bin": "./generate.js" } diff --git a/test/basic.js b/test/basic.js new file mode 100644 index 0000000..e4ba9bb --- /dev/null +++ b/test/basic.js @@ -0,0 +1,45 @@ +var Lab = require('lab'); +var lab = exports.lab = Lab.script(); +var assert = require('assert'); + +var spawn = require('child_process').spawn; + +lab.experiment('doc generation', function() { + lab.test('it renders html from *.markdown files', function(done) { + var files = [__dirname + '/fixtures/markdown/index.markdown']; + + generate('html', files, function (err, buf) { + assert.ok(/
+
+ + Index | + View on single page | + View as JSON +
+