Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 40a1049

Browse files
petebacondarwinIgorMinar
authored andcommitted
doc-gen(mergeDecoratorDocs): capture all the metadata docs
Iterate through the docs and merge all the of metadata docs for each decorator doc into the decorator doc and remove it so that it is not rendered in a page of its own
1 parent 30fbd85 commit 40a1049

File tree

4 files changed

+77
-40
lines changed

4 files changed

+77
-40
lines changed

tools/api-builder/docs-package/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
1818
.processor(require('./processors/checkUnbalancedBackTicks'))
1919
.processor(require('./processors/convertBackticksToCodeBlocks'))
2020
.processor(require('./processors/addNotYetDocumentedProperty'))
21-
.processor(require('./processors/createDecoratorDocs'))
21+
.processor(require('./processors/mergeDecoratorDocs'))
2222

2323
.config(function(parseTagsProcessor) {
2424
parseTagsProcessor.tagDefinitions.push({ name: 'internal', transforms: function() { return true; } });

tools/api-builder/docs-package/processors/createDecoratorDocs.js

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
var _ = require('lodash');
2+
3+
module.exports = function mergeDecoratorDocs() {
4+
return {
5+
$runAfter: ['processing-docs'],
6+
$runBefore: ['docs-processed'],
7+
docsToMergeInfo: [
8+
{ nameTemplate: _.template('${name}Decorator'), decoratorProperty: 'decoratorInterfaceDoc' },
9+
{ nameTemplate: _.template('${name}Metadata'), decoratorProperty: 'metadataDoc' },
10+
{ nameTemplate: _.template('${name}MetadataType'), decoratorProperty: 'metadataInterfaceDoc' },
11+
{ nameTemplate: _.template('${name}MetadataFactory'), decoratorProperty: 'metadataFactoryDoc' }
12+
],
13+
$process: function(docs) {
14+
15+
var docsToMergeInfo = this.docsToMergeInfo;
16+
var docsToMerge = Object.create(null);
17+
18+
docs.forEach(function(doc) {
19+
20+
// find all the decorators, signified by a call to `makeDecorator(metadata)`
21+
var makeDecorator = getMakeDecoratorCall(doc);
22+
if (makeDecorator) {
23+
doc.docType = 'decorator';
24+
doc.decoratorType = makeDecorator.arguments[0].text;
25+
26+
// keep track of the docs that need to be merged into this decorator doc
27+
docsToMergeInfo.forEach(function(info) {
28+
docsToMerge[info.nameTemplate({name: doc.name})] = { decoratorDoc: doc, property: info.decoratorProperty };
29+
});
30+
}
31+
});
32+
33+
// merge the metadata docs into the decorator docs
34+
docs = docs.filter(function(doc) {
35+
if (docsToMerge[doc.name]) {
36+
var decoratorDoc = docsToMerge[doc.name].decoratorDoc;
37+
var property = docsToMerge[doc.name].property;
38+
39+
// attach this document to its decorator
40+
decoratorDoc[property] = doc;
41+
42+
// remove doc from its module doc's exports
43+
doc.moduleDoc.exports = doc.moduleDoc.exports.filter(function(exportDoc) { return exportDoc !== doc; });
44+
45+
// remove from the overall list of docs to be rendered
46+
return false;
47+
}
48+
return true;
49+
});
50+
}
51+
};
52+
};
53+
54+
function getMakeDecoratorCall(doc, type) {
55+
56+
var makeDecoratorFnName = 'make' + (type || '')+ 'Decorator';
57+
58+
var initializer = doc.exportSymbol &&
59+
doc.exportSymbol.valueDeclaration &&
60+
doc.exportSymbol.valueDeclaration.initializer;
61+
62+
if (initializer) {
63+
// There appear to be two forms of initializer:
64+
// export var Injectable: InjectableFactory = <InjectableFactory>makeDecorator(InjectableMetadata);
65+
// and
66+
// export var RouteConfig: (configs: RouteDefinition[]) => ClassDecorator = makeDecorator(RouteConfigAnnotation);
67+
// In the first case, the type assertion `<InjectableFactory>` causes the AST to contain an extra level of expression
68+
// to hold the new type of the expression.
69+
if (initializer.expression && initializer.expression.expression) {
70+
initializer = initializer.expression;
71+
}
72+
if (initializer.expression && initializer.expression.text === makeDecoratorFnName) {
73+
return initializer;
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)