Skip to content

Commit 45cbc43

Browse files
chore(doc-gen): render decorators (annotations) for exported classes
Closes angular#3167 Closes angular#3221
1 parent 03fc7fe commit 45cbc43

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

docs/angular.io-package/templates/class.template.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010
:markdown
1111
{$ doc.description | indent(2, true) $}
1212

13+
{%- if doc.decorators %}
14+
.l-main-section
15+
h2 Annotations
16+
{%- for decorator in doc.decorators %}
17+
.l-sub-section
18+
h3.annotation {$ decorator.name $}
19+
pre.prettyprint
20+
code.
21+
@{$ decorator.name $}{$ paramList(decorator.arguments) | indent(8, false) $}
22+
{% endfor %}
23+
{% endif -%}
24+
25+
1326
{%- if doc.constructorDoc or doc.members.length -%}
1427
.l-main-section
1528
h2 Members

docs/docs-package/templates/class.template.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ <h1 class="class export">{$ doc.name $} <span class="type">{$ doc.docType $}</sp
99
</p>
1010
<p>{$ doc.description | marked $}</p>
1111

12+
{%- if doc.decorators %}
13+
<h2>Annotations</h2>
14+
{%- for decorator in doc.decorators %}
15+
<h3 class="annotation">@{$ decorator.name $}{$ paramList(decorator.arguments) $}</h3>
16+
{% endfor %}
17+
{% endif -%}
18+
1219
{%- if doc.constructorDoc or doc.members.length -%}
1320
<h2>Members</h2>
1421

docs/typescript-package/processors/readTypeScriptModules.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
176176
id: moduleDoc.id + '/' + name,
177177
typeParams: typeParamString,
178178
heritage: heritageString,
179+
decorators: getDecorators(exportSymbol),
179180
aliases: aliasNames,
180181
moduleDoc: moduleDoc,
181182
content: getContent(exportSymbol),
@@ -197,6 +198,7 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
197198
docType: 'member',
198199
classDoc: classDoc,
199200
name: memberSymbol.name,
201+
decorators: getDecorators(memberSymbol),
200202
content: getContent(memberSymbol),
201203
fileInfo: getFileInfo(memberSymbol, basePath),
202204
location: getLocation(memberSymbol)
@@ -240,6 +242,23 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
240242
return memberDoc;
241243
}
242244

245+
246+
function getDecorators(symbol) {
247+
var declaration = symbol.valueDeclaration || symbol.declarations[0];
248+
var sourceFile = ts.getSourceFileOfNode(declaration);
249+
250+
var decorators = declaration.decorators && declaration.decorators.map(function(decorator) {
251+
decorator = decorator.expression;
252+
return {
253+
name: decorator.expression.text,
254+
arguments: decorator.arguments && decorator.arguments.map(function(argument) {
255+
return getText(sourceFile, argument).trim();
256+
})
257+
};
258+
});
259+
return decorators;
260+
}
261+
243262
function getParameters(typeChecker, symbol) {
244263
var declaration = symbol.valueDeclaration || symbol.declarations[0];
245264
var sourceFile = ts.getSourceFileOfNode(declaration);

0 commit comments

Comments
 (0)