Skip to content

Commit b010638

Browse files
committed
feat(UI): Component, directive, pipe and injectable not linked inside a module should appear in the menu alone
fix #510
1 parent 05cd3a4 commit b010638

File tree

5 files changed

+183
-2
lines changed

5 files changed

+183
-2
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { IHtmlEngineHelper, IHandlebarsOptions } from './html-engine-helper.interface';
2+
import { extractLeadingText, splitLinkText } from '../../../utils/link-parser';
3+
import { DependenciesEngine } from '../dependencies.engine';
4+
5+
export class ElementAloneHelper implements IHtmlEngineHelper {
6+
constructor(private dependenciesEngine: DependenciesEngine) {}
7+
8+
public helperFunc(context: any, elements, elementType: string, options: IHandlebarsOptions) {
9+
let result = false;
10+
let alones = [];
11+
let modules = this.dependenciesEngine.modules;
12+
13+
elements.forEach(element => {
14+
let foundInOneModule = false;
15+
modules.forEach(module => {
16+
module.declarations.forEach(declaration => {
17+
if (declaration.name === element.name) {
18+
foundInOneModule = true;
19+
}
20+
});
21+
module.providers.forEach(provider => {
22+
if (provider.name === element.name) {
23+
foundInOneModule = true;
24+
}
25+
});
26+
});
27+
if (!foundInOneModule) {
28+
alones.push(element);
29+
}
30+
});
31+
32+
switch (elementType) {
33+
case 'component':
34+
context.components = alones;
35+
break;
36+
case 'directive':
37+
context.directives = alones;
38+
break;
39+
case 'injectable':
40+
context.injectables = alones;
41+
break;
42+
case 'pipe':
43+
context.pipes = alones;
44+
break;
45+
}
46+
47+
if (alones.length > 0) {
48+
return options.fn(context);
49+
}
50+
}
51+
}

src/app/engines/html.engine.helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { ObjectLengthHelper } from './html-engine-helpers/object-length.helper';
3232
import { ParseDescriptionHelper } from './html-engine-helpers/parse-description.helper';
3333
import { OneParameterHasHelper } from './html-engine-helpers/one-parameter-has.helper';
3434
import { ConfigurationInterface } from '../interfaces/configuration.interface';
35-
35+
import { ElementAloneHelper } from './html-engine-helpers/element-alone.helper';
3636

3737
export class HtmlEngineHelpers {
3838
public registerHelpers(
@@ -67,6 +67,7 @@ export class HtmlEngineHelpers {
6767
this.registerHelper(bars, 'objectLength', new ObjectLengthHelper());
6868
this.registerHelper(bars, 'parseDescription', new ParseDescriptionHelper(dependenciesEngine));
6969
this.registerHelper(bars, 'one-parameter-has', new OneParameterHasHelper());
70+
this.registerHelper(bars, 'element-alone', new ElementAloneHelper(dependenciesEngine));
7071
}
7172

7273
private registerHelper(bars, key: string, helper: IHtmlEngineHelper) {

src/templates/partials/menu.hbs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,64 @@
223223
</li>
224224
{{/if}}
225225

226+
{{#if components}}
227+
{{#element-alone components 'component'}}
228+
<li class="chapter">
229+
<div class="simple menu-toggler" data-toggle="collapse"
230+
{{#compare menu "===" 'normal' }}
231+
data-target="#components-links"
232+
{{else}}
233+
data-target="#xs-components-links"
234+
{{/compare}}>
235+
<span class="fa fa-fw fa-cogs"></span>
236+
<span>Components</span>
237+
<span class="fa {{#isNotToggle 'components'}}fa-angle-up{{else}}fa-angle-down{{/isNotToggle}}"></span>
238+
</div>
239+
<ul class="links collapse {{#isNotToggle 'components'}}in{{/isNotToggle}}"
240+
{{#compare menu "===" 'normal' }}
241+
id="components-links"
242+
{{else}}
243+
id="xs-components-links"
244+
{{/compare}}>
245+
{{#each components}}
246+
<li class="link">
247+
<a href="{{relativeURL ../depth 'components'}}components/{{name}}.html" {{#compare ../id "===" id }} data-type="entity-link" class="active" {{/compare}}>{{ name }}</a>
248+
</li>
249+
{{/each}}
250+
</ul>
251+
</li>
252+
{{/element-alone}}
253+
{{/if}}
254+
255+
{{#if directives}}
256+
{{#element-alone directives 'directive'}}
257+
<li class="chapter">
258+
<div class="simple menu-toggler" data-toggle="collapse"
259+
{{#compare menu "===" 'normal' }}
260+
data-target="#directives-links"
261+
{{else}}
262+
data-target="#xs-directives-links"
263+
{{/compare}}>
264+
<span class="fa fa-fw fa-code"></span>
265+
<span>Directives</span>
266+
<span class="fa {{#isNotToggle 'directives'}}fa-angle-up{{else}}fa-angle-down{{/isNotToggle}}"></span>
267+
</div>
268+
<ul class="links collapse {{#isNotToggle 'components'}}in{{/isNotToggle}}"
269+
{{#compare menu "===" 'normal' }}
270+
id="directives-links"
271+
{{else}}
272+
id="xs-directives-links"
273+
{{/compare}}>
274+
{{#each directives}}
275+
<li class="link">
276+
<a href="{{relativeURL ../depth 'directives'}}directives/{{name}}.html" {{#compare ../id "===" id }} data-type="entity-link" class="active" {{/compare}}>{{ name }}</a>
277+
</li>
278+
{{/each}}
279+
</ul>
280+
</li>
281+
{{/element-alone}}
282+
{{/if}}
283+
226284
{{#if classes}}
227285
<li class="chapter">
228286
<div class="simple menu-toggler" data-toggle="collapse"
@@ -250,6 +308,35 @@
250308
</li>
251309
{{/if}}
252310

311+
{{#if injectables}}
312+
{{#element-alone injectables 'injectable'}}
313+
<li class="chapter">
314+
<div class="simple menu-toggler" data-toggle="collapse"
315+
{{#compare menu "===" 'normal' }}
316+
data-target="#injectables-links"
317+
{{else}}
318+
data-target="#xs-injectables-links"
319+
{{/compare}}>
320+
<span class="fa fa-fw fa-long-arrow-down"></span>
321+
<span>Injectables</span>
322+
<span class="fa {{#isNotToggle 'injectables'}}fa-angle-up{{else}}fa-angle-down{{/isNotToggle}}"></span>
323+
</div>
324+
<ul class="links collapse {{#isNotToggle 'injectables'}}in{{/isNotToggle}}"
325+
{{#compare menu "===" 'normal' }}
326+
id="injectables-links"
327+
{{else}}
328+
id="xs-injectables-links"
329+
{{/compare}}>
330+
{{#each injectables}}
331+
<li class="link">
332+
<a href="{{relativeURL ../depth 'injectables'}}injectables/{{name}}.html" {{#compare ../id "===" id }} data-type="entity-link" class="active" {{/compare}}>{{ name }}</a>
333+
</li>
334+
{{/each}}
335+
</ul>
336+
</li>
337+
{{/element-alone}}
338+
{{/if}}
339+
253340
{{#if interceptors}}
254341
<li class="chapter">
255342
<div class="simple menu-toggler" data-toggle="collapse"
@@ -304,6 +391,35 @@
304391
</li>
305392
{{/if}}
306393

394+
{{#if pipes}}
395+
{{#element-alone pipes 'pipe'}}
396+
<li class="chapter">
397+
<div class="simple menu-toggler" data-toggle="collapse"
398+
{{#compare menu "===" 'normal' }}
399+
data-target="#pipes-links"
400+
{{else}}
401+
data-target="#xs-pipes-links"
402+
{{/compare}}>
403+
<span class="fa fa-fw fa-plus"></span>
404+
<span>Pipes</span>
405+
<span class="fa {{#isNotToggle 'pipes'}}fa-angle-up{{else}}fa-angle-down{{/isNotToggle}}"></span>
406+
</div>
407+
<ul class="links collapse {{#isNotToggle 'pipes'}}in{{/isNotToggle}}"
408+
{{#compare menu "===" 'normal' }}
409+
id="pipes-links"
410+
{{else}}
411+
id="xs-pipes-links"
412+
{{/compare}}>
413+
{{#each pipes}}
414+
<li class="link">
415+
<a href="{{relativeURL ../depth 'pipes'}}pipes/{{name}}.html" {{#compare ../id "===" id }} data-type="entity-link" class="active" {{/compare}}>{{ name }}</a>
416+
</li>
417+
{{/each}}
418+
</ul>
419+
</li>
420+
{{/element-alone}}
421+
{{/if}}
422+
307423
{{#if miscellaneous}}
308424
<li class="chapter">
309425
<div class="simple menu-toggler" data-toggle="collapse"

test/mocha.opts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
--colors
44
--harmony
55
--timeout 120000
6-
test/dist/cli/**/*.spec.js
6+
test/dist/cli/**/*.js

test/src/cli/cli-generation-big-app.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,4 +573,17 @@ describe('CLI simple generation - big app', () => {
573573
let file = read(distFolder + '/miscellaneous/typealiases.html');
574574
expect(file).to.contain('<code>Type&lt;TableCellRendererBase&gt; | TemplateRef&lt;any&gt;</code>');
575575
});
576+
577+
it('should support multiple union types with array', () => {
578+
let file = read(distFolder + '/components/TodoComponent.html');
579+
expect(file).to.contain('<code>(string | number)[]</code>');
580+
});
581+
582+
it('should support alone elements in their own entry menu', () => {
583+
let file = read(distFolder + '/index.html');
584+
expect(file).to.contain('<a href="./components/JigsawTab.html" >JigsawTab</a>');
585+
expect(file).to.contain('<a href="./directives/DoNothingDirective2.html" >DoNothingDirective2</a>');
586+
expect(file).to.contain('<a href="./injectables/EmitterService.html" >EmitterService</a>');
587+
expect(file).to.contain('<a href="./pipes/FirstUpperPipe2.html" >FirstUpperPipe2</a>');
588+
});
576589
});

0 commit comments

Comments
 (0)