elseware-nodejs 1.7.1 → 1.7.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.
package/dist/index.d.cts CHANGED
@@ -1896,7 +1896,9 @@ declare class EmailService {
1896
1896
 
1897
1897
  declare class TemplateEngine {
1898
1898
  static templateCache: Record<string, HandlebarsTemplateDelegate>;
1899
+ static partialsLoaded: Record<string, boolean>;
1899
1900
  static cssCache: Record<string, string>;
1901
+ static registerPartials(templateDir: string): void;
1900
1902
  static loadAllCSS(stylesDir: string): string;
1901
1903
  static render(templateName: string, data: any, templateDir: string): string;
1902
1904
  }
package/dist/index.d.ts CHANGED
@@ -1896,7 +1896,9 @@ declare class EmailService {
1896
1896
 
1897
1897
  declare class TemplateEngine {
1898
1898
  static templateCache: Record<string, HandlebarsTemplateDelegate>;
1899
+ static partialsLoaded: Record<string, boolean>;
1899
1900
  static cssCache: Record<string, string>;
1901
+ static registerPartials(templateDir: string): void;
1900
1902
  static loadAllCSS(stylesDir: string): string;
1901
1903
  static render(templateName: string, data: any, templateDir: string): string;
1902
1904
  }
package/dist/index.js CHANGED
@@ -5316,30 +5316,43 @@ var SMTPProvider = class {
5316
5316
  };
5317
5317
  var TemplateEngine = class {
5318
5318
  static templateCache = {};
5319
+ static partialsLoaded = {};
5319
5320
  static cssCache = {};
5320
- // Load ALL CSS files from styles folder
5321
+ static registerPartials(templateDir) {
5322
+ const partialsDir = path.join(templateDir, "partials");
5323
+ if (!fs3.existsSync(partialsDir) || this.partialsLoaded[templateDir]) return;
5324
+ const files = fs3.readdirSync(partialsDir);
5325
+ for (const file of files) {
5326
+ if (file.endsWith(".hbs")) {
5327
+ const name = path.basename(file, ".hbs");
5328
+ const content = fs3.readFileSync(path.join(partialsDir, file), "utf-8");
5329
+ Handlebars.registerPartial(name, content);
5330
+ }
5331
+ }
5332
+ this.partialsLoaded[templateDir] = true;
5333
+ }
5321
5334
  static loadAllCSS(stylesDir) {
5322
5335
  if (!fs3.existsSync(stylesDir)) return "";
5323
- const files = fs3.readdirSync(stylesDir).filter((f) => f.endsWith(".css"));
5324
- let combinedCSS = "";
5336
+ const files = fs3.readdirSync(stylesDir).filter((f) => f.endsWith(".css")).sort();
5337
+ let combined = "";
5325
5338
  for (const file of files) {
5326
5339
  const filePath = path.join(stylesDir, file);
5327
5340
  if (!this.cssCache[filePath]) {
5328
5341
  this.cssCache[filePath] = fs3.readFileSync(filePath, "utf-8");
5329
5342
  }
5330
- combinedCSS += this.cssCache[filePath] + "\n";
5343
+ combined += this.cssCache[filePath] + "\n";
5331
5344
  }
5332
- return combinedCSS;
5345
+ return combined;
5333
5346
  }
5334
5347
  static render(templateName, data, templateDir) {
5335
5348
  const templateKey = `${templateDir}:${templateName}`;
5349
+ this.registerPartials(templateDir);
5336
5350
  if (!this.templateCache[templateKey]) {
5337
5351
  const filePath = path.join(templateDir, `${templateName}.hbs`);
5338
5352
  const source = fs3.readFileSync(filePath, "utf-8");
5339
5353
  this.templateCache[templateKey] = Handlebars.compile(source);
5340
5354
  }
5341
- const stylesDir = path.join(templateDir, "styles");
5342
- const css = this.loadAllCSS(stylesDir);
5355
+ const css = this.loadAllCSS(path.join(templateDir, "styles"));
5343
5356
  const rawHtml = this.templateCache[templateKey]({
5344
5357
  ...data,
5345
5358
  styles: css