Skip to content

Show directive selector in generated API docs #3983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jelbourn opened this issue Apr 8, 2017 · 5 comments
Closed

Show directive selector in generated API docs #3983

jelbourn opened this issue Apr 8, 2017 · 5 comments
Labels
area: dev-infra Issue related to internal project infrastructure docs This issue is related to documentation feature This issue represents a new feature or feature request rather than a bug or bug fix help wanted The team would appreciate a PR from the community to address this issue

Comments

@jelbourn
Copy link
Member

jelbourn commented Apr 8, 2017

The API docs do not currently show the selector for directives. We should surface this information. This will involve collecting the information in categorizer.js and then adding it to the class.template.html.

Only the md- selectors should be shown (not the mat- selectors).

The follow-up would be styling the information on material.angular.io.

@jelbourn jelbourn added docs This issue is related to documentation help wanted The team would appreciate a PR from the community to address this issue area: dev-infra Issue related to internal project infrastructure feature This issue represents a new feature or feature request rather than a bug or bug fix labels Apr 8, 2017
@jbh
Copy link

jbh commented Apr 14, 2017

Is there a certain way this should be formatted/templated within class.template.html? Similar to propertyList and methodList or something simpler within class.template.html itself? At the moment, I have my fork grabbing the selectors from the classDoc object by traversing the decorators and parsing the arguments. This leaves me with an array of string selector names. That might not need to be as verbose as the methodList and propertyList.

// categorizer.js
/**
 * Function that walks through all inherited docs and collects public selectors.
 * Only the md- selectors should be shown (not the mat- selectors).
 */
function resolveMdSelectors(classDoc) {
  let onlyMdSelectors = [];

  classDoc.decorators.forEach(function(decorator) {
    decorator.arguments.forEach(function(argument) {
      // Split the stringified object by newline to get each part
      let argParts = argument.split('\n');
      // Get the selector line with `selector: \'` in order to ignore such things as `{selector: MAT_ELEMENTS_SELECTOR}`
      let selectorLine = argParts.filter(argPart => argPart.indexOf('selector: \'') !== -1)[0];

      if (selectorLine) {
        // Set the bookending ticks for grabbing the selectors
        let firstTick = selectorLine.indexOf('\'') + 1;
        let lastTick = selectorLine.indexOf('\'', firstTick);
        // Get the selectors.
        let selectors = selectorLine.substring(firstTick, lastTick).replace(/ /g, '').split(',');
        onlyMdSelectors = selectors.filter(selector => selector.indexOf('md') !== -1);
      }
    });
  });

  return onlyMdSelectors;
}

If there's a better way of getting the selectors, I'd be happy to clean that up.

@jelbourn
Copy link
Member Author

@jbh check out the existing getDirectiveExportAs function which does something similar.

As for how to show this information in the template- I was thinking it should go directly underneath the class name for any @Directive or @Component (wrapped in an element with its own class).

Thinking about this more, we should also have a blacklist for deprecated selectors. This would include, for now:
[portal], [portalHost], textarea[md-autosize], [overlay-origin], [connected-overlay]

@jbh
Copy link

jbh commented Apr 17, 2017

@jelbourn To clarify the blacklist, do you mean a blacklist constant to be maintained withincategorizer.js? Anything within this blacklist would be excluded from the selector list?

Also, when you said

Only the md- selectors should be shown (not the mat- selectors).

Did you mean to just exclude mat- selectors, or did you mean to only include selectors with md in it period?

@jelbourn
Copy link
Member Author

@jbh yeah, I would just put the blacklist there for now. Anything in that list would be ignored when decorating the doc object.

For prefixes, yes- I meant anything with the mat prefix should be omitted.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: dev-infra Issue related to internal project infrastructure docs This issue is related to documentation feature This issue represents a new feature or feature request rather than a bug or bug fix help wanted The team would appreciate a PR from the community to address this issue
Projects
None yet
Development

No branches or pull requests

3 participants