Skip to content

Commit 91942a1

Browse files
devversionjelbourn
authored andcommitted
build: allow jumping to base class of api class (#14232)
References #14122
1 parent 8354a63 commit 91942a1

File tree

5 files changed

+51
-15
lines changed

5 files changed

+51
-15
lines changed

test/karma-test-shim.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ function configureTestBed() {
4646
var testing = providers[1];
4747
var testingBrowser = providers[2];
4848

49-
console.log('----------');
5049
console.log('Running tests using Angular version: ' + core.VERSION.full);
51-
console.log('----------');
5250

5351
var testBed = testing.TestBed.initTestEnvironment(
5452
testingBrowser.BrowserDynamicTestingModule,

tools/dgeni/common/compute-api-url.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {Document} from 'dgeni';
2+
import {ModuleInfo} from '../processors/entry-point-grouper';
3+
4+
/**
5+
* Computes an URL that refers to the given API document in the docs. Note that this logic
6+
* needs to be kept in sync with the routes from the material.angular.io CLI project.
7+
*/
8+
export function computeApiDocumentUrl(apiDoc: Document, moduleInfo: ModuleInfo): string {
9+
// Base URL for the given package. This is currently either:
10+
// 1) material.angular.io/cdk
11+
// 2) material.angular.io/components
12+
const baseUrl = moduleInfo.packageName === 'cdk' ? 'cdk' : 'components';
13+
return `${baseUrl}/${moduleInfo.entryPointName}/api#${apiDoc.name}`;
14+
}

tools/dgeni/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ apiDocsPackage.config((parseTagsProcessor: any) => {
9898
]);
9999
});
100100

101+
apiDocsPackage.config((checkAnchorLinksProcessor: any) => {
102+
// This ensures that Dgeni will fail if we generate links that don't follow this format.
103+
checkAnchorLinksProcessor.ignoredLinks.push(/(components|cdk)\/[\w-]+\/api#\w+/);
104+
});
105+
101106
// Configure the processor for understanding TypeScript.
102107
apiDocsPackage.config((readTypeScriptModules: ReadTypeScriptModules, tsParser: TsParser) => {
103108
readTypeScriptModules.basePath = sourceDir;

tools/dgeni/processors/entry-point-grouper.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@ import {FunctionExportDoc} from 'dgeni-packages/typescript/api-doc-types/Functio
44
import {InterfaceExportDoc} from 'dgeni-packages/typescript/api-doc-types/InterfaceExportDoc';
55
import {TypeAliasExportDoc} from 'dgeni-packages/typescript/api-doc-types/TypeAliasExportDoc';
66
import * as path from 'path';
7+
import {computeApiDocumentUrl} from '../common/compute-api-url';
78
import {CategorizedClassDoc} from '../common/dgeni-definitions';
89

10+
export interface ModuleInfo {
11+
/** Name of the module (e.g. toolbar, drag-drop, ripple) */
12+
name: string;
13+
/** Name of the package that contains this entry point. */
14+
packageName: string;
15+
/** Name of the entry-point that contains this module. */
16+
entryPointName: string;
17+
}
18+
919
/** Document type for an entry-point. */
1020
export class EntryPointDoc {
1121

@@ -75,13 +85,17 @@ export class EntryPointGrouper implements Processor {
7585
const entryPoints = new Map<string, EntryPointDoc>();
7686

7787
docs.forEach(doc => {
78-
const documentInfo = getDocumentPackageInfo(doc);
88+
const moduleInfo = getModulePackageInfo(doc);
89+
90+
const packageName = moduleInfo.packageName;
91+
const packageDisplayName = packageName === 'cdk' ? 'CDK' : 'Material';
7992

80-
const packageName = documentInfo.packageName;
81-
const packageDisplayName = documentInfo.packageName === 'cdk' ? 'CDK' : 'Material';
93+
const moduleImportPath = `@angular/${packageName}/${moduleInfo.entryPointName}`;
94+
const entryPointName = packageName + '-' + moduleInfo.name;
8295

83-
const moduleImportPath = `@angular/${packageName}/${documentInfo.entryPointName}`;
84-
const entryPointName = packageName + '-' + documentInfo.name;
96+
// Compute a public URL that refers to the document. This is helpful if we want to
97+
// make references to other API documents. e.g. showing the extended class.
98+
doc.publicUrl = computeApiDocumentUrl(doc, moduleInfo);
8599

86100
// Get the entry-point for this doc, or, if one does not exist, create it.
87101
let entryPoint;
@@ -92,7 +106,7 @@ export class EntryPointGrouper implements Processor {
92106
entryPoints.set(entryPointName, entryPoint);
93107
}
94108

95-
entryPoint.displayName = documentInfo.name;
109+
entryPoint.displayName = moduleInfo.name;
96110
entryPoint.moduleImportPath = moduleImportPath;
97111
entryPoint.packageName = packageName;
98112
entryPoint.packageDisplayName = packageDisplayName;
@@ -121,26 +135,29 @@ export class EntryPointGrouper implements Processor {
121135
}
122136
}
123137

124-
/** Resolves package information for the given Dgeni document. */
125-
function getDocumentPackageInfo(doc: Document) {
138+
/** Resolves module package information of the given Dgeni document. */
139+
function getModulePackageInfo(doc: Document): ModuleInfo {
126140
// Full path to the file for this doc.
127141
const basePath = doc.fileInfo.basePath;
128142
const filePath = doc.fileInfo.filePath;
129143

130144
// All of the component documentation is under either `src/lib` or `src/cdk`.
131145
// We group the docs up by the directory immediately under that root.
132146
const pathSegments = path.relative(basePath, filePath).split(path.sep);
133-
let groupName = pathSegments[1];
147+
148+
// The module name is usually the entry-point (e.g. slide-toggle, toolbar), but this is not
149+
// guaranteed because we can also export a module from lib/core. e.g. the ripple module.
150+
let moduleName = pathSegments[1];
134151

135152
// The ripples are technically part of the `@angular/material/core` entry-point, but we
136153
// want to show the ripple API separately in the docs. In order to archive this, we treat
137-
// the ripple folder as its own entry-point.
154+
// the ripple folder as its own module.
138155
if (pathSegments[1] === 'core' && pathSegments[2] === 'ripple') {
139-
groupName = 'ripple';
156+
moduleName = 'ripple';
140157
}
141158

142159
return {
143-
name: groupName,
160+
name: moduleName,
144161
packageName: pathSegments[0] === 'lib' ? 'material' : pathSegments[0],
145162
entryPointName: pathSegments[1],
146163
};

tools/dgeni/templates/class.template.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ <h4 id="{$ class.name $}" class="docs-header-link docs-api-h4 docs-api-class-nam
66
{% if class.extendedDoc %}
77
<span class="docs-api-class-extends-clauses">
88
<span class="docs-api-class-extends-label">extends</span>
9-
<span class="docs-api-class-extends-type">{$ class.extendedDoc.name $}</span>
9+
<a href="{$ class.extendedDoc.publicUrl $}" class="docs-api-class-extends-type">
10+
{$ class.extendedDoc.name $}
11+
</a>
1012
</span>
1113
{% endif %}
1214
</h4>

0 commit comments

Comments
 (0)