diff --git a/lib/jsdoc/util/templateHelper.js b/lib/jsdoc/util/templateHelper.js index 61b1e25b..ca57f4e1 100644 --- a/lib/jsdoc/util/templateHelper.js +++ b/lib/jsdoc/util/templateHelper.js @@ -38,13 +38,13 @@ function getNamespace(kind) { return ''; } -function makeFilenameUnique(filename, str) { +function makeUniqueFilename(filename, str) { var key = filename.toLowerCase(); var nonUnique = true; // append enough underscores to make the filename unique while (nonUnique) { - if ( files[key] && hasOwnProp.call(files, key) ) { + if ( hasOwnProp.call(files, key) ) { filename += '_'; key = filename.toLowerCase(); } else { @@ -56,6 +56,27 @@ function makeFilenameUnique(filename, str) { return filename; } +function makeUniqueId(filename, id) { + var key = id.toLowerCase(); + var nonUnique = true; + + // append enough underscores to make the identifier unique + while (nonUnique) { + if ( hasOwnProp.call(ids, filename) && ids[filename].indexOf(key) !== -1 ) { + id += '_'; + key = id.toLowerCase(); + } + else { + nonUnique = false; + } + } + + ids[filename] = ids[filename] || []; + ids[filename].push(id); + + return id; +} + var htmlsafe = exports.htmlsafe = function(str) { return str.replace(/&/g, '&') .replace(/} A array of ancestor doclets, sorted from most to + * least distant. + */ +exports.getAncestors = function(data, doclet) { + var ancestors = []; + var doc = doclet; + + while (doc) { + doc = find(data, {longname: doc.memberof})[0]; + + if (doc) { + ancestors.unshift(doc); + } + } + + return ancestors; +}; + /** * Retrieve links to a member's ancestors. * @@ -622,21 +688,20 @@ exports.getSignatureReturns = function(d, cssClass) { * @return {Array.} HTML links to a member's ancestors. */ exports.getAncestorLinks = function(data, doclet, cssClass) { - var ancestors = [], - doc = doclet.memberof; + var ancestors = exports.getAncestors(data, doclet); + var links = []; - while (doc) { - doc = find( data, {longname: doc}, false ); - if (doc) { doc = doc[0]; } - if (!doc) { break; } - ancestors.unshift( linkto(doc.longname, (exports.scopeToPunc[doc.scope] || '') + doc.name, - cssClass) ); - doc = doc.memberof; + ancestors.forEach(function(ancestor) { + var linkText = (exports.scopeToPunc[ancestor.scope] || '') + ancestor.name; + var link = linkto(ancestor.longname, linkText, cssClass); + links.push(link); + }); + + if (links.length) { + links[links.length - 1] += (exports.scopeToPunc[doclet.scope] || ''); } - if (ancestors.length) { - ancestors[ancestors.length - 1] += (exports.scopeToPunc[doclet.scope] || ''); - } - return ancestors; + + return links; }; /** diff --git a/test/specs/jsdoc/util/templateHelper.js b/test/specs/jsdoc/util/templateHelper.js index 1db54291..c2720da0 100644 --- a/test/specs/jsdoc/util/templateHelper.js +++ b/test/specs/jsdoc/util/templateHelper.js @@ -43,6 +43,11 @@ describe("jsdoc/util/templateHelper", function() { expect(typeof helper.getUniqueFilename).toBe("function"); }); + it("should export a 'getUniqueId' function", function() { + expect(helper.getUniqueId).toBeDefined(); + expect(typeof helper.getUniqueId).toBe('function'); + }); + it("should export a 'longnameToUrl' property", function() { expect(helper.longnameToUrl).toBeDefined(); expect(typeof helper.longnameToUrl).toBe("object"); @@ -88,6 +93,11 @@ describe("jsdoc/util/templateHelper", function() { expect(typeof helper.getSignatureReturns).toBe("function"); }); + it("should export a 'getAncestors' function", function() { + expect(helper.getAncestors).toBeDefined(); + expect(typeof helper.getAncestors).toBe('function'); + }); + it("should export a 'getAncestorLinks' function", function() { expect(helper.getAncestorLinks).toBeDefined(); expect(typeof helper.getAncestorLinks).toBe("function"); @@ -215,6 +225,10 @@ describe("jsdoc/util/templateHelper", function() { }); }); + xdescribe('getUniqueId', function() { + // TODO + }); + describe("longnameToUrl", function() { it("is an object", function() { expect(typeof helper.longnameToUrl).toBe('object'); @@ -772,6 +786,10 @@ describe("jsdoc/util/templateHelper", function() { }); }); + xdescribe('getAncestors', function() { + // TODO + }); + describe("getAncestorLinks", function() { // make a hierarchy. var lackeys = new doclet.Doclet('/** @member lackeys\n@memberof module:mafia/gangs.Sharks~Henchman\n@instance*/', {}),