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.
This commit is contained in:
Paul Gschwendtner
2017-11-02 05:04:06 +01:00
committed by Andrew Seguin
parent 55476e2cb9
commit 44d61b2079
+31 -19
View File
@@ -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<string, ComponentGroup>();
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],
};
}