Skip to content

Commit a8533b2

Browse files
chore(doc-gen): add link inline tags
This commit enables links to other docs, such as classes and modules, via the `{@link CodeIdentifier}` style inline tag. Dgeni identifies what you are linking to by comparing the identifier to the aliases for each doc. If no alias matches the identifier then the dgeni run exits with a missing doc in link error. If more than one alias matches the identifier then dgeni exits with an ambiguous link error. In the future we could build in some heuristics for choosing a preferred doc when the link is ambiguous, such as choosing a public doc over a non-public doc; and choosing a code component that is in the same module as the doc where the link is found. Currently there are two aliases for each API component: its name and its identier. For example, if the `Directive` class is exported from `angular2/annotations`, so its aliases are 'Directive' and `angular2/annotations.Directive`. There is an issue in the non-public doc generation, which means that it does not yet have `{@link}` tags implemented. This is that when we re-export a code component, it gets cloned into another module. This means that a simple reference to the code component's name will always produce an ambiguous link. This can be fixed with a heuristic as described above. Meanwhile you can avoid this by always using the full id of the code component if it is being re-exported. Closes angular#1371 Closes angular#1421
1 parent 87ac100 commit a8533b2

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

docs/dgeni-package/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ module.exports = new Package('angular', [jsdocPackage, nunjucksPackage])
107107
computeIdsProcessor.idTemplates.push({
108108
docTypes: EXPORT_DOC_TYPES,
109109
idTemplate: '${moduleDoc.id}.${name}',
110-
getAliases: function(doc) { return [doc.id]; }
110+
getAliases: function(doc) { return [doc.id, doc.name]; }
111111
});
112112

113113
computeIdsProcessor.idTemplates.push({

docs/links-package/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var Package = require('dgeni').Package;
2+
3+
module.exports = new Package('links', [])
4+
5+
.factory(require('dgeni-packages/ngdoc/inline-tag-defs/link'))
6+
.factory(require('dgeni-packages/ngdoc/services/getAliases'))
7+
.factory(require('dgeni-packages/ngdoc/services/getDocFromAlias'))
8+
.factory(require('dgeni-packages/ngdoc/services/getLinkInfo'))
9+
10+
.config(function(inlineTagProcessor, linkInlineTagDef) {
11+
inlineTagProcessor.inlineTagDefinitions.push(linkInlineTagDef);
12+
});

docs/public-docs-package/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
var Package = require('dgeni').Package;
22
var basePackage = require('../dgeni-package');
3+
var linksPackage = require('../links-package');
34

4-
5-
module.exports = new Package('angular-public', [basePackage])
5+
module.exports = new Package('angular-public', [basePackage, linksPackage])
66

77
.processor(require('./processors/filterPublicDocs'))
88

0 commit comments

Comments
 (0)