remove variations before generating filenames (#179)

This commit is contained in:
Jeff Williams 2013-04-15 06:50:27 -07:00
parent e592427fce
commit 263e3ca2e4
2 changed files with 11 additions and 7 deletions

View File

@ -68,8 +68,10 @@ var nsprefix = /^(event|module|external):/;
var getUniqueFilename = exports.getUniqueFilename = function(str) { var getUniqueFilename = exports.getUniqueFilename = function(str) {
// allow for namespace prefix // allow for namespace prefix
var basename = str.replace(nsprefix, '$1-') var basename = str.replace(nsprefix, '$1-')
// and use - instead of ~ to denote 'inner' // use - instead of ~ to denote 'inner'
.replace(/~/g, '-'); .replace(/~/g, '-')
// remove the variation, if any
.replace(/\([\s\S]*\)$/, '');
// if the basename includes characters that we can't use in a filepath, remove everything up to // if the basename includes characters that we can't use in a filepath, remove everything up to
// and including the last bad character // and including the last bad character
@ -623,17 +625,14 @@ function getFilename(longname) {
/** Turn a doclet into a URL. */ /** Turn a doclet into a URL. */
exports.createLink = function(doclet) { exports.createLink = function(doclet) {
var url = ''; var url = '';
var longname; var longname = doclet.longname;
var filename; var filename;
if ( containers.indexOf(doclet.kind) !== -1 || isModuleFunction(doclet) ) { if ( containers.indexOf(doclet.kind) !== -1 || isModuleFunction(doclet) ) {
longname = doclet.longname;
url = getFilename(longname); url = getFilename(longname);
} }
else { else {
longname = doclet.longname;
filename = getFilename(doclet.memberof || exports.globalName); filename = getFilename(doclet.memberof || exports.globalName);
url = filename + '#' + getNamespace(doclet.kind) + doclet.name; url = filename + '#' + getNamespace(doclet.kind) + doclet.name;
} }

View File

@ -1,5 +1,5 @@
/*global afterEach: true, beforeEach: true, describe: true, expect: true, env: true, it: true, /*global afterEach: true, beforeEach: true, describe: true, expect: true, env: true, it: true,
spyOn: true, xdescribe: true */ jasmine: true, spyOn: true, xdescribe: true */
var hasOwnProp = Object.prototype.hasOwnProperty; var hasOwnProp = Object.prototype.hasOwnProperty;
describe("jsdoc/util/templateHelper", function() { describe("jsdoc/util/templateHelper", function() {
@ -202,6 +202,11 @@ describe("jsdoc/util/templateHelper", function() {
expect( filename1.toLowerCase() ).not.toBe( filename2.toLowerCase() ); expect( filename1.toLowerCase() ).not.toBe( filename2.toLowerCase() );
}); });
it('should remove variations from the longname before generating the filename', function() {
var filename = helper.getUniqueFilename('MyClass(foo, bar)');
expect(filename).toBe('MyClass.html');
});
}); });
describe("longnameToUrl", function() { describe("longnameToUrl", function() {