Skip to content

Commit

Permalink
feat(package): ability to enable/disable hashtag and mentions links #22
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyNahas committed Nov 21, 2018
1 parent 423a19d commit 2df2cf9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ gulp.task('rollup-bundle', (cb) => {
// See https://github.com/tinesoft/generator-ngx-library/TROUBLESHOUTING.md if trouble
'linkifyjs': _.camelCase('linkifyjs'.replace('/', '.')),
'linkifyjs/string': _.camelCase('linkifyjs/string'.replace('/', '.')),
'inkifyjs/plugins/hashtag': _.camelCase('inkifyjs/plugins/hashtag'.replace('/', '.')),
'inkifyjs/plugins/hashtag': _.camelCase('linkifyjsPluginsHashtag'.replace('/', '.')),
// 'linkifyjs/plugins/hashtag': 'hashtag',
};

Expand Down
5 changes: 5 additions & 0 deletions src/module/interfaces/ngx-linkifyjs.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ export interface Link {
value: string,
href: string,
}

export interface NgxLinkifyjsConfig {
enableHash?: boolean,
enableMention?: boolean
}
23 changes: 20 additions & 3 deletions src/module/ngx-linkifyjs.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {NgxLinkifyjsPipe} from './pipes/ngx-linkifyjs.pipe';

// Export module's public API
export {Link} from './interfaces/ngx-linkifyjs.interface';
import {NgxLinkifyjsConfig} from './interfaces/ngx-linkifyjs.interface';

export {LinkType} from './enum/linktype.enum';
export {NgxLinkifyjsPipe} from './pipes/ngx-linkifyjs.pipe';
export {NgxLinkifyjsService} from './service/ngx-linkifyjs.service';
Expand All @@ -25,15 +27,30 @@ export {NgxLinkifyjsService} from './service/ngx-linkifyjs.service';
})
export class NgxLinkifyjsModule {

static forRoot(): ModuleWithProviders {
private static DEFAULT_CONFIG: NgxLinkifyjsConfig = {
enableHash: true,
enableMention: true
};

static forRoot(config?: NgxLinkifyjsConfig): ModuleWithProviders {
Object.assign(this.DEFAULT_CONFIG, config);
return {
ngModule: NgxLinkifyjsModule,
providers: [NgxLinkifyjsService]
};
}

constructor() {
hashtag(linkify);
// mention(linkify);
this._handleConfig();
}

private _handleConfig() {
if (NgxLinkifyjsModule.DEFAULT_CONFIG.enableHash) {
hashtag(linkify);
}

if (NgxLinkifyjsModule.DEFAULT_CONFIG.enableMention) {
mention(linkify);
}
}
}

0 comments on commit 2df2cf9

Please sign in to comment.