Skip to content

Commit

Permalink
feat(UI): Component, directive, pipe and injectable not linked inside…
Browse files Browse the repository at this point in the history
… a module should appear in the menu alone

fix #510
  • Loading branch information
vogloblinsky committed Mar 19, 2018
1 parent 05cd3a4 commit b010638
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 2 deletions.
51 changes: 51 additions & 0 deletions src/app/engines/html-engine-helpers/element-alone.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { IHtmlEngineHelper, IHandlebarsOptions } from './html-engine-helper.interface';
import { extractLeadingText, splitLinkText } from '../../../utils/link-parser';
import { DependenciesEngine } from '../dependencies.engine';

export class ElementAloneHelper implements IHtmlEngineHelper {
constructor(private dependenciesEngine: DependenciesEngine) {}

public helperFunc(context: any, elements, elementType: string, options: IHandlebarsOptions) {
let result = false;
let alones = [];
let modules = this.dependenciesEngine.modules;

elements.forEach(element => {
let foundInOneModule = false;
modules.forEach(module => {
module.declarations.forEach(declaration => {
if (declaration.name === element.name) {
foundInOneModule = true;
}
});
module.providers.forEach(provider => {
if (provider.name === element.name) {
foundInOneModule = true;
}
});
});
if (!foundInOneModule) {
alones.push(element);
}
});

switch (elementType) {
case 'component':
context.components = alones;
break;
case 'directive':
context.directives = alones;
break;
case 'injectable':
context.injectables = alones;
break;
case 'pipe':
context.pipes = alones;
break;
}

if (alones.length > 0) {
return options.fn(context);
}
}
}
3 changes: 2 additions & 1 deletion src/app/engines/html.engine.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { ObjectLengthHelper } from './html-engine-helpers/object-length.helper';
import { ParseDescriptionHelper } from './html-engine-helpers/parse-description.helper';
import { OneParameterHasHelper } from './html-engine-helpers/one-parameter-has.helper';
import { ConfigurationInterface } from '../interfaces/configuration.interface';

import { ElementAloneHelper } from './html-engine-helpers/element-alone.helper';

export class HtmlEngineHelpers {
public registerHelpers(
Expand Down Expand Up @@ -67,6 +67,7 @@ export class HtmlEngineHelpers {
this.registerHelper(bars, 'objectLength', new ObjectLengthHelper());
this.registerHelper(bars, 'parseDescription', new ParseDescriptionHelper(dependenciesEngine));
this.registerHelper(bars, 'one-parameter-has', new OneParameterHasHelper());
this.registerHelper(bars, 'element-alone', new ElementAloneHelper(dependenciesEngine));
}

private registerHelper(bars, key: string, helper: IHtmlEngineHelper) {
Expand Down
116 changes: 116 additions & 0 deletions src/templates/partials/menu.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,64 @@
</li>
{{/if}}

{{#if components}}
{{#element-alone components 'component'}}
<li class="chapter">
<div class="simple menu-toggler" data-toggle="collapse"
{{#compare menu "===" 'normal' }}
data-target="#components-links"
{{else}}
data-target="#xs-components-links"
{{/compare}}>
<span class="fa fa-fw fa-cogs"></span>
<span>Components</span>
<span class="fa {{#isNotToggle 'components'}}fa-angle-up{{else}}fa-angle-down{{/isNotToggle}}"></span>
</div>
<ul class="links collapse {{#isNotToggle 'components'}}in{{/isNotToggle}}"
{{#compare menu "===" 'normal' }}
id="components-links"
{{else}}
id="xs-components-links"
{{/compare}}>
{{#each components}}
<li class="link">
<a href="{{relativeURL ../depth 'components'}}components/{{name}}.html" {{#compare ../id "===" id }} data-type="entity-link" class="active" {{/compare}}>{{ name }}</a>
</li>
{{/each}}
</ul>
</li>
{{/element-alone}}
{{/if}}

{{#if directives}}
{{#element-alone directives 'directive'}}
<li class="chapter">
<div class="simple menu-toggler" data-toggle="collapse"
{{#compare menu "===" 'normal' }}
data-target="#directives-links"
{{else}}
data-target="#xs-directives-links"
{{/compare}}>
<span class="fa fa-fw fa-code"></span>
<span>Directives</span>
<span class="fa {{#isNotToggle 'directives'}}fa-angle-up{{else}}fa-angle-down{{/isNotToggle}}"></span>
</div>
<ul class="links collapse {{#isNotToggle 'components'}}in{{/isNotToggle}}"
{{#compare menu "===" 'normal' }}
id="directives-links"
{{else}}
id="xs-directives-links"
{{/compare}}>
{{#each directives}}
<li class="link">
<a href="{{relativeURL ../depth 'directives'}}directives/{{name}}.html" {{#compare ../id "===" id }} data-type="entity-link" class="active" {{/compare}}>{{ name }}</a>
</li>
{{/each}}
</ul>
</li>
{{/element-alone}}
{{/if}}

{{#if classes}}
<li class="chapter">
<div class="simple menu-toggler" data-toggle="collapse"
Expand Down Expand Up @@ -250,6 +308,35 @@
</li>
{{/if}}

{{#if injectables}}
{{#element-alone injectables 'injectable'}}
<li class="chapter">
<div class="simple menu-toggler" data-toggle="collapse"
{{#compare menu "===" 'normal' }}
data-target="#injectables-links"
{{else}}
data-target="#xs-injectables-links"
{{/compare}}>
<span class="fa fa-fw fa-long-arrow-down"></span>
<span>Injectables</span>
<span class="fa {{#isNotToggle 'injectables'}}fa-angle-up{{else}}fa-angle-down{{/isNotToggle}}"></span>
</div>
<ul class="links collapse {{#isNotToggle 'injectables'}}in{{/isNotToggle}}"
{{#compare menu "===" 'normal' }}
id="injectables-links"
{{else}}
id="xs-injectables-links"
{{/compare}}>
{{#each injectables}}
<li class="link">
<a href="{{relativeURL ../depth 'injectables'}}injectables/{{name}}.html" {{#compare ../id "===" id }} data-type="entity-link" class="active" {{/compare}}>{{ name }}</a>
</li>
{{/each}}
</ul>
</li>
{{/element-alone}}
{{/if}}

{{#if interceptors}}
<li class="chapter">
<div class="simple menu-toggler" data-toggle="collapse"
Expand Down Expand Up @@ -304,6 +391,35 @@
</li>
{{/if}}

{{#if pipes}}
{{#element-alone pipes 'pipe'}}
<li class="chapter">
<div class="simple menu-toggler" data-toggle="collapse"
{{#compare menu "===" 'normal' }}
data-target="#pipes-links"
{{else}}
data-target="#xs-pipes-links"
{{/compare}}>
<span class="fa fa-fw fa-plus"></span>
<span>Pipes</span>
<span class="fa {{#isNotToggle 'pipes'}}fa-angle-up{{else}}fa-angle-down{{/isNotToggle}}"></span>
</div>
<ul class="links collapse {{#isNotToggle 'pipes'}}in{{/isNotToggle}}"
{{#compare menu "===" 'normal' }}
id="pipes-links"
{{else}}
id="xs-pipes-links"
{{/compare}}>
{{#each pipes}}
<li class="link">
<a href="{{relativeURL ../depth 'pipes'}}pipes/{{name}}.html" {{#compare ../id "===" id }} data-type="entity-link" class="active" {{/compare}}>{{ name }}</a>
</li>
{{/each}}
</ul>
</li>
{{/element-alone}}
{{/if}}

{{#if miscellaneous}}
<li class="chapter">
<div class="simple menu-toggler" data-toggle="collapse"
Expand Down
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
--colors
--harmony
--timeout 120000
test/dist/cli/**/*.spec.js
test/dist/cli/**/*.js
13 changes: 13 additions & 0 deletions test/src/cli/cli-generation-big-app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,4 +573,17 @@ describe('CLI simple generation - big app', () => {
let file = read(distFolder + '/miscellaneous/typealiases.html');
expect(file).to.contain('<code>Type&lt;TableCellRendererBase&gt; | TemplateRef&lt;any&gt;</code>');
});

it('should support multiple union types with array', () => {
let file = read(distFolder + '/components/TodoComponent.html');
expect(file).to.contain('<code>(string | number)[]</code>');
});

it('should support alone elements in their own entry menu', () => {
let file = read(distFolder + '/index.html');
expect(file).to.contain('<a href="./components/JigsawTab.html" >JigsawTab</a>');
expect(file).to.contain('<a href="./directives/DoNothingDirective2.html" >DoNothingDirective2</a>');
expect(file).to.contain('<a href="./injectables/EmitterService.html" >EmitterService</a>');
expect(file).to.contain('<a href="./pipes/FirstUpperPipe2.html" >FirstUpperPipe2</a>');
});
});

0 comments on commit b010638

Please sign in to comment.