mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Merge pull request #281 from mathematicalcoffee/template-event-list-in-index
Default template: Event list in right hand sidebar
This commit is contained in:
commit
f79728ed62
@ -123,14 +123,16 @@ var find = exports.find = function(data, spec) {
|
||||
* + Mixins
|
||||
* + Modules
|
||||
* + Namespaces
|
||||
* + Events
|
||||
* @param {TAFFY} data The TaffyDB database to search.
|
||||
* @return {object} An object with `classes`, `externals`, `globals`, `mixins`, `modules`, and
|
||||
* `namespaces` properties. Each property contains an array of objects.
|
||||
* @return {object} An object with `classes`, `externals`, `globals`, `mixins`, `modules`,
|
||||
* `events`, and `namespaces` properties. Each property contains an array of objects.
|
||||
*/
|
||||
exports.getMembers = function(data) {
|
||||
return {
|
||||
classes: find( data, {kind: 'class'} ),
|
||||
externals: find( data, {kind: 'external'} ),
|
||||
events: find( data, {kind: 'event'} ),
|
||||
globals: find(data, {
|
||||
kind: ['member', 'function', 'constant', 'typedef'],
|
||||
memberof: { isUndefined: true }
|
||||
|
||||
@ -82,6 +82,7 @@ function generate(title, docs, filename) {
|
||||
* @param {array<object>} members.modules
|
||||
* @param {array<object>} members.namespaces
|
||||
* @param {array<object>} members.tutorials
|
||||
* @param {array<object>} members.events
|
||||
* @return {string} The HTML for the navigation sidebar.
|
||||
*/
|
||||
function buildNav(members) {
|
||||
@ -133,6 +134,18 @@ function buildNav(members) {
|
||||
|
||||
nav += '</ul>';
|
||||
}
|
||||
|
||||
if (members.events.length) {
|
||||
nav += '<h3>Events</h3><ul>';
|
||||
members.events.forEach(function(e) {
|
||||
if ( !hasOwnProp.call(seen, e.longname) ) {
|
||||
nav += '<li>'+linkto(e.longname, e.name)+'</li>';
|
||||
}
|
||||
seen[e.longname] = true;
|
||||
});
|
||||
|
||||
nav += '</ul>';
|
||||
}
|
||||
|
||||
if (members.namespaces.length) {
|
||||
nav += '<h3>Namespaces</h3><ul>';
|
||||
|
||||
@ -202,8 +202,111 @@ describe("jsdoc/util/templateHelper", function() {
|
||||
});
|
||||
});
|
||||
|
||||
xdescribe("getMembers", function() {
|
||||
// TODO
|
||||
// we can't use toEqual() because TaffyDB adds its own stuff to the array it returns.
|
||||
// instead, we make sure arrays a and b are the same length, and that each object in
|
||||
// array b has all the properties of the corresponding object in array a
|
||||
// used for getMembers and prune tests.
|
||||
function compareObjectArrays(a, b) {
|
||||
expect(a.length).toEqual(b.length);
|
||||
|
||||
for (var i = 0, l = a.length; i < l; i++) {
|
||||
for (var prop in a[i]) {
|
||||
if ( hasOwnProp.call(a[i], prop) ) {
|
||||
expect(b[i][prop]).toBeDefined();
|
||||
expect(a[i][prop]).toEqual(b[i][prop]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
describe("getMembers", function() {
|
||||
// instead parse a file from fixtures and verify it?
|
||||
var classes = [
|
||||
{kind: 'class'}, // global
|
||||
{kind: 'class', memberof: 'SomeNamespace'}, // not global
|
||||
];
|
||||
var externals = [
|
||||
{kind: 'external'},
|
||||
];
|
||||
var events = [
|
||||
{kind: 'event'},
|
||||
];
|
||||
var mixins = [
|
||||
{kind: 'mixin'},
|
||||
];
|
||||
var modules = [
|
||||
{kind: 'module'},
|
||||
];
|
||||
var namespaces = [
|
||||
{kind: 'namespace'},
|
||||
];
|
||||
var misc = [
|
||||
{kind: 'function'}, // global
|
||||
{kind: 'member'}, // global
|
||||
{kind: 'constant'}, // global
|
||||
{kind: 'typedef'}, // global
|
||||
{kind: 'constant', memberof: 'module:one/two'}, // not global
|
||||
];
|
||||
var array = classes.concat(externals.concat(events.concat(mixins.concat(modules.concat(namespaces.concat(misc))))));
|
||||
var data = require('taffydb').taffy(array);
|
||||
var members = helper.getMembers(data);
|
||||
|
||||
// check the output object has properties as expected.
|
||||
it("should have a 'classes' property", function() {
|
||||
expect(members.classes).toBeDefined();
|
||||
});
|
||||
|
||||
it("should have a 'externals' property", function() {
|
||||
expect(members.externals).toBeDefined();
|
||||
});
|
||||
|
||||
it("should have a 'events' property", function() {
|
||||
expect(members.events).toBeDefined();
|
||||
});
|
||||
|
||||
it("should have a 'globals' property", function() {
|
||||
expect(members.globals).toBeDefined();
|
||||
});
|
||||
|
||||
it("should have a 'mixins' property", function() {
|
||||
expect(members.mixins).toBeDefined();
|
||||
});
|
||||
|
||||
it("should have a 'modules' property", function() {
|
||||
expect(members.modules).toBeDefined();
|
||||
});
|
||||
|
||||
it("should have a 'namespaces' property", function() {
|
||||
expect(members.namespaces).toBeDefined();
|
||||
});
|
||||
|
||||
// check that things were found properly.
|
||||
it("classes are detected", function() {
|
||||
compareObjectArrays(classes, members.classes);
|
||||
});
|
||||
|
||||
it("externals are detected", function() {
|
||||
compareObjectArrays(externals, members.externals);
|
||||
});
|
||||
|
||||
it("events are detected", function() {
|
||||
compareObjectArrays(events, members.events);
|
||||
});
|
||||
|
||||
it("mixins are detected", function() {
|
||||
compareObjectArrays(mixins, members.mixins);
|
||||
});
|
||||
|
||||
it("modules are detected", function() {
|
||||
compareObjectArrays(modules, members.modules);
|
||||
});
|
||||
|
||||
it("namespaces are detected", function() {
|
||||
compareObjectArrays(namespaces, members.namespaces);
|
||||
});
|
||||
|
||||
it("globals are detected", function() {
|
||||
compareObjectArrays(misc.slice(0, -1), members.globals);
|
||||
});
|
||||
});
|
||||
|
||||
xdescribe("getAttribs", function() {
|
||||
@ -227,21 +330,6 @@ describe("jsdoc/util/templateHelper", function() {
|
||||
});
|
||||
|
||||
describe("prune", function() {
|
||||
// we can't use toEqual() because TaffyDB adds its own stuff to the array it returns.
|
||||
// instead, we make sure arrays a and b are the same length, and that each object in
|
||||
// array b has all the properties of the corresponding object in array a
|
||||
function compareObjectArrays(a, b) {
|
||||
expect(a.length).toEqual(b.length);
|
||||
|
||||
for (var i = 0, l = a.length; i < l; i++) {
|
||||
for (var prop in a[i]) {
|
||||
if ( hasOwnProp.call(a[i], prop) ) {
|
||||
expect(b[i][prop]).toBeDefined();
|
||||
expect(a[i][prop]).toEqual(b[i][prop]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var taffy = require('taffydb').taffy;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user