UNPKG

2.69 kBPlain TextView Raw
1import { IHtmlEngineHelper, IHandlebarsOptions } from './html-engine-helper.interface';
2import DependenciesEngine from '../dependencies.engine';
3
4export class ElementAloneHelper implements IHtmlEngineHelper {
5 constructor() {}
6
7 public helperFunc(context: any, elements, elementType: string, options: IHandlebarsOptions) {
8 let alones = [];
9 let modules = DependenciesEngine.modules;
10
11 elements.forEach(element => {
12 let foundInOneModule = false;
13 modules.forEach(module => {
14 module.declarations.forEach(declaration => {
15 if (declaration.id === element.id) {
16 foundInOneModule = true;
17 }
18 if (declaration.file === element.file) {
19 foundInOneModule = true;
20 }
21 });
22 module.bootstrap.forEach(boostrapedElement => {
23 if (boostrapedElement.id === element.id) {
24 foundInOneModule = true;
25 }
26 if (boostrapedElement.file === element.file) {
27 foundInOneModule = true;
28 }
29 });
30 module.controllers.forEach(controller => {
31 if (controller.id === element.id) {
32 foundInOneModule = true;
33 }
34 if (controller.file === element.file) {
35 foundInOneModule = true;
36 }
37 });
38 module.providers.forEach(provider => {
39 if (provider.id === element.id) {
40 foundInOneModule = true;
41 }
42 if (provider.file === element.file) {
43 foundInOneModule = true;
44 }
45 });
46 });
47 if (!foundInOneModule) {
48 alones.push(element);
49 }
50 });
51
52 if (alones.length > 0) {
53 switch (elementType) {
54 case 'component':
55 context.components = alones;
56 break;
57 case 'directive':
58 context.directives = alones;
59 break;
60 case 'controller':
61 context.controllers = alones;
62 break;
63 case 'injectable':
64 context.injectables = alones;
65 break;
66 case 'pipe':
67 context.pipes = alones;
68 break;
69 }
70 return options.fn(context);
71 }
72 }
73}