fix several tutorial-related issues (#222)

- Tutorial code allowed JSON files to have a .js extension, then tried
to parse all .js files as JSON. The code now only looks for JSON files
with a .json extension. This allows .js files and tutorials to live in
the same directory.
- Recent changes caused tutorials to be generated with the wrong
filename. This is now fixed.
This commit is contained in:
Jeff Williams 2012-11-11 03:17:02 -08:00
parent ef6d78f88e
commit dc75f6328b
4 changed files with 16 additions and 6 deletions

View File

@ -14,7 +14,7 @@ var tutorial = require('jsdoc/tutorial'),
hasOwnProp = Object.prototype.hasOwnProperty, hasOwnProp = Object.prototype.hasOwnProperty,
conf = {}, conf = {},
tutorials = {}, tutorials = {},
finder = /^(.*)\.(x(?:ht)?ml|html?|md|markdown|js(?:on)?)$/i; finder = /^(.*)\.(x(?:ht)?ml|html?|md|markdown|json)$/i;
/** Adds new tutorial. /** Adds new tutorial.
@param {tutorial.Tutorial} current - New tutorial. @param {tutorial.Tutorial} current - New tutorial.
@ -75,7 +75,6 @@ exports.load = function(_path) {
break; break;
// configuration file // configuration file
case 'js':
case 'json': case 'json':
conf[name] = JSON.parse(content); conf[name] = JSON.parse(content);
// don't add this as a tutorial // don't add this as a tutorial
@ -100,9 +99,7 @@ exports.resolve = function() {
current; current;
for (var name in conf) { for (var name in conf) {
if ( hasOwnProp.call(conf, name) ) { if ( hasOwnProp.call(conf, name) ) {
// should we be restrictive here? // TODO: should we complain about this?
// what is someone just wants to keep sample sources in same directory with tutorials?
// I've decided to leave such cases alone
if (!(name in tutorials)) { if (!(name in tutorials)) {
continue; continue;
} }

View File

@ -86,6 +86,11 @@ var linkMap = {
urlToLongname: {} urlToLongname: {}
}; };
var tutorialLinkMap = {
nameToUrl: {},
urlToName: {}
};
var longnameToUrl = exports.longnameToUrl = linkMap.longnameToUrl; var longnameToUrl = exports.longnameToUrl = linkMap.longnameToUrl;
var linkto = exports.linkto = function(longname, linktext) { var linkto = exports.linkto = function(longname, linktext) {
@ -336,7 +341,15 @@ var tutorialToUrl = exports.tutorialToUrl = function(tutorial) {
return; return;
} }
return 'tutorial-' + getUniqueFilename(node.name); var url;
// define the URL if necessary
if (!tutorialLinkMap.nameToUrl[node.name]) {
url = 'tutorial-' + getUniqueFilename(node.name);
tutorialLinkMap.nameToUrl[node.name] = url;
tutorialLinkMap.urlToName[url] = node.name;
}
return tutorialLinkMap.nameToUrl[node.name];
}; };
/** /**