From dc75f6328bc71818a94ec538a0b3d553bb81ca66 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Sun, 11 Nov 2012 03:17:02 -0800 Subject: [PATCH] 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. --- rhino_modules/jsdoc/tutorial/resolver.js | 7 ++----- rhino_modules/jsdoc/util/templateHelper.js | 15 ++++++++++++++- test/tutorials/incomplete/{test.js => test.json} | 0 test/tutorials/tutorials/{test.js => test.json} | 0 4 files changed, 16 insertions(+), 6 deletions(-) rename test/tutorials/incomplete/{test.js => test.json} (100%) rename test/tutorials/tutorials/{test.js => test.json} (100%) diff --git a/rhino_modules/jsdoc/tutorial/resolver.js b/rhino_modules/jsdoc/tutorial/resolver.js index 6f8a717b..fd1819f1 100644 --- a/rhino_modules/jsdoc/tutorial/resolver.js +++ b/rhino_modules/jsdoc/tutorial/resolver.js @@ -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; } diff --git a/rhino_modules/jsdoc/util/templateHelper.js b/rhino_modules/jsdoc/util/templateHelper.js index f8b58960..54ad3468 100644 --- a/rhino_modules/jsdoc/util/templateHelper.js +++ b/rhino_modules/jsdoc/util/templateHelper.js @@ -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]; }; /** diff --git a/test/tutorials/incomplete/test.js b/test/tutorials/incomplete/test.json similarity index 100% rename from test/tutorials/incomplete/test.js rename to test/tutorials/incomplete/test.json diff --git a/test/tutorials/tutorials/test.js b/test/tutorials/tutorials/test.json similarity index 100% rename from test/tutorials/tutorials/test.js rename to test/tutorials/tutorials/test.json