Skip to content

Commit 336a922

Browse files
author
Nicolas Joyard
committed
Add method categories to JSDoc navigation
1 parent 4f4e29d commit 336a922

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

tools/jsdoc-conf.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,10 @@
1414
"plugins": [
1515
"plugins/markdown",
1616
"tools/jsdoc-aliases.js"
17-
]
17+
],
18+
19+
"markdown": {
20+
"parser": "evilstreak",
21+
"dialect": "Markuru"
22+
}
1823
}

tools/jsdoc-template/publish.js

+22
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ function getAncestorLinks(doclet) {
2828
return helper.getAncestorLinks(data, doclet);
2929
}
3030

31+
function getCategoryLink(className, cat) {
32+
return '<a href="' + className + '.html#' + cat.toLowerCase().replace(/[^a-z0-9]/gi, '-') + '-methods">' + cat + ' methods</a>';
33+
}
34+
3135
function hashToLink(doclet, hash) {
3236
if ( !/^(#.+)/.test(hash) ) { return hash; }
3337

@@ -223,6 +227,11 @@ function buildNav(members) {
223227
members.classes.forEach(function(c) {
224228
if ( !hasOwnProp.call(seen, c.longname) ) {
225229
classNav += '<li>'+linkto(c.longname, c.name)+'</li>';
230+
if (c.longname in members.categories) {
231+
classNav += '<ul>' + members.categories[c.longname].reduce(function(nav, cat) {
232+
return nav + '<li> ' + getCategoryLink(c.longname, cat) + '</li>';
233+
}, '') + '</ul>';
234+
}
226235
}
227236
seen[c.longname] = true;
228237
});
@@ -465,6 +474,19 @@ exports.publish = function(taffyData, opts, tutorials) {
465474

466475
var members = helper.getMembers(data);
467476
members.tutorials = tutorials.children;
477+
members.categories = data('method').get().reduce(function(cats, method) {
478+
if (!(method.memberof in cats)) {
479+
cats[method.memberof] = [];
480+
}
481+
482+
var cat = method.category || 'Other';
483+
if (cats[method.memberof].indexOf(cat) === -1) {
484+
cats[method.memberof].push(cat);
485+
cats[method.memberof] = cats[method.memberof].sort();
486+
}
487+
488+
return cats;
489+
}, {});
468490

469491
// output pretty-printed source files by default
470492
var outputSourceFiles = conf['default'] && conf['default'].outputSourceFiles !== false ? true :

tools/jsdoc-template/static/styles/jsdoc-default.css

+5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ nav ul {
8686
list-style-type:none;
8787
}
8888

89+
nav ul ul {
90+
margin-left: 10px;
91+
font-size: 90%;
92+
}
93+
8994
nav h2 a, nav h2 a:visited {
9095
color: #A35A00;
9196
text-decoration: none;

tools/jsdoc-template/tmpl/container.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125

126126
Object.keys(categories).sort().forEach(function(category) {
127127
?>
128-
<h3 class="subsection-title"><?js= category ?></h3>
128+
<h3 class="subsection-title"><a name="<?js= category.toLowerCase().replace(/[^a-z0-9]/gi, '-') ?>"></a><?js= category ?></h3>
129129

130130
<dl><?js categories[category].forEach(function(m) { ?>
131131
<?js= self.partial('method.tmpl', m) ?>

0 commit comments

Comments
 (0)