1 | import { IHtmlEngineHelper, IHandlebarsOptions } from './html-engine-helper.interface';
|
2 | import DependenciesEngine from '../dependencies.engine';
|
3 | import AngularVersionUtil from '../../../utils/angular-version.util';
|
4 | import BasicTypeUtil from '../../../utils/basic-type.util';
|
5 | import Configuration from '../../configuration';
|
6 |
|
7 | export class LinkTypeHelper implements IHtmlEngineHelper {
|
8 | constructor() {}
|
9 |
|
10 | public helperFunc(context: any, name: string, options: IHandlebarsOptions) {
|
11 | let _result = DependenciesEngine.find(name);
|
12 | let angularDocPrefix = AngularVersionUtil.prefixOfficialDoc(
|
13 | Configuration.mainData.angularVersion
|
14 | );
|
15 | if (_result) {
|
16 | context.type = {
|
17 | raw: name
|
18 | };
|
19 | if (_result.source === 'internal') {
|
20 | if (_result.data.type === 'class') {
|
21 | _result.data.type = 'classe';
|
22 | }
|
23 | context.type.href = '../' + _result.data.type + 's/' + _result.data.name + '.html';
|
24 | if (
|
25 | _result.data.type === 'miscellaneous' ||
|
26 | (_result.data.ctype && _result.data.ctype === 'miscellaneous')
|
27 | ) {
|
28 | let mainpage = '';
|
29 | switch (_result.data.subtype) {
|
30 | case 'enum':
|
31 | mainpage = 'enumerations';
|
32 | break;
|
33 | case 'function':
|
34 | mainpage = 'functions';
|
35 | break;
|
36 | case 'typealias':
|
37 | mainpage = 'typealiases';
|
38 | break;
|
39 | case 'variable':
|
40 | mainpage = 'variables';
|
41 | }
|
42 | context.type.href =
|
43 | '../' + _result.data.ctype + '/' + mainpage + '.html#' + _result.data.name;
|
44 | }
|
45 | context.type.target = '_self';
|
46 | } else {
|
47 | context.type.href = `https://${angularDocPrefix}angular.io/${_result.data.path}`;
|
48 | context.type.target = '_blank';
|
49 | }
|
50 |
|
51 | return options.fn(context);
|
52 | } else if (BasicTypeUtil.isKnownType(name)) {
|
53 | context.type = {
|
54 | raw: name
|
55 | };
|
56 | context.type.target = '_blank';
|
57 | context.type.href = BasicTypeUtil.getTypeUrl(name);
|
58 | return options.fn(context);
|
59 | } else {
|
60 | return options.inverse(context);
|
61 | }
|
62 | }
|
63 | }
|