From 6375c5b03c3c0b99b1382934c2588ffa53aa45a2 Mon Sep 17 00:00:00 2001 From: Josh Hall Date: Thu, 20 Apr 2017 14:02:58 -0500 Subject: [PATCH 1/2] docs: Show directive selector in generated API docs * Adds method to get directive selectors to categorizor.js * Adds selectors to class.template.html Takes care of #3983 Conflicts: tools/dgeni/templates/class.template.html --- tools/dgeni/templates/class.template.html | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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) $} From ef1dbe26395465a352e718bf064de0f15d19689e Mon Sep 17 00:00:00 2001 From: Josh Hall Date: Thu, 20 Apr 2017 14:07:22 -0500 Subject: [PATCH 2/2] Recover categorizer --- tools/dgeni/processors/categorizer.js | 28 ++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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];