Skip to content

Commit

Permalink
show modules in navigation list - davidshimjs#27
Browse files Browse the repository at this point in the history
  • Loading branch information
bsvensson committed Mar 19, 2015
1 parent 6827820 commit b0549aa
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 30 deletions.
84 changes: 55 additions & 29 deletions publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ function getAncestorLinks(doclet) {

function hashToLink(doclet, hash) {
if ( !/^(#.+)/.test(hash) ) { return hash; }

var url = helper.createLink(doclet);

url = url.replace(/(#.+|$)/, hash);
return '<a href="' + url + '">' + hash + '</a>';
}
Expand Down Expand Up @@ -59,23 +59,23 @@ function needsSignature(doclet) {

function addSignatureParams(f) {
var params = helper.getSignatureParams(f, 'optional');

f.signature = (f.signature || '') + '('+params.join(', ')+')';
}

function addSignatureReturns(f) {
var returnTypes = helper.getSignatureReturns(f);

f.signature = '<span class="signature">'+(f.signature || '') + '</span>';

if (returnTypes.length) {
f.signature += '<span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">'+(returnTypes.length ? '{'+returnTypes.join('|')+'}' : '')+'</span>';
}
}

function addSignatureTypes(f) {
var types = helper.getSignatureTypes(f);

f.signature = (f.signature || '') + '<span class="type-signature">'+(types.length? ' :'+types.join('|') : '')+'</span>';
}

Expand All @@ -84,7 +84,7 @@ function addAttribs(f) {

if (attribs.length) {
f.attribs = '<span class="type-signature ' + (attribs[0] === 'static' ? 'static' : '') + '">' + htmlsafe(attribs.length ? attribs.join(',') : '') + '</span>';
}
}
}

function shortenPaths(files, commonPrefix) {
Expand All @@ -108,7 +108,7 @@ function getPathFromDoclet(doclet) {
doclet.meta.path + '/' + doclet.meta.filename :
doclet.meta.filename;
}

function generate(title, docs, filename, resolveLinks) {
resolveLinks = resolveLinks === false ? false : true;

Expand All @@ -117,13 +117,13 @@ function generate(title, docs, filename, resolveLinks) {
title: title,
docs: docs
};

var outpath = path.join(outdir, filename),
html = view.render('container.tmpl', docData);

if (resolveLinks) {
html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>

// Add a link target for external links @davidshimjs
html = html.toString().replace(/<a\s+([^>]*href\s*=\s*['"]*[^\s'"]*:\/\/)/ig, '<a target="_blank" $1');
}
Expand Down Expand Up @@ -158,7 +158,7 @@ function generateSourceFiles(sourceFiles) {
* exports only that class or function), then attach the classes or functions to the `module`
* property of the appropriate module doclets. The name of each class or function is also updated
* for display purposes. This function mutates the original arrays.
*
*
* @private
* @param {Array.<module:jsdoc/doclet.Doclet>} doclets - The array of classes and functions to
* check.
Expand Down Expand Up @@ -248,6 +248,32 @@ function buildNav(members) {
});
}

if (members.modules.length) {
_.each(members.modules, function (v) {
nav.push({
type: 'module',
longname: v.longname,
name: v.name,
members: find({
kind: 'member',
memberof: v.longname
}),
methods: find({
kind: 'function',
memberof: v.longname
}),
typedefs: find({
kind: 'typedef',
memberof: v.longname
}),
events: find({
kind: 'event',
memberof: v.longname
})
});
});
}

return nav;
}

Expand All @@ -265,7 +291,7 @@ exports.publish = function(taffyData, opts, tutorials) {

var templatePath = opts.template;
view = new template.Template(templatePath + '/tmpl');

// claim some special filenames in advance, so the All-Powerful Overseer of Filename Uniqueness
// doesn't try to hand them out later
var indexUrl = helper.getUniqueFilename('index');
Expand All @@ -288,7 +314,7 @@ exports.publish = function(taffyData, opts, tutorials) {
var sourceFilePaths = [];
data().each(function(doclet) {
doclet.attribs = '';

if (doclet.examples) {
doclet.examples = doclet.examples.map(function(example) {
var caption, code;
Expand Down Expand Up @@ -321,7 +347,7 @@ exports.publish = function(taffyData, opts, tutorials) {
sourceFilePaths.push(sourcePath);
}
});

// update outdir if necessary, then create outdir
var packageInfo = ( find({kind: 'package'}) || [] ) [0];
if (packageInfo && packageInfo.name) {
Expand Down Expand Up @@ -360,7 +386,7 @@ exports.publish = function(taffyData, opts, tutorials) {
});
});
}

if (sourceFilePaths.length) {
sourceFiles = shortenPaths( sourceFiles, path.commonPrefix(sourceFilePaths) );
}
Expand All @@ -378,7 +404,7 @@ exports.publish = function(taffyData, opts, tutorials) {
}
}
});

data().each(function(doclet) {
var url = helper.longnameToUrl[doclet.longname];

Expand All @@ -388,14 +414,14 @@ exports.publish = function(taffyData, opts, tutorials) {
else {
doclet.id = doclet.name;
}

if ( needsSignature(doclet) ) {
addSignatureParams(doclet);
addSignatureReturns(doclet);
addAttribs(doclet);
}
});

// do this after the urls have all been generated
data().each(function(doclet) {
doclet.ancestors = getAncestorLinks(doclet);
Expand All @@ -404,14 +430,14 @@ exports.publish = function(taffyData, opts, tutorials) {
addSignatureTypes(doclet);
addAttribs(doclet);
}

if (doclet.kind === 'constant') {
addSignatureTypes(doclet);
addAttribs(doclet);
doclet.kind = 'member';
}
});

var members = helper.getMembers(data);
members.tutorials = tutorials.children;

Expand All @@ -435,7 +461,7 @@ exports.publish = function(taffyData, opts, tutorials) {
}

if (members.globals.length) { generate('Global', [{kind: 'globalobj'}], globalUrl); }

// index page displays information from package.json and lists files
var files = find({kind: 'file'}),
packages = find({kind: 'package'});
Expand All @@ -452,14 +478,14 @@ exports.publish = function(taffyData, opts, tutorials) {
var namespaces = taffy(members.namespaces);
var mixins = taffy(members.mixins);
var externals = taffy(members.externals);

for (var longname in helper.longnameToUrl) {
if ( hasOwnProp.call(helper.longnameToUrl, longname) ) {
var myClasses = helper.find(classes, {longname: longname});
if (myClasses.length) {
generate('Class: ' + myClasses[0].name, myClasses, helper.longnameToUrl[longname]);
}

var myModules = helper.find(modules, {longname: longname});
if (myModules.length) {
generate('Module: ' + myModules[0].name, myModules, helper.longnameToUrl[longname]);
Expand All @@ -469,7 +495,7 @@ exports.publish = function(taffyData, opts, tutorials) {
if (myNamespaces.length) {
generate('Namespace: ' + myNamespaces[0].name, myNamespaces, helper.longnameToUrl[longname]);
}

var myMixins = helper.find(mixins, {longname: longname});
if (myMixins.length) {
generate('Mixin: ' + myMixins[0].name, myMixins, helper.longnameToUrl[longname]);
Expand All @@ -490,16 +516,16 @@ exports.publish = function(taffyData, opts, tutorials) {
content: tutorial.parse(),
children: tutorial.children
};

var tutorialPath = path.join(outdir, filename),
html = view.render('tutorial.tmpl', tutorialData);

// yes, you can use {@link} in tutorials too!
html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>

fs.writeFileSync(tutorialPath, html, 'utf8');
}

// tutorials can have only one parent so there is no risk for loops
function saveChildren(node) {
node.children.forEach(function(child) {
Expand Down
2 changes: 1 addition & 1 deletion static/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $(function () {
});

// Show an item related a current documentation automatically
var filename = $('.page-title').data('filename').replace(/\.[a-z]+$/, '');
var filename = $('.page-title').data('filename').replace(/\.[a-z]+$/, '').replace("-", ":");
var $currentItem = $('.navigation .item[data-name*="' + filename + '"]:eq(0)');

if ($currentItem.length) {
Expand Down

0 comments on commit b0549aa

Please sign in to comment.