Skip to content

Commit

Permalink
remove variations before generating filenames (jsdoc#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
hegemonic committed Apr 15, 2013
1 parent e592427 commit 263e3ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 5 additions & 6 deletions lib/jsdoc/util/templateHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ var nsprefix = /^(event|module|external):/;
var getUniqueFilename = exports.getUniqueFilename = function(str) {
// allow for namespace prefix
var basename = str.replace(nsprefix, '$1-')
// and use - instead of ~ to denote 'inner'
.replace(/~/g, '-');
// use - instead of ~ to denote 'inner'
.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
// and including the last bad character
Expand Down Expand Up @@ -623,17 +625,14 @@ function getFilename(longname) {
/** Turn a doclet into a URL. */
exports.createLink = function(doclet) {
var url = '';
var longname;
var longname = doclet.longname;
var filename;

if ( containers.indexOf(doclet.kind) !== -1 || isModuleFunction(doclet) ) {
longname = doclet.longname;
url = getFilename(longname);
}
else {
longname = doclet.longname;
filename = getFilename(doclet.memberof || exports.globalName);

url = filename + '#' + getNamespace(doclet.kind) + doclet.name;
}

Expand Down
7 changes: 6 additions & 1 deletion test/specs/jsdoc/util/templateHelper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*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;

describe("jsdoc/util/templateHelper", function() {
Expand Down Expand Up @@ -202,6 +202,11 @@ describe("jsdoc/util/templateHelper", function() {

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() {
Expand Down

0 comments on commit 263e3ca

Please sign in to comment.