Skip to content

Commit 44d61b2

Browse files
devversionandrewseguin
authored andcommitted
docs: create ripples api document (#8147)
* Generates a `material-ripple.html` API file in the material docs content. This can be used to show the ripple API information in material.angular.io.
1 parent 55476e2 commit 44d61b2

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

tools/dgeni/processors/component-grouper.ts

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {CategorizedClassDoc} from './categorizer';
2-
import {DocCollection, Processor} from 'dgeni';
2+
import {DocCollection, Document, Processor} from 'dgeni';
33
import * as path from 'path';
44

55
/** Component group data structure. */
@@ -66,24 +66,13 @@ export class ComponentGrouper implements Processor {
6666
const groups = new Map<string, ComponentGroup>();
6767

6868
docs.forEach(doc => {
69-
// Full path to the file for this doc.
70-
const basePath = doc.fileInfo.basePath;
71-
const filePath = doc.fileInfo.filePath;
72-
73-
// All of the component documentation is under either `src/lib` or `src/cdk`.
74-
// We group the docs up by the directory immediately under that root.
75-
let packageName, packageDisplayName;
76-
if (filePath.includes('cdk')) {
77-
packageName = 'cdk';
78-
packageDisplayName = 'CDK';
79-
} else {
80-
packageName = 'material';
81-
packageDisplayName = 'Material';
82-
}
69+
const documentInfo = getDocumentPackageInfo(doc);
8370

84-
const displayName = path.relative(basePath, filePath).split(path.sep)[1];
85-
const moduleImportPath = `@angular/${packageName}/${displayName}`;
86-
const groupName = packageName + '-' + displayName;
71+
const packageName = documentInfo.packageName;
72+
const packageDisplayName = documentInfo.packageName === 'cdk' ? 'CDK' : 'Material';
73+
74+
const moduleImportPath = `@angular/${packageName}/${documentInfo.entryPointName}`;
75+
const groupName = packageName + '-' + documentInfo.name;
8776

8877
// Get the group for this doc, or, if one does not exist, create it.
8978
let group;
@@ -94,9 +83,8 @@ export class ComponentGrouper implements Processor {
9483
groups.set(groupName, group);
9584
}
9685

97-
group.displayName = displayName;
86+
group.displayName = documentInfo.name;
9887
group.moduleImportPath = moduleImportPath;
99-
10088
group.packageName = packageName;
10189
group.packageDisplayName = packageDisplayName;
10290

@@ -115,3 +103,27 @@ export class ComponentGrouper implements Processor {
115103
return Array.from(groups.values());
116104
}
117105
}
106+
107+
/** Resolves package information for the given Dgeni document. */
108+
function getDocumentPackageInfo(doc: Document) {
109+
// Full path to the file for this doc.
110+
const basePath = doc.fileInfo.basePath;
111+
const filePath = doc.fileInfo.filePath;
112+
113+
// All of the component documentation is under either `src/lib` or `src/cdk`.
114+
// We group the docs up by the directory immediately under that root.
115+
const pathSegments = path.relative(basePath, filePath).split(path.sep);
116+
let groupName = pathSegments[1];
117+
118+
// For the ripples there should be a component group in the docs. Even it's not a
119+
// secondary-entry point it can be still documented with its own `material-ripple.html` file.
120+
if (pathSegments[1] === 'core' && pathSegments[2] === 'ripple') {
121+
groupName = 'ripple';
122+
}
123+
124+
return {
125+
name: groupName,
126+
packageName: pathSegments[0] === 'lib' ? 'material' : pathSegments[0],
127+
entryPointName: pathSegments[1],
128+
};
129+
}

0 commit comments

Comments
 (0)