From 13878efca75a5c45f07ca06d42f8e030dd6693c4 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 8 Sep 2016 23:09:55 +0100 Subject: [PATCH] api-builder: show metadata details on decorator docs --- .../templates/decorator.template.html | 28 ++++++++++++++++--- .../processors/mergeDecoratorDocs.js | 14 +++++++++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/tools/api-builder/angular.io-package/templates/decorator.template.html b/tools/api-builder/angular.io-package/templates/decorator.template.html index c055039527..1303ef9cd9 100644 --- a/tools/api-builder/angular.io-package/templates/decorator.template.html +++ b/tools/api-builder/angular.io-package/templates/decorator.template.html @@ -15,16 +15,36 @@ include {$ relativePath(doc.path, '_util-fns') $} div(layout="row" layout-xs="column" class="row-margin ng-cloak") div(flex="20" flex-xs="100") - h2(class="h2-api-docs") Variable Export + h2(class="h2-api-docs") Description div(class="code-links" flex="80" flex-xs="100") - pre.prettyprint.no-bg - code. - export {$ doc.name $}(options : {@link {$ doc.decoratorType $} {$ doc.decoratorType | escape $}}){$ params.returnType(doc.returnType) $} :marked {%- if not doc.notYetDocumented %} {$ doc.description | indentForMarkdown(6) | trimBlankLines $} {% endif %} +{% if doc.metadataDoc and doc.metadataDoc.members.length %} +div(layout="row" layout-xs="column" class="metadata" class="row-margin ng-cloak") + div(flex="20" flex-xs="100") + h2(class="h2-api-docs") Metadata Properties + div(class="code-links" flex="80" flex-xs="100") + {% for metadata in doc.metadataDoc.members %}{% if not metadata.internal %} + a(name="{$ metadata.name $}-anchor" class="anchor-offset") + pre(class="prettyprint no-bg" ng-class="{ 'anchor-focused': appCtrl.isApiDocMemberFocused('{$ metadata.name $}') }") + code(class="api-doc-code"). + {$ metadata.name $}{$ params.paramList(metadata.parameters) | indent(8, false) | trim $}{$ params.returnType(metadata.returnType) $} + + :marked + {%- if not metadata.notYetDocumented %} +{$ metadata.description | indentForMarkdown(6) | replace('### Example', '') | replace('## Example', '') | replace('# Example', '') | trimBlankLines $} + {% endif -%} + + {% if not loop.last %} + .hr(class="hr-margin") + {% endif %} + + {% endif %}{% endfor %} +{% endif %} + p.location-badge. exported from {@link {$ doc.moduleDoc.id $} {$doc.moduleDoc.id $} } defined in {$ github.githubViewLink(doc) $} diff --git a/tools/api-builder/docs-package/processors/mergeDecoratorDocs.js b/tools/api-builder/docs-package/processors/mergeDecoratorDocs.js index dcde64b665..83c9d40d83 100644 --- a/tools/api-builder/docs-package/processors/mergeDecoratorDocs.js +++ b/tools/api-builder/docs-package/processors/mergeDecoratorDocs.js @@ -6,7 +6,7 @@ module.exports = function mergeDecoratorDocs() { $runBefore: ['docs-processed'], docsToMergeInfo: [ { nameTemplate: _.template('${name}Decorator'), decoratorProperty: 'decoratorInterfaceDoc' }, - { nameTemplate: _.template('${name}Metadata'), decoratorProperty: 'metadataDoc' }, + { nameTemplate: _.template('${name}Metadata'), decoratorProperty: 'metadataDoc', useFields: ['howToUse', 'whatItDoes'] }, { nameTemplate: _.template('${name}MetadataType'), decoratorProperty: 'metadataInterfaceDoc' }, { nameTemplate: _.template('${name}MetadataFactory'), decoratorProperty: 'metadataFactoryDoc' } ], @@ -21,7 +21,10 @@ module.exports = function mergeDecoratorDocs() { var makeDecorator = getMakeDecoratorCall(doc); if (makeDecorator) { doc.docType = 'decorator'; + // get the type of the decorator metadata doc.decoratorType = makeDecorator.arguments[0].text; + // clear the symbol type named (e.g. ComponentMetadataFactory) since it is not needed + doc.symbolTypeName = undefined; // keep track of the docs that need to be merged into this decorator doc docsToMergeInfo.forEach(function(info) { @@ -35,13 +38,22 @@ module.exports = function mergeDecoratorDocs() { if (docsToMerge[doc.name]) { var decoratorDoc = docsToMerge[doc.name].decoratorDoc; var property = docsToMerge[doc.name].property; + var useFields = docsToMerge[doc.name].useFields; // attach this document to its decorator decoratorDoc[property] = doc; + // Copy over fields from the merged doc if specified + if (useFields) { + useFields.forEach(function(field) { + decoratorDoc[field] = doc[field]; + }); + } + // remove doc from its module doc's exports doc.moduleDoc.exports = doc.moduleDoc.exports.filter(function(exportDoc) { return exportDoc !== doc; }); + // remove from the overall list of docs to be rendered return false; }