Skip to content

Commit

Permalink
fix several tutorial-related issues (jsdoc#222)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
hegemonic committed Nov 11, 2012
1 parent ef6d78f commit dc75f63
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
7 changes: 2 additions & 5 deletions rhino_modules/jsdoc/tutorial/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
15 changes: 14 additions & 1 deletion rhino_modules/jsdoc/util/templateHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ var linkMap = {
urlToLongname: {}
};

var tutorialLinkMap = {
nameToUrl: {},
urlToName: {}
};

var longnameToUrl = exports.longnameToUrl = linkMap.longnameToUrl;

var linkto = exports.linkto = function(longname, linktext) {
Expand Down Expand Up @@ -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];
};

/**
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit dc75f63

Please sign in to comment.