diff --git a/lib/adapters/handlebars.adapter.ts b/lib/adapters/handlebars.adapter.ts index ebbd35ccc..4187160a8 100644 --- a/lib/adapters/handlebars.adapter.ts +++ b/lib/adapters/handlebars.adapter.ts @@ -13,6 +13,13 @@ import { TemplateAdapter } from '../interfaces/template-adapter.interface'; export class HandlebarsAdapter implements TemplateAdapter { private precompiledTemplates: { [name: string]: handlebars.TemplateDelegate } = {}; + constructor() { + handlebars.registerHelper('concat', (...args) => { + args.pop(); + return args.join(''); + }); + } + public compile(mail: any, callback: any, mailerOptions: MailerOptions): void { const precompile = (template, callback, options) => { const templateExt = path.extname(template) || '.hbs'; @@ -25,17 +32,17 @@ export class HandlebarsAdapter implements TemplateAdapter { const template = fs.readFileSync(templatePath, 'UTF-8'); this.precompiledTemplates[templateName] = handlebars.compile(template, get(options, 'options', {})); - - return { - templateExt, - templateName, - templateDir, - templatePath, - }; } catch (err) { return callback(err); } } + + return { + templateExt, + templateName, + templateDir, + templatePath, + }; }; const { @@ -43,18 +50,21 @@ export class HandlebarsAdapter implements TemplateAdapter { templatePath, } = precompile(mail.data.template, callback, mailerOptions.template); - const { partials } = get(mailerOptions, 'template.options', { + const runtimeOptions = get(mailerOptions, 'options', { partials: false, + data: {}, }) - if (partials) { - const files = glob.sync(path.join(partials.dir, '*.hbs')); - files.forEach((file: string) => { - precompile(file, () => {}, partials); - }); + if (runtimeOptions.partials) { + const files = glob.sync(path.join(runtimeOptions.partials.dir, '*.hbs')); + files.forEach( + (file) => + precompile(file, () => { }, runtimeOptions.partials) + ); } const rendered = this.precompiledTemplates[templateName](mail.data.context, { + ...runtimeOptions, partials: this.precompiledTemplates }); diff --git a/package.json b/package.json index e09925b02..faa72f01a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "@veeklabs/nestjs-modules-mailer", - "version": "1.3.0", + "name": "@veek/nestjs-modules-mailer", + "version": "1.3.1", "description": "A mailer module for Nest framework (node.js)", "main": "dist/index.js", "types": "dist/index", @@ -29,7 +29,8 @@ "contributors": [ "Paweł Partyka ", "Cristiam Díaz ", - "Juan Echeverry " + "Juan Echeverry ", + "Eduardo Leal " ], "license": "MIT", "bugs": { diff --git a/publish.sh b/publish.sh old mode 100644 new mode 100755 index df8acea16..8d776ff8f --- a/publish.sh +++ b/publish.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash npm version $1 -npm publish +npm publish --access public