From 45cbc430e83ae92e679225e51b7d9445ed7e309c Mon Sep 17 00:00:00 2001
From: Peter Bacon Darwin
Date: Tue, 28 Jul 2015 11:23:01 +0100
Subject: [PATCH] chore(doc-gen): render decorators (annotations) for exported
classes
Closes #3167
Closes #3221
---
.../templates/class.template.html | 13 +++++++++++++
.../templates/class.template.html | 7 +++++++
.../processors/readTypeScriptModules.js | 19 +++++++++++++++++++
3 files changed, 39 insertions(+)
diff --git a/docs/angular.io-package/templates/class.template.html b/docs/angular.io-package/templates/class.template.html
index b17d1d3651..7ef3e573a6 100644
--- a/docs/angular.io-package/templates/class.template.html
+++ b/docs/angular.io-package/templates/class.template.html
@@ -10,6 +10,19 @@ p.location-badge.
: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
diff --git a/docs/docs-package/templates/class.template.html b/docs/docs-package/templates/class.template.html
index f97ee97b14..a015cf5e7e 100644
--- a/docs/docs-package/templates/class.template.html
+++ b/docs/docs-package/templates/class.template.html
@@ -9,6 +9,13 @@ defined in {$ githubViewLink(doc) $}
{$ doc.description | marked $}
+{%- if doc.decorators %}
+Annotations
+{%- for decorator in doc.decorators %}
+ @{$ decorator.name $}{$ paramList(decorator.arguments) $}
+{% endfor %}
+{% endif -%}
+
{%- if doc.constructorDoc or doc.members.length -%}
Members
diff --git a/docs/typescript-package/processors/readTypeScriptModules.js b/docs/typescript-package/processors/readTypeScriptModules.js
index a40e497ab0..317dec63a8 100644
--- a/docs/typescript-package/processors/readTypeScriptModules.js
+++ b/docs/typescript-package/processors/readTypeScriptModules.js
@@ -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),
@@ -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)
@@ -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);