elseware-nodejs 1.7.2 → 1.7.4
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 +24 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +24 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5331,30 +5331,47 @@ var SMTPProvider = class {
|
|
|
5331
5331
|
};
|
|
5332
5332
|
var TemplateEngine = class {
|
|
5333
5333
|
static templateCache = {};
|
|
5334
|
+
static partialsLoaded = {};
|
|
5334
5335
|
static cssCache = {};
|
|
5335
|
-
|
|
5336
|
+
static registerPartials(templateDir) {
|
|
5337
|
+
if (this.partialsLoaded[templateDir]) return;
|
|
5338
|
+
const registerFromDir = (dirPath) => {
|
|
5339
|
+
if (!fs3__default.default.existsSync(dirPath)) return;
|
|
5340
|
+
const files = fs3__default.default.readdirSync(dirPath);
|
|
5341
|
+
for (const file of files) {
|
|
5342
|
+
if (file.endsWith(".hbs")) {
|
|
5343
|
+
const name = path__default.default.basename(file, ".hbs");
|
|
5344
|
+
const content = fs3__default.default.readFileSync(path__default.default.join(dirPath, file), "utf-8");
|
|
5345
|
+
Handlebars__default.default.registerPartial(name, content);
|
|
5346
|
+
}
|
|
5347
|
+
}
|
|
5348
|
+
};
|
|
5349
|
+
registerFromDir(path__default.default.join(templateDir, "partials"));
|
|
5350
|
+
registerFromDir(path__default.default.join(templateDir, "layouts"));
|
|
5351
|
+
this.partialsLoaded[templateDir] = true;
|
|
5352
|
+
}
|
|
5336
5353
|
static loadAllCSS(stylesDir) {
|
|
5337
5354
|
if (!fs3__default.default.existsSync(stylesDir)) return "";
|
|
5338
|
-
const files = fs3__default.default.readdirSync(stylesDir).filter((f) => f.endsWith(".css"));
|
|
5339
|
-
let
|
|
5355
|
+
const files = fs3__default.default.readdirSync(stylesDir).filter((f) => f.endsWith(".css")).sort();
|
|
5356
|
+
let combined = "";
|
|
5340
5357
|
for (const file of files) {
|
|
5341
5358
|
const filePath = path__default.default.join(stylesDir, file);
|
|
5342
5359
|
if (!this.cssCache[filePath]) {
|
|
5343
5360
|
this.cssCache[filePath] = fs3__default.default.readFileSync(filePath, "utf-8");
|
|
5344
5361
|
}
|
|
5345
|
-
|
|
5362
|
+
combined += this.cssCache[filePath] + "\n";
|
|
5346
5363
|
}
|
|
5347
|
-
return
|
|
5364
|
+
return combined;
|
|
5348
5365
|
}
|
|
5349
5366
|
static render(templateName, data, templateDir) {
|
|
5350
5367
|
const templateKey = `${templateDir}:${templateName}`;
|
|
5368
|
+
this.registerPartials(templateDir);
|
|
5351
5369
|
if (!this.templateCache[templateKey]) {
|
|
5352
5370
|
const filePath = path__default.default.join(templateDir, `${templateName}.hbs`);
|
|
5353
5371
|
const source = fs3__default.default.readFileSync(filePath, "utf-8");
|
|
5354
5372
|
this.templateCache[templateKey] = Handlebars__default.default.compile(source);
|
|
5355
5373
|
}
|
|
5356
|
-
const
|
|
5357
|
-
const css = this.loadAllCSS(stylesDir);
|
|
5374
|
+
const css = this.loadAllCSS(path__default.default.join(templateDir, "styles"));
|
|
5358
5375
|
const rawHtml = this.templateCache[templateKey]({
|
|
5359
5376
|
...data,
|
|
5360
5377
|
styles: css
|