From 4e45f2c481d06925882d6dd3bc393649996ae9aa Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Mon, 13 Aug 2018 10:56:03 +0100 Subject: [PATCH] build(docs-infra): include packages in API template breadcrumbs (#25453) PR Close #25453 --- .../processors/computeApiBreadCrumbs.js | 18 +++++++++++++++- .../processors/computeApiBreadCrumbs.spec.js | 21 +++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/aio/tools/transforms/angular-api-package/processors/computeApiBreadCrumbs.js b/aio/tools/transforms/angular-api-package/processors/computeApiBreadCrumbs.js index 62eb6c2225..622b4d3202 100644 --- a/aio/tools/transforms/angular-api-package/processors/computeApiBreadCrumbs.js +++ b/aio/tools/transforms/angular-api-package/processors/computeApiBreadCrumbs.js @@ -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 }; +} diff --git a/aio/tools/transforms/angular-api-package/processors/computeApiBreadCrumbs.spec.js b/aio/tools/transforms/angular-api-package/processors/computeApiBreadCrumbs.spec.js index 256d7c44d2..2266cc149b 100644 --- a/aio/tools/transforms/angular-api-package/processors/computeApiBreadCrumbs.spec.js +++ b/aio/tools/transforms/angular-api-package/processors/computeApiBreadCrumbs.spec.js @@ -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); @@ -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' }, ]); }); });