Skip to content

Commit 0b33f74

Browse files
committed
feat(app): link to Angular types
#57
1 parent 16a884e commit 0b33f74

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

src/app/engines/dependencies.engine.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as _ from 'lodash';
22

3+
import { finderInAngularAPIs } from '../../utils/angular-api';
4+
35
class DependenciesEngine {
46
private static _instance:DependenciesEngine = new DependenciesEngine();
57
rawData: Object;
@@ -33,10 +35,31 @@ class DependenciesEngine {
3335
this.classes = _.sortBy(this.rawData.classes, ['name']);
3436
}
3537
find(type: string) {
36-
let finder = function(data) {
37-
return _.find(data, function(o) {return type.indexOf(o.name) !== -1;}) || _.find(data, function(o) { return type.indexOf(o.name) !== -1;});
38+
let finderInCompodocDependencies = function(data) {
39+
let _result = {
40+
source: 'internal',
41+
data: null
42+
},
43+
i = 0,
44+
len = data.length;
45+
for (i; i<len; i++) {
46+
if (type.indexOf(data[i].name) !== -1) {
47+
_result.data = data[i]
48+
}
49+
}
50+
return _result;
51+
},
52+
resultInCompodocInjectables = finderInCompodocDependencies(this.injectables),
53+
resultInCompodocClasses = finderInCompodocDependencies(this.classes),
54+
resultInAngularAPIs = finderInAngularAPIs(type)
55+
56+
if (resultInCompodocInjectables.data !== null) {
57+
return resultInCompodocInjectables
58+
} else if (resultInCompodocClasses.data !== null) {
59+
return resultInCompodocClasses
60+
} else if (resultInAngularAPIs.data !== null) {
61+
return resultInAngularAPIs
3862
}
39-
return finder(this.injectables) || finder(this.classes);
4063
}
4164
getModules() {
4265
return this.modules;

src/app/engines/html.engine.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,17 @@ export class HtmlEngine {
102102
var _result = $dependenciesEngine.find(name);
103103
if (_result) {
104104
this.type = {
105-
path: _result.type,
106-
name: _result.name,
107105
raw: name
108106
}
109-
if (_result.type === 'class') this.type.path = 'classe';
107+
if (_result.source === 'internal') {
108+
if (_result.data.type === 'class') _result.data.type = 'classe';
109+
this.type.href = './' + _result.data.type + 's/' + _result.data.name + '.html';
110+
this.type.target = '_self';
111+
} else {
112+
this.type.href = 'https://angular.io/docs/ts/latest/api/' + _result.data.path;
113+
this.type.target = '_blank';
114+
}
115+
110116
return options.fn(this);
111117
} else {
112118
return options.inverse(this);

src/templates/partials/link-type.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{#linkType type}}
2-
<code><a href="./{{type.path}}s/{{type.name}}.html" >{{type.raw}}</a></code>
2+
<code><a href="{{type.href}}" target="{{type.target}}" >{{type.raw}}</a></code>
33
{{else}}
44
<code>{{type}}</code>
55
{{/linkType}}

src/utils/angular-api.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as _ from 'lodash';
2+
3+
let AngularAPIs = require('../src/data/api-list.json');
4+
5+
export function finderInAngularAPIs(type: string) {
6+
let _result = {
7+
source: 'external',
8+
data: null
9+
};
10+
11+
_.forEach(AngularAPIs, function(angularModuleAPIs, angularModule) {
12+
let i = 0,
13+
len = angularModuleAPIs.length;
14+
for (i; i<len; i++) {
15+
if (angularModuleAPIs[i].title === type) {
16+
_result.data = angularModuleAPIs[i]
17+
}
18+
}
19+
});
20+
21+
return _result;
22+
}

0 commit comments

Comments
 (0)