dart-archive / ts2dart

ts2dart TypeScript to Dart transpiler
Apache License 2.0
179 stars 61 forks source link

Rewriting annotation links #237

Open mhevery opened 9 years ago

mhevery commented 9 years ago

In Angular documentation we often write: See {@link Component} Which generates a link to: <a href='/angular2/angular2.api/Component'><code>Component</code>. But this is not quite right. It should generate a link to <a href='/angular2/angular2.api/ComponentAnnotation'><code>Component</code>. No we could just change the source to say See {@link ComponentAnnotation} but that would break the Dart documentation, since Dart does not have decorators only components.

Two solutions:

  1. Have a list of annotations which the dgeni would automatically append Annotation too. So `See {@link Component} becomes: <a href='/angular2/angular2.api/ComponentAnnotation'><code>Component</code>
  2. Have the source always say Annotation suffix and then have dgeni auto remove it in Dart and in the link. So See {@link ComponentAnnotation} becomes: <a href='/angular2/angular2.api/ComponentAnnotation'><code>Component</code> (note that we want to keep the text as Component in both cases)

Solution no. 1: (Preffered)

Algorithm

  1. Detect if a symbol is in a set of annotations: Component, View, Directive, Query, Attribute, Injectable
  2. If it is annotation, then generate URL to: <a href='/angular2/angular2.api/FooAnnotation'><code>Foo</code>

Solution no. 2 is simpler to implement, but requires both ts2dart and dgeni collaboration, so I don't think we should do it.

Algorithm

  1. Docs always say: {@link FooAnnotation}
  2. Dgeni generates: <a href='/angular2/angular2.api/FooAnnotation'><code>Foo</code> where
  3. it always strips out Annotation suffix in the title.
  4. strips out Annotation suffix in the URL only for Dart generation
petebacondarwin commented 9 years ago

Docs in dgeni can have aliases that are used in link matching. I think it will be enough to add the name stripped of the Annotation postfix as alias for ea check of those.

E.g.

id: 'ComponentAnnotation',
aliases: ['ComponentAnnotation', 'Component']