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.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,47 @@ var SMTPProvider = class {
|
|
|
5316
5316
|
};
|
|
5317
5317
|
var TemplateEngine = class {
|
|
5318
5318
|
static templateCache = {};
|
|
5319
|
+
static partialsLoaded = {};
|
|
5319
5320
|
static cssCache = {};
|
|
5320
|
-
|
|
5321
|
+
static registerPartials(templateDir) {
|
|
5322
|
+
if (this.partialsLoaded[templateDir]) return;
|
|
5323
|
+
const registerFromDir = (dirPath) => {
|
|
5324
|
+
if (!fs3.existsSync(dirPath)) return;
|
|
5325
|
+
const files = fs3.readdirSync(dirPath);
|
|
5326
|
+
for (const file of files) {
|
|
5327
|
+
if (file.endsWith(".hbs")) {
|
|
5328
|
+
const name = path.basename(file, ".hbs");
|
|
5329
|
+
const content = fs3.readFileSync(path.join(dirPath, file), "utf-8");
|
|
5330
|
+
Handlebars.registerPartial(name, content);
|
|
5331
|
+
}
|
|
5332
|
+
}
|
|
5333
|
+
};
|
|
5334
|
+
registerFromDir(path.join(templateDir, "partials"));
|
|
5335
|
+
registerFromDir(path.join(templateDir, "layouts"));
|
|
5336
|
+
this.partialsLoaded[templateDir] = true;
|
|
5337
|
+
}
|
|
5321
5338
|
static loadAllCSS(stylesDir) {
|
|
5322
5339
|
if (!fs3.existsSync(stylesDir)) return "";
|
|
5323
|
-
const files = fs3.readdirSync(stylesDir).filter((f) => f.endsWith(".css"));
|
|
5324
|
-
let
|
|
5340
|
+
const files = fs3.readdirSync(stylesDir).filter((f) => f.endsWith(".css")).sort();
|
|
5341
|
+
let combined = "";
|
|
5325
5342
|
for (const file of files) {
|
|
5326
5343
|
const filePath = path.join(stylesDir, file);
|
|
5327
5344
|
if (!this.cssCache[filePath]) {
|
|
5328
5345
|
this.cssCache[filePath] = fs3.readFileSync(filePath, "utf-8");
|
|
5329
5346
|
}
|
|
5330
|
-
|
|
5347
|
+
combined += this.cssCache[filePath] + "\n";
|
|
5331
5348
|
}
|
|
5332
|
-
return
|
|
5349
|
+
return combined;
|
|
5333
5350
|
}
|
|
5334
5351
|
static render(templateName, data, templateDir) {
|
|
5335
5352
|
const templateKey = `${templateDir}:${templateName}`;
|
|
5353
|
+
this.registerPartials(templateDir);
|
|
5336
5354
|
if (!this.templateCache[templateKey]) {
|
|
5337
5355
|
const filePath = path.join(templateDir, `${templateName}.hbs`);
|
|
5338
5356
|
const source = fs3.readFileSync(filePath, "utf-8");
|
|
5339
5357
|
this.templateCache[templateKey] = Handlebars.compile(source);
|
|
5340
5358
|
}
|
|
5341
|
-
const
|
|
5342
|
-
const css = this.loadAllCSS(stylesDir);
|
|
5359
|
+
const css = this.loadAllCSS(path.join(templateDir, "styles"));
|
|
5343
5360
|
const rawHtml = this.templateCache[templateKey]({
|
|
5344
5361
|
...data,
|
|
5345
5362
|
styles: css
|