From 5d30f6f7523e1006169ef9853ee772d5d885baee Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Tue, 10 May 2016 11:56:56 -0700 Subject: [PATCH] tools: fix regression in doctool 101dd1e introduced a regression in the doctool. This commit reverts the changes that were made to the function signature of the various doctool functions while maintaining support for passing in specific node versions. Refs: https://github.com/nodejs/node/commit/101dd1e PR-URL: https://github.com/nodejs/node/pull/6680 Reviewed-By: Jeremiah Senkpiel Reviewed-By: Robert Lindstaedt --- tools/doc/generate.js | 16 +++++++--------- tools/doc/html.js | 36 ++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/tools/doc/generate.js b/tools/doc/generate.js index 94c0905468f862..7df987e1cf78f9 100644 --- a/tools/doc/generate.js +++ b/tools/doc/generate.js @@ -24,6 +24,8 @@ args.forEach(function(arg) { } }); +nodeVersion = nodeVersion || process.version; + if (!inputFile) { throw new Error('No input file specified'); } @@ -46,15 +48,11 @@ function next(er, input) { break; case 'html': - require('./html.js')({ - input: input, - filename: inputFile, - template: template, - nodeVersion: nodeVersion, - }, function(er, html) { - if (er) throw er; - console.log(html); - }); + require('./html.js')(input, inputFile, template, nodeVersion, + function(er, html) { + if (er) throw er; + console.log(html); + }); break; default: diff --git a/tools/doc/html.js b/tools/doc/html.js index 45d0a809143a8f..ef7d78d5b70ab3 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -30,11 +30,12 @@ var gtocPath = path.resolve(path.join( var gtocLoading = null; var gtocData = null; -/** - * opts: input, filename, template, nodeVersion. - */ -function toHTML(opts, cb) { - var template = opts.template; +function toHTML(input, filename, template, nodeVersion, cb) { + if (typeof nodeVersion === 'function') { + cb = nodeVersion; + nodeVersion = null; + } + nodeVersion = nodeVersion || process.version; if (gtocData) { return onGtocLoaded(); @@ -56,15 +57,10 @@ function toHTML(opts, cb) { } function onGtocLoaded() { - var lexed = marked.lexer(opts.input); + var lexed = marked.lexer(input); fs.readFile(template, 'utf8', function(er, template) { if (er) return cb(er); - render({ - lexed: lexed, - filename: opts.filename, - template: template, - nodeVersion: opts.nodeVersion, - }, cb); + render(lexed, filename, template, nodeVersion, cb); }); } } @@ -91,13 +87,13 @@ function toID(filename) { .replace(/-+/g, '-'); } -/** - * opts: lexed, filename, template, nodeVersion. - */ -function render(opts, cb) { - var lexed = opts.lexed; - var filename = opts.filename; - var template = opts.template; +function render(lexed, filename, template, nodeVersion, cb) { + if (typeof nodeVersion === 'function') { + cb = nodeVersion; + nodeVersion = null; + } + + nodeVersion = nodeVersion || process.version; // get the section var section = getSection(lexed); @@ -117,7 +113,7 @@ function render(opts, cb) { template = template.replace(/__ID__/g, id); template = template.replace(/__FILENAME__/g, filename); template = template.replace(/__SECTION__/g, section); - template = template.replace(/__VERSION__/g, opts.nodeVersion); + template = template.replace(/__VERSION__/g, nodeVersion); template = template.replace(/__TOC__/g, toc); template = template.replace( /__GTOC__/g,