build(aio): compute breadcrums for all API doc types (#24000)

PR Close #24000
This commit is contained in:
Pete Bacon Darwin 2018-05-23 22:20:14 +01:00 committed by Miško Hevery
parent 859a3d5784
commit 8daadf360c
2 changed files with 14 additions and 10 deletions

View File

@ -1,16 +1,15 @@
module.exports = function computeApiBreadCrumbs(EXPORT_DOC_TYPES) {
module.exports = function computeApiBreadCrumbs(API_DOC_TYPES_TO_RENDER) {
return {
$runAfter: ['paths-computed'],
$runBefore: ['rendering-docs'],
$process(docs) {
// Compute the breadcrumb for each doc by processing its containers
docs.forEach(doc => {
if (EXPORT_DOC_TYPES.indexOf(doc.docType) !== -1) {
doc.breadCrumbs = [
{ text: 'API', path: '/api' },
{ text: '@angular/' + doc.moduleDoc.id, path: doc.moduleDoc.path },
{ text: doc.name, path: doc.path }
];
if (API_DOC_TYPES_TO_RENDER.indexOf(doc.docType) !== -1) {
doc.breadCrumbs = [];
doc.breadCrumbs.push({ text: 'API', path: '/api' });
if (doc.moduleDoc) doc.breadCrumbs.push({ text: '@angular/' + doc.moduleDoc.id, path: doc.moduleDoc.path });
doc.breadCrumbs.push({ text: doc.name, path: doc.path });
}
});
}

View File

@ -13,14 +13,15 @@ describe('angular-api-package: computeApiBreadCrumbs processor', () => {
expect(processor.$runBefore).toEqual(['rendering-docs']);
});
it('should attach a breadCrumbs property to each of the EXPORT_DOC_TYPES docs', () => {
const EXPORT_DOC_TYPES = ['class', 'interface'];
const processor = processorFactory(EXPORT_DOC_TYPES);
it('should attach a breadCrumbs property to each of the API_DOC_TYPES_TO_RENDER docs', () => {
const API_DOC_TYPES_TO_RENDER = ['class', 'interface', 'module'];
const processor = processorFactory(API_DOC_TYPES_TO_RENDER);
const docs = [
{ docType: 'class', name: 'ClassA', path: 'module-1/class-a', moduleDoc: { id: 'moduleOne', path: 'module-1' } },
{ docType: 'interface', name: 'InterfaceB', path: 'module-2/interface-b', moduleDoc: { id: 'moduleTwo', path: 'module-2' } },
{ docType: 'guide', name: 'Guide One', path: 'guide/guide-1' },
{ docType: 'module', name: 'testing', id: 'http/testing', path: 'http/testing' },
];
processor.$process(docs);
@ -35,5 +36,9 @@ describe('angular-api-package: computeApiBreadCrumbs processor', () => {
{ text: 'InterfaceB', path: 'module-2/interface-b' },
]);
expect(docs[2].breadCrumbs).toBeUndefined();
expect(docs[3].breadCrumbs).toEqual([
{ text: 'API', path: '/api' },
{ text: 'testing', path: 'http/testing' },
]);
});
});