From 659adf83dcaae2b42f03f315c7b68f3a43ef7164 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 11 Jun 2015 19:15:17 +0100 Subject: [PATCH] chore(doc-gen): move typeParams and heritage rendering to template Partially solves #2452 --- .../processors/readTypeScriptModules.js | 23 +++++++++++++------ .../templates/type-definition.template.html | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/docs/dgeni-package/processors/readTypeScriptModules.js b/docs/dgeni-package/processors/readTypeScriptModules.js index 4c2fb53586..ddbd4367f9 100644 --- a/docs/dgeni-package/processors/readTypeScriptModules.js +++ b/docs/dgeni-package/processors/readTypeScriptModules.js @@ -65,7 +65,7 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo // Generate docs for each of the export's members if (resolvedExport.flags & ts.SymbolFlags.HasMembers) { - + exportDoc.members = []; for(var memberName in resolvedExport.members) { log.silly('>>>>>> member: ' + memberName + ' from ' + exportDoc.id + ' in ' + moduleDoc.id); @@ -116,23 +116,30 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo } function createExportDoc(name, exportSymbol, moduleDoc, basePath, typeChecker) { + var typeParamString = ''; + var heritageString = ''; + exportSymbol.declarations.forEach(function(decl) { var sourceFile = ts.getSourceFileOfNode(decl); + if (decl.typeParameters) { - name = name + '<' + getText(sourceFile, decl.typeParameters) + '>'; + typeParamString = '<' + getText(sourceFile, decl.typeParameters) + '>'; } + if (decl.heritageClauses) { decl.heritageClauses.forEach(function(heritage) { + if (heritage.token == ts.SyntaxKind.ExtendsKeyword) { - name = name + " extends "; + heritageString += " extends "; heritage.types.forEach(function(typ, idx) { - name = name + (idx > 0 ? ', ' : '') + typ.getFullText(); + heritageString += (idx > 0 ? ', ' : '') + typ.getFullText(); }); } + if (heritage.token == ts.SyntaxKind.ImplementsKeyword) { - name = name + " implements "; + heritageString += " implements "; heritage.types.forEach(function(typ, idx) { - name = name + (idx > 0 ? ', ' : '') + typ.getFullText(); + heritageString += (idx > 0 ? ', ' : '') + typ.getFullText(); }); } }); @@ -143,7 +150,9 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo docType: getExportDocType(exportSymbol), name: name, id: name, - aliases: [name], + typeParams: typeParamString, + heritage: heritageString, + aliases: [name, name + typeParamString], moduleDoc: moduleDoc, content: getContent(exportSymbol), fileInfo: getFileInfo(exportSymbol, basePath), diff --git a/docs/dgeni-package/templates/type-definition.template.html b/docs/dgeni-package/templates/type-definition.template.html index 3a91d41a2c..e352540f8d 100644 --- a/docs/dgeni-package/templates/type-definition.template.html +++ b/docs/dgeni-package/templates/type-definition.template.html @@ -47,7 +47,7 @@ declare module "{$ module.id $}" { {%- if export.content -%} {$ commentBlock(export, 3) $} {%- endif %} - {$ export.docType $} {$ export.name $} + {$ export.docType $} {$ export.name $}{$ export.typeParams $}{$ export.heritage $} {%- if export.docType == 'class' or export.docType == 'interface' %} { {%- for member in export.members -%} {$ commentBlock(member, 5) $}