Skip to content

Commit

Permalink
chore(doc-gen): render decorators (annotations) for exported classes
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Jul 28, 2015
1 parent 03fc7fe commit 45cbc43
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/angular.io-package/templates/class.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
:markdown
{$ doc.description | indent(2, true) $}

{%- if doc.decorators %}
.l-main-section
h2 Annotations
{%- for decorator in doc.decorators %}
.l-sub-section
h3.annotation {$ decorator.name $}
pre.prettyprint
code.
@{$ decorator.name $}{$ paramList(decorator.arguments) | indent(8, false) $}
{% endfor %}
{% endif -%}


{%- if doc.constructorDoc or doc.members.length -%}
.l-main-section
h2 Members
Expand Down
7 changes: 7 additions & 0 deletions docs/docs-package/templates/class.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ <h1 class="class export">{$ doc.name $} <span class="type">{$ doc.docType $}</sp
</p>
<p>{$ doc.description | marked $}</p>

{%- if doc.decorators %}
<h2>Annotations</h2>
{%- for decorator in doc.decorators %}
<h3 class="annotation">@{$ decorator.name $}{$ paramList(decorator.arguments) $}</h3>
{% endfor %}
{% endif -%}

{%- if doc.constructorDoc or doc.members.length -%}
<h2>Members</h2>

Expand Down
19 changes: 19 additions & 0 deletions docs/typescript-package/processors/readTypeScriptModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
id: moduleDoc.id + '/' + name,
typeParams: typeParamString,
heritage: heritageString,
decorators: getDecorators(exportSymbol),
aliases: aliasNames,
moduleDoc: moduleDoc,
content: getContent(exportSymbol),
Expand All @@ -197,6 +198,7 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
docType: 'member',
classDoc: classDoc,
name: memberSymbol.name,
decorators: getDecorators(memberSymbol),
content: getContent(memberSymbol),
fileInfo: getFileInfo(memberSymbol, basePath),
location: getLocation(memberSymbol)
Expand Down Expand Up @@ -240,6 +242,23 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
return memberDoc;
}


function getDecorators(symbol) {
var declaration = symbol.valueDeclaration || symbol.declarations[0];
var sourceFile = ts.getSourceFileOfNode(declaration);

var decorators = declaration.decorators && declaration.decorators.map(function(decorator) {
decorator = decorator.expression;
return {
name: decorator.expression.text,
arguments: decorator.arguments && decorator.arguments.map(function(argument) {
return getText(sourceFile, argument).trim();
})
};
});
return decorators;
}

function getParameters(typeChecker, symbol) {
var declaration = symbol.valueDeclaration || symbol.declarations[0];
var sourceFile = ts.getSourceFileOfNode(declaration);
Expand Down

0 comments on commit 45cbc43

Please sign in to comment.