Skip to content

Commit

Permalink
build(docs-infra): include packages in API template breadcrumbs (#25453)
Browse files Browse the repository at this point in the history
PR Close #25453
  • Loading branch information
petebacondarwin authored and benlesh committed Aug 14, 2018
1 parent 1c86e9b commit bf441e8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,27 @@ module.exports = function computeApiBreadCrumbs(API_DOC_TYPES_TO_RENDER) {
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 });
if (isSecondaryEntryPoint(doc)) {
doc.breadCrumbs.push(createPackageBreadcrumb(doc));
}
if (doc.moduleDoc) {
if (isSecondaryEntryPoint(doc.moduleDoc)) {
doc.breadCrumbs.push(createPackageBreadcrumb(doc.moduleDoc));
}
doc.breadCrumbs.push({ text: '@angular/' + doc.moduleDoc.id, path: doc.moduleDoc.path });
}
doc.breadCrumbs.push({ text: doc.name, path: doc.path });
}

});
}
};
};

function isSecondaryEntryPoint(doc) {
return doc.docType === 'package' && !doc.isPrimaryPackage;
}

function createPackageBreadcrumb(doc) {
return { text: doc.packageInfo.primary.name, path: doc.packageInfo.primary.path };
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ describe('angular-api-package: computeApiBreadCrumbs processor', () => {
const API_DOC_TYPES_TO_RENDER = ['class', 'interface', 'package'];
const processor = processorFactory(API_DOC_TYPES_TO_RENDER);

const httpPackage = { docType: 'package', name: '@angular/http', id: 'http', path: 'http', isPrimaryPackage: true };
const httpTestingPackage = { docType: 'package', name: '@angular/http/testing', id: 'http/testing', path: 'http/testing', packageInfo: { primary: httpPackage } };
const testRequestClass = { docType: 'class', name: 'TestRequest', path: 'http/testing/test-request', moduleDoc: httpTestingPackage };

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: 'package', name: 'testing', id: 'http/testing', path: 'http/testing' },
httpPackage,
httpTestingPackage,
testRequestClass
];
processor.$process(docs);

Expand All @@ -38,7 +44,18 @@ describe('angular-api-package: computeApiBreadCrumbs processor', () => {
expect(docs[2].breadCrumbs).toBeUndefined();
expect(docs[3].breadCrumbs).toEqual([
{ text: 'API', path: '/api' },
{ text: 'testing', path: 'http/testing' },
{ text: '@angular/http', path: 'http' },
]);
expect(docs[4].breadCrumbs).toEqual([
{ text: 'API', path: '/api' },
{ text: '@angular/http', path: 'http' },
{ text: '@angular/http/testing', path: 'http/testing' },
]);
expect(docs[5].breadCrumbs).toEqual([
{ text: 'API', path: '/api' },
{ text: '@angular/http', path: 'http' },
{ text: '@angular/http/testing', path: 'http/testing' },
{ text: 'TestRequest', path: 'http/testing/test-request' },
]);
});
});

0 comments on commit bf441e8

Please sign in to comment.