build(docs-infra): include packages in API template breadcrumbs (#25453)
PR Close #25453
This commit is contained in:
parent
78f477652e
commit
4e45f2c481
|
@ -8,11 +8,27 @@ module.exports = function computeApiBreadCrumbs(API_DOC_TYPES_TO_RENDER) {
|
||||||
if (API_DOC_TYPES_TO_RENDER.indexOf(doc.docType) !== -1) {
|
if (API_DOC_TYPES_TO_RENDER.indexOf(doc.docType) !== -1) {
|
||||||
doc.breadCrumbs = [];
|
doc.breadCrumbs = [];
|
||||||
doc.breadCrumbs.push({ text: 'API', path: '/api' });
|
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 });
|
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 };
|
||||||
|
}
|
||||||
|
|
|
@ -17,11 +17,17 @@ describe('angular-api-package: computeApiBreadCrumbs processor', () => {
|
||||||
const API_DOC_TYPES_TO_RENDER = ['class', 'interface', 'package'];
|
const API_DOC_TYPES_TO_RENDER = ['class', 'interface', 'package'];
|
||||||
const processor = processorFactory(API_DOC_TYPES_TO_RENDER);
|
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 = [
|
const docs = [
|
||||||
{ docType: 'class', name: 'ClassA', path: 'module-1/class-a', moduleDoc: { id: 'moduleOne', path: 'module-1' } },
|
{ 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: 'interface', name: 'InterfaceB', path: 'module-2/interface-b', moduleDoc: { id: 'moduleTwo', path: 'module-2' } },
|
||||||
{ docType: 'guide', name: 'Guide One', path: 'guide/guide-1' },
|
{ 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);
|
processor.$process(docs);
|
||||||
|
|
||||||
|
@ -38,7 +44,18 @@ describe('angular-api-package: computeApiBreadCrumbs processor', () => {
|
||||||
expect(docs[2].breadCrumbs).toBeUndefined();
|
expect(docs[2].breadCrumbs).toBeUndefined();
|
||||||
expect(docs[3].breadCrumbs).toEqual([
|
expect(docs[3].breadCrumbs).toEqual([
|
||||||
{ text: 'API', path: '/api' },
|
{ 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' },
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue