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 <fishrock123@rocketmail.com>
Reviewed-By: Robert Lindstaedt <robert.lindstaedt@gmail.com>
This commit is contained in:
Myles Borins 2016-05-10 11:56:56 -07:00
parent 0912b88320
commit 572e28efa2
2 changed files with 23 additions and 29 deletions

View File

@ -24,6 +24,8 @@ args.forEach(function(arg) {
} }
}); });
nodeVersion = nodeVersion || process.version;
if (!inputFile) { if (!inputFile) {
throw new Error('No input file specified'); throw new Error('No input file specified');
} }
@ -46,15 +48,11 @@ function next(er, input) {
break; break;
case 'html': case 'html':
require('./html.js')({ require('./html.js')(input, inputFile, template, nodeVersion,
input: input, function(er, html) {
filename: inputFile, if (er) throw er;
template: template, console.log(html);
nodeVersion: nodeVersion, });
}, function(er, html) {
if (er) throw er;
console.log(html);
});
break; break;
default: default:

View File

@ -30,11 +30,12 @@ var gtocPath = path.resolve(path.join(
var gtocLoading = null; var gtocLoading = null;
var gtocData = null; var gtocData = null;
/** function toHTML(input, filename, template, nodeVersion, cb) {
* opts: input, filename, template, nodeVersion. if (typeof nodeVersion === 'function') {
*/ cb = nodeVersion;
function toHTML(opts, cb) { nodeVersion = null;
var template = opts.template; }
nodeVersion = nodeVersion || process.version;
if (gtocData) { if (gtocData) {
return onGtocLoaded(); return onGtocLoaded();
@ -56,15 +57,10 @@ function toHTML(opts, cb) {
} }
function onGtocLoaded() { function onGtocLoaded() {
var lexed = marked.lexer(opts.input); var lexed = marked.lexer(input);
fs.readFile(template, 'utf8', function(er, template) { fs.readFile(template, 'utf8', function(er, template) {
if (er) return cb(er); if (er) return cb(er);
render({ render(lexed, filename, template, nodeVersion, cb);
lexed: lexed,
filename: opts.filename,
template: template,
nodeVersion: opts.nodeVersion,
}, cb);
}); });
} }
} }
@ -91,13 +87,13 @@ function toID(filename) {
.replace(/-+/g, '-'); .replace(/-+/g, '-');
} }
/** function render(lexed, filename, template, nodeVersion, cb) {
* opts: lexed, filename, template, nodeVersion. if (typeof nodeVersion === 'function') {
*/ cb = nodeVersion;
function render(opts, cb) { nodeVersion = null;
var lexed = opts.lexed; }
var filename = opts.filename;
var template = opts.template; nodeVersion = nodeVersion || process.version;
// get the section // get the section
var section = getSection(lexed); var section = getSection(lexed);
@ -117,7 +113,7 @@ function render(opts, cb) {
template = template.replace(/__ID__/g, id); template = template.replace(/__ID__/g, id);
template = template.replace(/__FILENAME__/g, filename); template = template.replace(/__FILENAME__/g, filename);
template = template.replace(/__SECTION__/g, section); 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(/__TOC__/g, toc);
template = template.replace( template = template.replace(
/__GTOC__/g, /__GTOC__/g,