diff --git a/tools/dgeni/processors/component-grouper.ts b/tools/dgeni/processors/component-grouper.ts index 625af6ce9c2..e1f89b84ab9 100644 --- a/tools/dgeni/processors/component-grouper.ts +++ b/tools/dgeni/processors/component-grouper.ts @@ -1,5 +1,5 @@ import {CategorizedClassDoc} from './categorizer'; -import {DocCollection, Processor} from 'dgeni'; +import {DocCollection, Document, Processor} from 'dgeni'; import * as path from 'path'; /** Component group data structure. */ @@ -66,24 +66,13 @@ export class ComponentGrouper implements Processor { const groups = new Map(); docs.forEach(doc => { - // Full path to the file for this doc. - const basePath = doc.fileInfo.basePath; - const filePath = doc.fileInfo.filePath; + const documentInfo = getDocumentPackageInfo(doc); - // All of the component documentation is under either `src/lib` or `src/cdk`. - // We group the docs up by the directory immediately under that root. - let packageName, packageDisplayName; - if (filePath.includes('cdk')) { - packageName = 'cdk'; - packageDisplayName = 'CDK'; - } else { - packageName = 'material'; - packageDisplayName = 'Material'; - } + const packageName = documentInfo.packageName; + const packageDisplayName = documentInfo.packageName === 'cdk' ? 'CDK' : 'Material'; - const displayName = path.relative(basePath, filePath).split(path.sep)[1]; - const moduleImportPath = `@angular/${packageName}/${displayName}`; - const groupName = packageName + '-' + displayName; + const moduleImportPath = `@angular/${packageName}/${documentInfo.entryPointName}`; + const groupName = packageName + '-' + documentInfo.name; // Get the group for this doc, or, if one does not exist, create it. let group; @@ -94,9 +83,8 @@ export class ComponentGrouper implements Processor { groups.set(groupName, group); } - group.displayName = displayName; + group.displayName = documentInfo.name; group.moduleImportPath = moduleImportPath; - group.packageName = packageName; group.packageDisplayName = packageDisplayName; @@ -115,3 +103,27 @@ export class ComponentGrouper implements Processor { return Array.from(groups.values()); } } + +/** Resolves package information for the given Dgeni document. */ +function getDocumentPackageInfo(doc: Document) { + // Full path to the file for this doc. + const basePath = doc.fileInfo.basePath; + const filePath = doc.fileInfo.filePath; + + // All of the component documentation is under either `src/lib` or `src/cdk`. + // We group the docs up by the directory immediately under that root. + const pathSegments = path.relative(basePath, filePath).split(path.sep); + let groupName = pathSegments[1]; + + // For the ripples there should be a component group in the docs. Even it's not a + // secondary-entry point it can be still documented with its own `material-ripple.html` file. + if (pathSegments[1] === 'core' && pathSegments[2] === 'ripple') { + groupName = 'ripple'; + } + + return { + name: groupName, + packageName: pathSegments[0] === 'lib' ? 'material' : pathSegments[0], + entryPointName: pathSegments[1], + }; +}