Skip to content

Commit

Permalink
Prevent doclet paths from being shortened twice
Browse files Browse the repository at this point in the history
Prevent doclet paths from being shortened twice.

Solve: issue davidshimjs#23 (equivalent to jsdoc/jsdoc#514)
Based on: jsdoc/jsdoc@f958ab0
  • Loading branch information
tgirardi authored and bsvensson committed Mar 19, 2015
1 parent 6c8171f commit 5617ccb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
20 changes: 6 additions & 14 deletions publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,14 @@ function shortenPaths(files, commonPrefix) {
return files;
}

function resolveSourcePath(filepath) {
return path.resolve(process.cwd(), filepath);
}

function getPathFromDoclet(doclet) {
if (!doclet.meta) {
return;
}

var filepath = doclet.meta.path && doclet.meta.path !== 'null' ?
return doclet.meta.path && doclet.meta.path !== 'null' ?
doclet.meta.path + '/' + doclet.meta.filename :
doclet.meta.filename;

return filepath;
}

function generate(title, docs, filename, resolveLinks) {
Expand Down Expand Up @@ -140,7 +134,7 @@ function generate(title, docs, filename, resolveLinks) {
function generateSourceFiles(sourceFiles) {
Object.keys(sourceFiles).forEach(function(file) {
var source;
// links are keyed to the shortened path in each doclet's `meta.filename` property
// links are keyed to the shortened path in each doclet's `meta.shortpath.` property
var sourceOutfile = helper.getUniqueFilename(sourceFiles[file].shortened);
helper.registerLink(sourceFiles[file].shortened, sourceOutfile);

Expand Down Expand Up @@ -318,15 +312,13 @@ exports.publish = function(taffyData, opts, tutorials) {

// build a list of source files
var sourcePath;
var resolvedSourcePath;
if (doclet.meta) {
sourcePath = getPathFromDoclet(doclet);
resolvedSourcePath = resolveSourcePath(sourcePath);
sourceFiles[sourcePath] = {
resolved: resolvedSourcePath,
resolved: sourcePath,
shortened: null
};
sourceFilePaths.push(resolvedSourcePath);
sourceFilePaths.push(sourcePath);
}
});

Expand Down Expand Up @@ -376,13 +368,13 @@ exports.publish = function(taffyData, opts, tutorials) {
var url = helper.createLink(doclet);
helper.registerLink(doclet.longname, url);

// replace the filename with a shortened version of the full path
// add a shortened version of the full path
var docletPath;
if (doclet.meta) {
docletPath = getPathFromDoclet(doclet);
docletPath = sourceFiles[docletPath].shortened;
if (docletPath) {
doclet.meta.filename = docletPath;
doclet.meta.shortpath = docletPath;
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion tmpl/method.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var self = this;

<?js if (data.meta) {?>
<div class="tag-source">
<?js= self.linkto(meta.filename) ?>, <?js= self.linkto(meta.filename, 'line ' + meta.lineno, null, 'line' + meta.lineno) ?>
<?js= self.linkto(meta.shortpath) ?>, <?js= self.linkto(meta.shortpath, 'line ' + meta.lineno, null, 'line' + meta.lineno) ?>
</div>
<?js } ?>
</div>
Expand Down

0 comments on commit 5617ccb

Please sign in to comment.