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

View File

@ -86,6 +86,11 @@ var linkMap = {
urlToLongname: {}
};
var tutorialLinkMap = {
nameToUrl: {},
urlToName: {}
};
var longnameToUrl = exports.longnameToUrl = linkMap.longnameToUrl;
var linkto = exports.linkto = function(longname, linktext) {
@ -336,7 +341,15 @@ var tutorialToUrl = exports.tutorialToUrl = function(tutorial) {
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];
};
/**