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.cjs CHANGED
@@ -5331,30 +5331,43 @@ var SMTPProvider = class {
5331
5331
  };
5332
5332
  var TemplateEngine = class {
5333
5333
  static templateCache = {};
5334
+ static partialsLoaded = {};
5334
5335
  static cssCache = {};
5335
- // Load ALL CSS files from styles folder
5336
+ static registerPartials(templateDir) {
5337
+ const partialsDir = path__default.default.join(templateDir, "partials");
5338
+ if (!fs3__default.default.existsSync(partialsDir) || this.partialsLoaded[templateDir]) return;
5339
+ const files = fs3__default.default.readdirSync(partialsDir);
5340
+ for (const file of files) {
5341
+ if (file.endsWith(".hbs")) {
5342
+ const name = path__default.default.basename(file, ".hbs");
5343
+ const content = fs3__default.default.readFileSync(path__default.default.join(partialsDir, file), "utf-8");
5344
+ Handlebars__default.default.registerPartial(name, content);
5345
+ }
5346
+ }
5347
+ this.partialsLoaded[templateDir] = true;
5348
+ }
5336
5349
  static loadAllCSS(stylesDir) {
5337
5350
  if (!fs3__default.default.existsSync(stylesDir)) return "";
5338
- const files = fs3__default.default.readdirSync(stylesDir).filter((f) => f.endsWith(".css"));
5339
- let combinedCSS = "";
5351
+ const files = fs3__default.default.readdirSync(stylesDir).filter((f) => f.endsWith(".css")).sort();
5352
+ let combined = "";
5340
5353
  for (const file of files) {
5341
5354
  const filePath = path__default.default.join(stylesDir, file);
5342
5355
  if (!this.cssCache[filePath]) {
5343
5356
  this.cssCache[filePath] = fs3__default.default.readFileSync(filePath, "utf-8");
5344
5357
  }
5345
- combinedCSS += this.cssCache[filePath] + "\n";
5358
+ combined += this.cssCache[filePath] + "\n";
5346
5359
  }
5347
- return combinedCSS;
5360
+ return combined;
5348
5361
  }
5349
5362
  static render(templateName, data, templateDir) {
5350
5363
  const templateKey = `${templateDir}:${templateName}`;
5364
+ this.registerPartials(templateDir);
5351
5365
  if (!this.templateCache[templateKey]) {
5352
5366
  const filePath = path__default.default.join(templateDir, `${templateName}.hbs`);
5353
5367
  const source = fs3__default.default.readFileSync(filePath, "utf-8");
5354
5368
  this.templateCache[templateKey] = Handlebars__default.default.compile(source);
5355
5369
  }
5356
- const stylesDir = path__default.default.join(templateDir, "styles");
5357
- const css = this.loadAllCSS(stylesDir);
5370
+ const css = this.loadAllCSS(path__default.default.join(templateDir, "styles"));
5358
5371
  const rawHtml = this.templateCache[templateKey]({
5359
5372
  ...data,
5360
5373
  styles: css