Skip to content

Commit

Permalink
feat(app): link to Angular types
Browse files Browse the repository at this point in the history
  • Loading branch information
vogloblinsky committed Jan 10, 2017
1 parent 16a884e commit 0b33f74
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
29 changes: 26 additions & 3 deletions src/app/engines/dependencies.engine.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as _ from 'lodash';

import { finderInAngularAPIs } from '../../utils/angular-api';

class DependenciesEngine {
private static _instance:DependenciesEngine = new DependenciesEngine();
rawData: Object;
Expand Down Expand Up @@ -33,10 +35,31 @@ class DependenciesEngine {
this.classes = _.sortBy(this.rawData.classes, ['name']);
}
find(type: string) {
let finder = function(data) {
return _.find(data, function(o) {return type.indexOf(o.name) !== -1;}) || _.find(data, function(o) { return type.indexOf(o.name) !== -1;});
let finderInCompodocDependencies = function(data) {
let _result = {
source: 'internal',
data: null
},
i = 0,
len = data.length;
for (i; i<len; i++) {
if (type.indexOf(data[i].name) !== -1) {
_result.data = data[i]
}
}
return _result;
},
resultInCompodocInjectables = finderInCompodocDependencies(this.injectables),
resultInCompodocClasses = finderInCompodocDependencies(this.classes),
resultInAngularAPIs = finderInAngularAPIs(type)

if (resultInCompodocInjectables.data !== null) {
return resultInCompodocInjectables
} else if (resultInCompodocClasses.data !== null) {
return resultInCompodocClasses
} else if (resultInAngularAPIs.data !== null) {
return resultInAngularAPIs
}
return finder(this.injectables) || finder(this.classes);
}
getModules() {
return this.modules;
Expand Down
12 changes: 9 additions & 3 deletions src/app/engines/html.engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,17 @@ export class HtmlEngine {
var _result = $dependenciesEngine.find(name);
if (_result) {
this.type = {
path: _result.type,
name: _result.name,
raw: name
}
if (_result.type === 'class') this.type.path = 'classe';
if (_result.source === 'internal') {
if (_result.data.type === 'class') _result.data.type = 'classe';
this.type.href = './' + _result.data.type + 's/' + _result.data.name + '.html';
this.type.target = '_self';
} else {
this.type.href = 'https://angular.io/docs/ts/latest/api/' + _result.data.path;
this.type.target = '_blank';
}

return options.fn(this);
} else {
return options.inverse(this);
Expand Down
2 changes: 1 addition & 1 deletion src/templates/partials/link-type.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{#linkType type}}
<code><a href="./{{type.path}}s/{{type.name}}.html" >{{type.raw}}</a></code>
<code><a href="{{type.href}}" target="{{type.target}}" >{{type.raw}}</a></code>
{{else}}
<code>{{type}}</code>
{{/linkType}}
22 changes: 22 additions & 0 deletions src/utils/angular-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as _ from 'lodash';

let AngularAPIs = require('../src/data/api-list.json');

export function finderInAngularAPIs(type: string) {
let _result = {
source: 'external',
data: null
};

_.forEach(AngularAPIs, function(angularModuleAPIs, angularModule) {
let i = 0,
len = angularModuleAPIs.length;
for (i; i<len; i++) {
if (angularModuleAPIs[i].title === type) {
_result.data = angularModuleAPIs[i]
}
}
});

return _result;
}

0 comments on commit 0b33f74

Please sign in to comment.