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

Commit ec72c80

Browse files
vsavkinnaomiblack
authored andcommitted
fix: merge the decorator data with the symbol
1 parent 053ecc2 commit ec72c80

File tree

1 file changed

+107
-72
lines changed

1 file changed

+107
-72
lines changed

tools/api-builder/angular.io-package/processors/addJadeDataDocsProcessor.js

Lines changed: 107 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,65 @@ var titleCase = function(text) {
1919
*
2020
*/
2121

22+
23+
function processExportDoc(exportDoc) {
24+
// STABILITY STATUS
25+
// Supported tags:
26+
// @stable
27+
// @experimental
28+
// @deprecated
29+
// Default is the empty string (no badge)
30+
// Do not capitalize the strings, they are intended for use in constructing a css class from _hero.scss
31+
// and used in _hero.jade
32+
var stability = '';
33+
if (_.has(exportDoc, 'stable')) {
34+
stability = 'stable';
35+
} else if (_.has(exportDoc, 'experimental')) {
36+
stability = 'experimental';
37+
} else if (_.has(exportDoc, 'deprecated')) {
38+
stability = 'deprecated';
39+
exportDoc.showDeprecatedNotes = true;
40+
}
41+
42+
var howToUse = '';
43+
if(_.has(exportDoc, 'howToUse')) {
44+
var howToUseArray = exportDoc.tags.tags.filter(function(tag) {
45+
return tag.tagName === 'howToUse'
46+
});
47+
48+
// Remove line breaks, there should only be one tag
49+
howToUse = howToUseArray[0].description.replace(/(\r\n|\n|\r)/gm," ");
50+
}
51+
52+
var whatItDoes = '';
53+
if(_.has(exportDoc, 'whatItDoes')) {
54+
var whatItDoesArray = exportDoc.tags.tags.filter(function(tag) {
55+
return tag.tagName === 'whatItDoes'
56+
});
57+
58+
// Remove line breaks, there should only be one tag
59+
whatItDoes = whatItDoesArray[0].description.replace(/(\r\n|\n|\r)/gm," ");
60+
}
61+
62+
// SECURITY STATUS
63+
// Supported tags:
64+
// @security
65+
// Default is no security risk assessed for api
66+
var security = false;
67+
if (_.has(exportDoc, 'security')) {
68+
var securityArray = exportDoc.tags.tags.filter(function(tag) {
69+
return tag.tagName === 'security'
70+
});
71+
72+
// Remove line breaks, there should only be one tag
73+
security = securityArray[0].description.replace(/(\r\n|\n|\r)/gm," ");
74+
75+
exportDoc.showSecurityNotes = true;
76+
}
77+
78+
return {stability: stability, howToUse: howToUse, whatItDoes: whatItDoes, security: security};
79+
}
80+
2281
module.exports = function addJadeDataDocsProcessor() {
2382
return {
2483
$runAfter: ['adding-extra-docs'],
@@ -51,7 +110,7 @@ module.exports = function addJadeDataDocsProcessor() {
51110
*
52111
* Modules must be public and have content
53112
*/
54-
113+
55114
_.forEach(docs, function(doc) {
56115
if (doc.docType === 'module' && !doc.internal && doc.exports.length) {
57116
modules.push(doc);
@@ -65,83 +124,60 @@ module.exports = function addJadeDataDocsProcessor() {
65124
intro: doc.description.replace('"', '\"').replace(/\s*(\r?\n|\r)\s*/g," "),
66125
docType: 'module'
67126
}];
68-
127+
128+
var decorators = {};
129+
69130
// GET DATA FOR EACH PAGE (CLASS, VARS, FUNCTIONS)
70131
var modulePageInfo = _(doc.exports)
71132
.map(function(exportDoc) {
72-
73-
// STABILITY STATUS
74-
// Supported tags:
75-
// @stable
76-
// @experimental
77-
// @deprecated
78-
// Default is the empty string (no badge)
79-
// Do not capitalize the strings, they are intended for use in constructing a css class from _hero.scss
80-
// and used in _hero.jade
81-
var stability = '';
82-
if (_.has(exportDoc, 'stable')) {
83-
stability = 'stable';
84-
} else if (_.has(exportDoc, 'experimental')) {
85-
stability = 'experimental';
86-
} else if (_.has(exportDoc, 'deprecated')) {
87-
stability = 'deprecated';
88-
exportDoc.showDeprecatedNotes = true;
89-
}
90-
91-
var howToUse = '';
92-
if(_.has(exportDoc, 'howToUse')) {
93-
var howToUseArray = exportDoc.tags.tags.filter(function(tag) {
94-
return tag.tagName === 'howToUse'
95-
});
96-
97-
// Remove line breaks, there should only be one tag
98-
howToUse = howToUseArray[0].description.replace(/(\r\n|\n|\r)/gm," ");
99-
}
100-
101-
var whatItDoes = '';
102-
if(_.has(exportDoc, 'whatItDoes')) {
103-
var whatItDoesArray = exportDoc.tags.tags.filter(function(tag) {
104-
return tag.tagName === 'whatItDoes'
105-
});
106-
107-
// Remove line breaks, there should only be one tag
108-
whatItDoes = whatItDoesArray[0].description.replace(/(\r\n|\n|\r)/gm," ");
133+
// if it ends with "Decorator", we store it in the map
134+
// to later merge with the token
135+
if (exportDoc.name.endsWith("Decorator")) {
136+
var p = processExportDoc(exportDoc.callMember);
137+
decorators[exportDoc.name] = {
138+
stability : p.stability,
139+
howToUse : p.howToUse,
140+
whatItDoes : p.whatItDoes,
141+
security : p.security,
142+
description : exportDoc.callMember.description,
143+
docType: 'decorator'
144+
};
145+
return null;
146+
147+
} else {
148+
var p = processExportDoc(exportDoc);
149+
150+
// Data inserted into jade-data.template.html
151+
var dataDoc = {
152+
name: exportDoc.name + '-' + exportDoc.docType,
153+
title: exportDoc.name,
154+
docType: exportDoc.docType,
155+
exportDoc: exportDoc,
156+
stability: p.stability,
157+
howToUse: p.howToUse,
158+
whatItDoes: p.whatItDoes,
159+
security: p.security
160+
};
161+
162+
if (exportDoc.symbolTypeName) dataDoc.varType = titleCase(exportDoc.symbolTypeName);
163+
if (exportDoc.originalModule) dataDoc.originalModule = exportDoc.originalModule;
164+
165+
return dataDoc;
109166
}
110-
111-
// SECURITY STATUS
112-
// Supported tags:
113-
// @security
114-
// Default is no security risk assessed for api
115-
var security = false;
116-
if (_.has(exportDoc, 'security')) {
117-
var securityArray = exportDoc.tags.tags.filter(function(tag) {
118-
return tag.tagName === 'security'
119-
});
120-
121-
// Remove line breaks, there should only be one tag
122-
security = securityArray[0].description.replace(/(\r\n|\n|\r)/gm," ");
123-
124-
exportDoc.showSecurityNotes = true;
125-
}
126-
127-
// Data inserted into jade-data.template.html
128-
var dataDoc = {
129-
name: exportDoc.name + '-' + exportDoc.docType,
130-
title: exportDoc.name,
131-
docType: exportDoc.docType,
132-
exportDoc: exportDoc,
133-
stability: stability,
134-
howToUse: howToUse,
135-
whatItDoes: whatItDoes,
136-
security: security
137-
};
138-
139-
if (exportDoc.symbolTypeName) dataDoc.varType = titleCase(exportDoc.symbolTypeName);
140-
if (exportDoc.originalModule) dataDoc.originalModule = exportDoc.originalModule;
141-
return dataDoc;
142167
})
168+
.filter(function(s) { return !!s; }) // filter out all null values
143169
.sortBy('name')
144170
.value();
171+
172+
// find a matching symbol for every decorator item
173+
// and merge the data
174+
_.forEach(Object.keys(decorators), function(name) {
175+
var varToken = name.split("Decorator")[0];
176+
var c = modulePageInfo.filter(function(n) { return n.exportDoc.name === varToken; });
177+
178+
c[0].docType = decorators[name].docType;
179+
Object.assign(c[0].exportDoc, decorators[name]);
180+
});
145181

146182
doc.childPages = modulePageInfo;
147183

@@ -162,7 +198,6 @@ module.exports = function addJadeDataDocsProcessor() {
162198
}
163199
});
164200

165-
166201
return docs.concat(extraDocs);
167202
}
168203
};

0 commit comments

Comments
 (0)