Skip to content

Commit b0549aa

Browse files
committed
show modules in navigation list - davidshimjs#27
1 parent 6827820 commit b0549aa

File tree

2 files changed

+56
-30
lines changed

2 files changed

+56
-30
lines changed

publish.js

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ function getAncestorLinks(doclet) {
2929

3030
function hashToLink(doclet, hash) {
3131
if ( !/^(#.+)/.test(hash) ) { return hash; }
32-
32+
3333
var url = helper.createLink(doclet);
34-
34+
3535
url = url.replace(/(#.+|$)/, hash);
3636
return '<a href="' + url + '">' + hash + '</a>';
3737
}
@@ -59,23 +59,23 @@ function needsSignature(doclet) {
5959

6060
function addSignatureParams(f) {
6161
var params = helper.getSignatureParams(f, 'optional');
62-
62+
6363
f.signature = (f.signature || '') + '('+params.join(', ')+')';
6464
}
6565

6666
function addSignatureReturns(f) {
6767
var returnTypes = helper.getSignatureReturns(f);
68-
68+
6969
f.signature = '<span class="signature">'+(f.signature || '') + '</span>';
70-
70+
7171
if (returnTypes.length) {
7272
f.signature += '<span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">'+(returnTypes.length ? '{'+returnTypes.join('|')+'}' : '')+'</span>';
7373
}
7474
}
7575

7676
function addSignatureTypes(f) {
7777
var types = helper.getSignatureTypes(f);
78-
78+
7979
f.signature = (f.signature || '') + '<span class="type-signature">'+(types.length? ' :'+types.join('|') : '')+'</span>';
8080
}
8181

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

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

9090
function shortenPaths(files, commonPrefix) {
@@ -108,7 +108,7 @@ function getPathFromDoclet(doclet) {
108108
doclet.meta.path + '/' + doclet.meta.filename :
109109
doclet.meta.filename;
110110
}
111-
111+
112112
function generate(title, docs, filename, resolveLinks) {
113113
resolveLinks = resolveLinks === false ? false : true;
114114

@@ -117,13 +117,13 @@ function generate(title, docs, filename, resolveLinks) {
117117
title: title,
118118
docs: docs
119119
};
120-
120+
121121
var outpath = path.join(outdir, filename),
122122
html = view.render('container.tmpl', docData);
123-
123+
124124
if (resolveLinks) {
125125
html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>
126-
126+
127127
// Add a link target for external links @davidshimjs
128128
html = html.toString().replace(/<a\s+([^>]*href\s*=\s*['"]*[^\s'"]*:\/\/)/ig, '<a target="_blank" $1');
129129
}
@@ -158,7 +158,7 @@ function generateSourceFiles(sourceFiles) {
158158
* exports only that class or function), then attach the classes or functions to the `module`
159159
* property of the appropriate module doclets. The name of each class or function is also updated
160160
* for display purposes. This function mutates the original arrays.
161-
*
161+
*
162162
* @private
163163
* @param {Array.<module:jsdoc/doclet.Doclet>} doclets - The array of classes and functions to
164164
* check.
@@ -248,6 +248,32 @@ function buildNav(members) {
248248
});
249249
}
250250

251+
if (members.modules.length) {
252+
_.each(members.modules, function (v) {
253+
nav.push({
254+
type: 'module',
255+
longname: v.longname,
256+
name: v.name,
257+
members: find({
258+
kind: 'member',
259+
memberof: v.longname
260+
}),
261+
methods: find({
262+
kind: 'function',
263+
memberof: v.longname
264+
}),
265+
typedefs: find({
266+
kind: 'typedef',
267+
memberof: v.longname
268+
}),
269+
events: find({
270+
kind: 'event',
271+
memberof: v.longname
272+
})
273+
});
274+
});
275+
}
276+
251277
return nav;
252278
}
253279

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

266292
var templatePath = opts.template;
267293
view = new template.Template(templatePath + '/tmpl');
268-
294+
269295
// claim some special filenames in advance, so the All-Powerful Overseer of Filename Uniqueness
270296
// doesn't try to hand them out later
271297
var indexUrl = helper.getUniqueFilename('index');
@@ -288,7 +314,7 @@ exports.publish = function(taffyData, opts, tutorials) {
288314
var sourceFilePaths = [];
289315
data().each(function(doclet) {
290316
doclet.attribs = '';
291-
317+
292318
if (doclet.examples) {
293319
doclet.examples = doclet.examples.map(function(example) {
294320
var caption, code;
@@ -321,7 +347,7 @@ exports.publish = function(taffyData, opts, tutorials) {
321347
sourceFilePaths.push(sourcePath);
322348
}
323349
});
324-
350+
325351
// update outdir if necessary, then create outdir
326352
var packageInfo = ( find({kind: 'package'}) || [] ) [0];
327353
if (packageInfo && packageInfo.name) {
@@ -360,7 +386,7 @@ exports.publish = function(taffyData, opts, tutorials) {
360386
});
361387
});
362388
}
363-
389+
364390
if (sourceFilePaths.length) {
365391
sourceFiles = shortenPaths( sourceFiles, path.commonPrefix(sourceFilePaths) );
366392
}
@@ -378,7 +404,7 @@ exports.publish = function(taffyData, opts, tutorials) {
378404
}
379405
}
380406
});
381-
407+
382408
data().each(function(doclet) {
383409
var url = helper.longnameToUrl[doclet.longname];
384410

@@ -388,14 +414,14 @@ exports.publish = function(taffyData, opts, tutorials) {
388414
else {
389415
doclet.id = doclet.name;
390416
}
391-
417+
392418
if ( needsSignature(doclet) ) {
393419
addSignatureParams(doclet);
394420
addSignatureReturns(doclet);
395421
addAttribs(doclet);
396422
}
397423
});
398-
424+
399425
// do this after the urls have all been generated
400426
data().each(function(doclet) {
401427
doclet.ancestors = getAncestorLinks(doclet);
@@ -404,14 +430,14 @@ exports.publish = function(taffyData, opts, tutorials) {
404430
addSignatureTypes(doclet);
405431
addAttribs(doclet);
406432
}
407-
433+
408434
if (doclet.kind === 'constant') {
409435
addSignatureTypes(doclet);
410436
addAttribs(doclet);
411437
doclet.kind = 'member';
412438
}
413439
});
414-
440+
415441
var members = helper.getMembers(data);
416442
members.tutorials = tutorials.children;
417443

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

437463
if (members.globals.length) { generate('Global', [{kind: 'globalobj'}], globalUrl); }
438-
464+
439465
// index page displays information from package.json and lists files
440466
var files = find({kind: 'file'}),
441467
packages = find({kind: 'package'});
@@ -452,14 +478,14 @@ exports.publish = function(taffyData, opts, tutorials) {
452478
var namespaces = taffy(members.namespaces);
453479
var mixins = taffy(members.mixins);
454480
var externals = taffy(members.externals);
455-
481+
456482
for (var longname in helper.longnameToUrl) {
457483
if ( hasOwnProp.call(helper.longnameToUrl, longname) ) {
458484
var myClasses = helper.find(classes, {longname: longname});
459485
if (myClasses.length) {
460486
generate('Class: ' + myClasses[0].name, myClasses, helper.longnameToUrl[longname]);
461487
}
462-
488+
463489
var myModules = helper.find(modules, {longname: longname});
464490
if (myModules.length) {
465491
generate('Module: ' + myModules[0].name, myModules, helper.longnameToUrl[longname]);
@@ -469,7 +495,7 @@ exports.publish = function(taffyData, opts, tutorials) {
469495
if (myNamespaces.length) {
470496
generate('Namespace: ' + myNamespaces[0].name, myNamespaces, helper.longnameToUrl[longname]);
471497
}
472-
498+
473499
var myMixins = helper.find(mixins, {longname: longname});
474500
if (myMixins.length) {
475501
generate('Mixin: ' + myMixins[0].name, myMixins, helper.longnameToUrl[longname]);
@@ -490,16 +516,16 @@ exports.publish = function(taffyData, opts, tutorials) {
490516
content: tutorial.parse(),
491517
children: tutorial.children
492518
};
493-
519+
494520
var tutorialPath = path.join(outdir, filename),
495521
html = view.render('tutorial.tmpl', tutorialData);
496-
522+
497523
// yes, you can use {@link} in tutorials too!
498524
html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>
499-
525+
500526
fs.writeFileSync(tutorialPath, html, 'utf8');
501527
}
502-
528+
503529
// tutorials can have only one parent so there is no risk for loops
504530
function saveChildren(node) {
505531
node.children.forEach(function(child) {

static/scripts/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ $(function () {
3030
});
3131

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

3636
if ($currentItem.length) {

0 commit comments

Comments
 (0)