Skip to content

Commit

Permalink
tools: fix regression in doctool
Browse files Browse the repository at this point in the history
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: nodejs@101dd1e

PR-URL: nodejs#6680
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Robert Lindstaedt <robert.lindstaedt@gmail.com>
  • Loading branch information
Myles Borins authored and addaleax committed Jul 12, 2016
1 parent ace5efe commit 9c4838f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
16 changes: 7 additions & 9 deletions tools/doc/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ args.forEach(function(arg) {
}
});

nodeVersion = nodeVersion || process.version;

if (!inputFile) {
throw new Error('No input file specified');
}
Expand All @@ -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:
Expand Down
36 changes: 16 additions & 20 deletions tools/doc/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
});
}
}
Expand All @@ -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);
Expand All @@ -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,
Expand Down

0 comments on commit 9c4838f

Please sign in to comment.