@brilab-mailer/template-handlebars 0.0.5-1 → 0.0.5-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ interface HandlebarsConfig extends MailerTemplateEngineExtendsOptionsType {
5
5
  export declare class HandlebarsTemplateEngine implements MailerTemplateEngine {
6
6
  private readonly options;
7
7
  private readonly hbs;
8
+ private readonly _cached;
8
9
  private readonly templateCache;
9
10
  private readonly layoutCache;
10
11
  private readonly templatesDir;
@@ -1 +1 @@
1
- {"version":3,"file":"handlebars-template.engine.d.ts","sourceRoot":"","sources":["../../src/lib/handlebars-template.engine.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,oBAAoB,EACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EACX,sCAAsC,EACtC,MAAM,0BAA0B,CAAC;AAKlC,UAAU,gBACT,SAAQ,sCAAsC;CAAG;AAElD,qBACa,wBAAyB,YAAW,oBAAoB;IAYnE,OAAO,CAAC,QAAQ,CAAC,OAAO;IAXzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAuB;IAE3C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkD;IAChF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkD;IAE9E,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBAInB,OAAO,EAAE,gBAAgB;IAkB3C,OAAO,CAAC,mBAAmB;IAiB3B,OAAO,CAAC,uBAAuB;IAkC/B,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,UAAU;IAaZ,MAAM,CACX,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EACjC,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAA6B,GACxD,OAAO,CAAC,MAAM,CAAC;CASlB"}
1
+ {"version":3,"file":"handlebars-template.engine.d.ts","sourceRoot":"","sources":["../../src/lib/handlebars-template.engine.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,oBAAoB,EACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EACX,sCAAsC,EACtC,MAAM,0BAA0B,CAAC;AAMlC,UAAU,gBACT,SAAQ,sCAAsC;CAC9C;AAED,qBACa,wBAAyB,YAAW,oBAAoB;IAanE,OAAO,CAAC,QAAQ,CAAC,OAAO;IAZzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAuB;IAE3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkD;IAChF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkD;IAE9E,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBAInB,OAAO,EAAE,gBAAgB;IAoB3C,OAAO,CAAC,mBAAmB;IAiB3B,OAAO,CAAC,uBAAuB;IAkC/B,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,UAAU;IAaZ,MAAM,CACX,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EACjC,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAA6B,GACxD,OAAO,CAAC,MAAM,CAAC;CAYlB"}
@@ -4,9 +4,11 @@ import { MAILER_TEMPLATE_ENGINE_OPTIONS, } from '@brilab-mailer/contracts';
4
4
  import * as fs from 'fs';
5
5
  import * as path from 'path';
6
6
  import Handlebars from 'handlebars';
7
+ import juice from 'juice';
7
8
  let HandlebarsTemplateEngine = class HandlebarsTemplateEngine {
8
9
  options;
9
10
  hbs = Handlebars.create();
11
+ _cached;
10
12
  templateCache = new Map();
11
13
  layoutCache = new Map();
12
14
  templatesDir;
@@ -14,6 +16,7 @@ let HandlebarsTemplateEngine = class HandlebarsTemplateEngine {
14
16
  partialsDir;
15
17
  constructor(options) {
16
18
  this.options = options;
19
+ this._cached = this.options.cached ?? true;
17
20
  const rootDir = this.options?.rootDir ?? process.cwd();
18
21
  const templateDir = this.options?.templateDir ?? '';
19
22
  const baseDir = path.join(rootDir, templateDir);
@@ -60,7 +63,7 @@ let HandlebarsTemplateEngine = class HandlebarsTemplateEngine {
60
63
  if (!file.name.toLowerCase().endsWith('.hbs'))
61
64
  continue;
62
65
  const name = `${namespace}${path.basename(file.name, '.hbs')}`;
63
- if (registered.has(name))
66
+ if (this._cached && registered.has(name))
64
67
  continue;
65
68
  const content = fs.readFileSync(fullPath, 'utf8');
66
69
  registered.add(name);
@@ -70,7 +73,7 @@ let HandlebarsTemplateEngine = class HandlebarsTemplateEngine {
70
73
  registerRecursive(partialsPath);
71
74
  }
72
75
  loadTemplate(key) {
73
- if (this.templateCache.has(key))
76
+ if (this._cached && this.templateCache.has(key))
74
77
  return this.templateCache.get(key);
75
78
  const filePath = path.join(this.templatesDir, `${key}.hbs`);
76
79
  if (!fs.existsSync(filePath)) {
@@ -82,7 +85,7 @@ let HandlebarsTemplateEngine = class HandlebarsTemplateEngine {
82
85
  return compiled;
83
86
  }
84
87
  loadLayout(key) {
85
- if (this.layoutCache.has(key))
88
+ if (this._cached && this.layoutCache.has(key))
86
89
  return this.layoutCache.get(key);
87
90
  const filePath = path.join(this.layoutsDir, `${key}.hbs`);
88
91
  if (!fs.existsSync(filePath))
@@ -96,9 +99,10 @@ let HandlebarsTemplateEngine = class HandlebarsTemplateEngine {
96
99
  const template = this.loadTemplate(templateKey);
97
100
  const bodyHtml = template(context);
98
101
  const layout = this.loadLayout(options?.layoutKey || 'default');
99
- if (!layout)
100
- return bodyHtml;
101
- return layout({ ...context, body: bodyHtml });
102
+ const fullHtml = layout
103
+ ? layout({ ...context, body: bodyHtml })
104
+ : bodyHtml;
105
+ return juice(fullHtml);
102
106
  }
103
107
  };
104
108
  HandlebarsTemplateEngine = __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brilab-mailer/template-handlebars",
3
- "version": "0.0.5-1",
3
+ "version": "0.0.5-3",
4
4
  "author": "Bohdan Radchenko <radchenkobs@gmail.com>",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -26,8 +26,8 @@
26
26
  "peerDependencies": {
27
27
  "@nestjs/common": "^10.0.0",
28
28
  "@nestjs/config": "^3.0.0",
29
- "@brilab-mailer/contracts": "^0.0.5-1",
30
- "@brilab-mailer/core": "^0.0.5-1"
29
+ "@brilab-mailer/contracts": "^0.0.5-3",
30
+ "@brilab-mailer/core": "^0.0.5-3"
31
31
  },
32
32
  "peerDependenciesMeta": {
33
33
  "@brilab-mailer/contracts": {
@@ -38,6 +38,7 @@
38
38
  }
39
39
  },
40
40
  "dependencies": {
41
- "handlebars": "4.7.8"
41
+ "handlebars": "4.7.8",
42
+ "juice": "^11.0.3"
42
43
  }
43
44
  }