Skip to content
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

build(aio): add metadata aliases for directives, components and pipes #19317

Merged
merged 1 commit into from Sep 25, 2017

Conversation

petebacondarwin
Copy link
Member

This change will enable people to link to the API docs via their selectors
or names, as used in a template.

Since the selectors can be quite complex we are not able to get 100%
accuracy.

Closes #16787

@petebacondarwin petebacondarwin added comp: aio action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Sep 21, 2017
@mary-poppins
Copy link

You can preview a1469bb at https://pr19317-a1469bb.ngbuilds.io/.

@wardbell
Copy link
Contributor

Nice touch!

@mary-poppins
Copy link

You can preview a612155 at https://pr19317-a612155.ngbuilds.io/.

}
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this new line should be moved below stripQuotes() 😛


function extractSelectors(selectors) {
if (selectors) {
return stripQuotes(selectors).split(',').map(selector => selector.replace(/^\W+(\w+)\W+$/, '$1'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is intentional, but the current implementation will return selector that don't match the RegExp unchanged. E.g. foo:not(bar) will be returned as an alias and .foo will be converted to foo.

Most of the directives will not be affected as they use simple selectors, but I think it would be safer to only include aliases for selectors that match the RegExp.

Speaking of the RegExp, \w+ will not match - (it will only match letters, numbers and _ iirc).
I assume this was not intentional either? It seems useful to be able to catch selectors with - (even if there aren't (m)any atm).

For example, the current implementation will not match [my-directive].

So, I would expect something along the lines:

const re = /^\W*([\w-]+)\W*$/;
return stripQuotes(selectors).
  split(',').
  map(s => re.exec(s)).
  filter(m => m).
  map(m => m[1]);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex was designed intentionally.

Most of the more complex selectors require CSS parsing on both sides of the matching (i.e. here and also in the autolinker), so I didn't try too hard to make the parser here too clever. It seemed more sensible to just pass through unmatched selectors, so that they were at least available to people if they wanted to create a manual inline link e.g. {@link foo:not(bar)}.

The way that auto-linking works, it only tries to match whole words in source code snippets, so anything with a symbol in it is never going to be auto-linked anyway, even if there was an alias for it.

But I guess that since people might want to create manual links then we might benefit from a more lenient approach on the regex.

expect(processor.$runBefore).toEqual(['computing-ids']);
});

it('should add new aliases for directives and components', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and pipes 😃

{ docType: 'enum', name: 'MyEnum', aliases: ['MyEnum'] },
{ docType: 'function', name: 'myFunction', aliases: ['myFunction'] },
{ docType: 'pipe', name: 'MyPipe', aliases: ['MyPipe'], pipeOptions: { name: '\'myPipe\'' } },
{ docType: 'directive', name: 'MyDirective', aliases: ['MyDirective'], directiveOptions: { selector: '\'my-directive,[myDirective]\'' } },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing tests for [my-directive] and double quotes 😃

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double quotes never appear in these fields, so the strip quotes is too complicated, but I don't feel the need to test something that never occurs 🙀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the only reason you added support for both ' and " was to show off you improving RegExp skills 😛

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improving! I am honoured :-)
Or perhaps I just cut and pasted it from another part of the code :shame:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Judiciously copy-pasting is a skill to be proud, not ashamed, of 😛

@gkalpak
Copy link
Member

gkalpak commented Sep 22, 2017

Forgot to mention, this will be a-w-e-s-o-m-e 💃 💯

This change will enable people to link to the API docs via their selectors
or names, as used in a template.

Since the selectors can be quite complex we are not able to get 100%
accuracy.

Closes angular#16787
@petebacondarwin
Copy link
Member Author

@gkalpak PTAL

@mary-poppins
Copy link

You can preview 01498d9 at https://pr19317-01498d9.ngbuilds.io/.

@gkalpak gkalpak added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 22, 2017
@petebacondarwin petebacondarwin moved this from REVIEW to MERGE in docs-infra Sep 22, 2017
@vicb vicb merged commit adb0b76 into angular:master Sep 25, 2017
vicb pushed a commit that referenced this pull request Sep 25, 2017
…#19317)

This change will enable people to link to the API docs via their selectors
or names, as used in a template.

Since the selectors can be quite complex we are not able to get 100%
accuracy.

Closes #16787
@petebacondarwin petebacondarwin removed this from MERGE in docs-infra Sep 25, 2017
@petebacondarwin petebacondarwin deleted the aio-autolink-selectors branch September 28, 2017 12:19
@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 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aio: autolinking code blocks improvements
6 participants