diff --git a/tools/dgeni/processors/categorizer.js b/tools/dgeni/processors/categorizer.js index b515e5a026c5..3d6da71a05ac 100644 --- a/tools/dgeni/processors/categorizer.js +++ b/tools/dgeni/processors/categorizer.js @@ -1,3 +1,16 @@ +/** + * We want to avoid emitting selectors that are deprecated but don't have a way to mark + * them as such in the source code. Thus, we maintain a separate blacklist of selectors + * that should not be emitted in the documentation. + */ +const SELECTOR_BLACKLIST = new Set([ + '[portal]', + '[portalHost]', + 'textarea[md-autosize]', + '[overlay-origin]', + '[connected-overlay]', +]); + /** * Processor to add properties to docs objects. * @@ -29,11 +42,12 @@ module.exports = function categorizer() { classDoc.properties.forEach(doc => decoratePropertyDoc(doc)); decoratePublicDoc(classDoc); - + // Categorize the current visited classDoc into its Angular type. if (isDirective(classDoc)) { classDoc.isDirective = true; classDoc.directiveExportAs = getDirectiveExportAs(classDoc); + classDoc.directiveSelectors = getDirectiveSelectors(classDoc); } else if (isService(classDoc)) { classDoc.isService = true; } else if (isNgModule(classDoc)) { @@ -171,6 +185,18 @@ function getDirectiveOutputAlias(doc) { return isDirectiveOutput(doc) ? doc.decorators.find(d => d.name == 'Output').arguments[0] : ''; } +function getDirectiveSelectors(classDoc) { + let metadata = classDoc.decorators + .find(d => d.name === 'Component' || d.name === 'Directive').arguments[0]; + + let selectorMatches = /selector\s*:\s*(?:"|')([^']*?)(?:"|')/g.exec(metadata); + selectorMatches = selectorMatches && selectorMatches[1]; + + return selectorMatches ? selectorMatches.split(/\s*,\s*/) + .filter(s => s !== '' && !s.includes('mat') && !SELECTOR_BLACKLIST.has(s)) + : selectorMatches; +} + function getDirectiveExportAs(doc) { let metadata = doc.decorators .find(d => d.name === 'Component' || d.name === 'Directive').arguments[0]; diff --git a/tools/dgeni/templates/class.template.html b/tools/dgeni/templates/class.template.html index f23c5d4e4d86..c9d03bf8348a 100644 --- a/tools/dgeni/templates/class.template.html +++ b/tools/dgeni/templates/class.template.html @@ -3,6 +3,15 @@

{$ class.description $}

+{%- if class.directiveSelectors -%} +
+ selector: + {% for s in class.directiveSelectors %} + {$ s $} + {% endfor %} +
+{%- endif -%} + {%- if class.directiveExportAs -%} Exported as: {$ class.directiveExportAs $} @@ -10,7 +19,7 @@

{%- if class.isDeprecated -%}
Deprecated
-{%- endif -%} +{%- endif -%} {$ propertyList(class.properties) $}