diff --git a/docs/dgeni-package/index.js b/docs/dgeni-package/index.js index 9c9f326a26..1efe1b8d98 100644 --- a/docs/dgeni-package/index.js +++ b/docs/dgeni-package/index.js @@ -38,6 +38,7 @@ module.exports = new Package('angular', [jsdocPackage, nunjucksPackage, linksPac .processor(require('./processors/generateNavigationDoc')) .processor(require('./processors/extractTitleFromGuides')) .processor(require('./processors/createOverviewDump')) +.processor(require('./processors/createTypeDefinitionFile')) // Configure the log service diff --git a/docs/dgeni-package/processors/createTypeDefinitionFile.js b/docs/dgeni-package/processors/createTypeDefinitionFile.js new file mode 100644 index 0000000000..95b98f1df4 --- /dev/null +++ b/docs/dgeni-package/processors/createTypeDefinitionFile.js @@ -0,0 +1,24 @@ +var _ = require('lodash'); + +module.exports = function createTypeDefinitionFile() { + + return { + $runAfter: ['processing-docs'], + $runBefore: ['docs-processed'], + $process: function(docs) { + var typeDefDoc = { + id: 'type-definition', + aliases: ['type-definition'], + path: 'type-definition', + outputPath: 'angular2.d.ts', + modules: [] + }; + _.forEach(docs, function(doc) { + if ( doc.docType === 'module' ) { + typeDefDoc.modules.push(doc); + } + }); + docs.push(typeDefDoc); + } + }; +}; \ No newline at end of file diff --git a/docs/dgeni-package/processors/readTypeScriptModules.js b/docs/dgeni-package/processors/readTypeScriptModules.js index 068215ba22..834c545608 100644 --- a/docs/dgeni-package/processors/readTypeScriptModules.js +++ b/docs/dgeni-package/processors/readTypeScriptModules.js @@ -127,6 +127,8 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo }; if(exportSymbol.flags & ts.SymbolFlags.Function) { exportDoc.parameters = getParameters(typeChecker, exportSymbol); + } + if(exportSymbol.flags & ts.SymbolFlags.Value) { exportDoc.returnType = getReturnType(typeChecker, exportSymbol); } return exportDoc; @@ -148,7 +150,6 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo // with the `params` property that will be updated by dgeni reading the // `@param` tags from the docs memberDoc.parameters = getParameters(typeChecker, memberSymbol); - memberDoc.returnType = getReturnType(typeChecker, memberSymbol); } if (memberSymbol.flags & ts.SymbolFlags.Constructor) { @@ -156,6 +157,10 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo memberDoc.name = 'constructor'; } + if(memberSymbol.flags & ts.SymbolFlags.Value) { + memberDoc.returnType = getReturnType(typeChecker, memberSymbol); + } + return memberDoc; } diff --git a/docs/dgeni-package/templates/type-definition.template.html b/docs/dgeni-package/templates/type-definition.template.html new file mode 100644 index 0000000000..aeeec36c4a --- /dev/null +++ b/docs/dgeni-package/templates/type-definition.template.html @@ -0,0 +1,37 @@ +{%- macro commentBlock(doc, level) -%} +{%- if doc.content | trim %} +{% if level > 1 %}{$ '/**' | indent(level-1, true) | replace(r/\n$/, "") $}{% else %}/**{% endif %} +{$ doc.content | replace(r/^/gm, "* ") | indent(level, true) | replace(r/\n$/, "") $} +{$ '*/' | indent(level, true) | replace(r/\n$/, "") $}{% endif -%} +{%- endmacro -%} + +// Type definitions for Angular v2.0.0-alpha.22 +// Project: http://angular.io/ +// Definitions by: angular team +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +{% for module in doc.modules %} +{$ commentBlock(module, 1) $} +declare module "{$ module.id $}" { + + {% for export in module.exports -%} + {$ commentBlock(export, 3) $} + {$ export.docType $} {$ export.name $} + {%- if export.docType == 'class' or export.docType == 'interface' %} { + {% for member in export.members -%} + {$ commentBlock(member, 5) $} + {$ member.name $} + {%- if member.parameters %}({% for param in member.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}){%- endif %} + {%- if member.returnType %} : {$ member.returnType $} {% endif %} + {% endfor %} + } + {%- else -%} + {% if export.parameters %}({% for param in export.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}){%- endif %} + {%- if export.returnType %} : {$ export.returnType $} {% endif -%} + {% endif %} + + {% endfor %} +} + +{% endfor %} +