Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 29 additions & 23 deletions lib/adapters/liquid.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,38 @@ import { TemplateAdapter } from '../interfaces/template-adapter.interface';
import { Liquid } from 'liquidjs';

export class LiquidAdapter implements TemplateAdapter {
private config: Partial<Liquid['options']>;
private config: Partial<Liquid['options']>;

constructor(config?: Partial<Liquid['options']>) {
Object.assign(this.config, config);
}
constructor(config?: Partial<Liquid['options']>) {
Object.assign(this.config, config);
}

public compile(mail: any, callback: any, mailerOptions: MailerOptions): void {
const { context, template } = mail.data;
public compile(mail: any, callback: any, mailerOptions: MailerOptions): void {
const { context, template } = mail.data;

const templateExt = path.extname(template) || '.liquid';
const templateName = path.basename(template, path.extname(template));
const templateDir = path.isAbsolute(template)
? path.dirname(template)
: path.join(get(mailerOptions, 'template.dir', ''), path.dirname(template));
const templateExt = path.extname(template) || '.liquid';
const templateName = path.basename(template, path.extname(template));
const templateDir = path.isAbsolute(template)
? path.dirname(template)
: path.join(
get(mailerOptions, 'template.dir', ''),
path.dirname(template),
);

const engine = new Liquid({
extname: templateExt,
root: templateDir,
...this.config.globals
});
const engine = new Liquid({
extname: templateExt,
root: templateDir,
...this.config.globals,
});

engine.renderFile(templateName, context).then((body) => {
mail.data.html = body;
return callback();
}).catch((err) => {
return callback(err);
});
}
engine
.renderFile(templateName, context)
.then((body) => {
mail.data.html = body;
return callback();
})
.catch((err) => {
return callback(err);
});
}
}
73 changes: 37 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"build": "tsc -p tsconfig.json",
"deploy": "sh ./publish.sh",
"format": "prettier **/**/*.ts --ignore-path ./.prettierignore --write",
"audit:convert": "yarn-audit-fix --flow=convert",
"audit:patch": "yarn-audit-fix --flow=patch",
"audit:convert": "npx yarn-audit-fix --flow=convert",
"audit:patch": "npx yarn-audit-fix --flow=patch",
"audit:fix": "npx yarn-audit-fix --package-lock-only=false --force --legacy-peer-deps --flow=convert",
"major": "npm run release -- --release-as major",
"minor": "npm run release -- --release-as minor",
Expand All @@ -54,62 +54,63 @@
]
},
"dependencies": {
"@css-inline/css-inline": "0.14.1",
"glob": "10.3.12"
"@css-inline/css-inline": "0.14.3",
"glob": "11.0.1"
},
"optionalDependencies": {
"@types/ejs": "^3.1.5",
"@types/pug": "^2.0.10",
"@types/mjml": "^4.7.4",
"@types/pug": "^2.0.10",
"ejs": "^3.1.10",
"handlebars": "^4.7.8",
"mjml": "^5.0.0-alpha.4",
"pug": "^3.0.2",
"liquidjs": "^10.11.1",
"preview-email": "^3.0.19"
"liquidjs": "^10.20.2",
"mjml": "5.0.0-alpha.6",
"preview-email": "^3.1.0",
"pug": "^3.0.3"
},
"devDependencies": {
"@commitlint/cli": "19.3.0",
"@commitlint/config-angular": "19.3.0",
"@nestjs/common": "10.3.8",
"@nestjs/core": "10.3.8",
"@nestjs/testing": "10.3.8",
"@commitlint/cli": "19.6.1",
"@commitlint/config-angular": "19.7.0",
"@nestjs/common": "11.0.4",
"@nestjs/core": "11.0.4",
"@nestjs/testing": "11.0.4",
"@types/glob": "8.1.0",
"@types/jest": "29.5.12",
"@types/lodash": "4.17.0",
"@types/nodemailer": "6.4.14",
"@types/pug": "2.0.10",
"@typescript-eslint/eslint-plugin": "7.7.1",
"@typescript-eslint/parser": "7.7.1",
"husky": "9.0.11",
"@types/jest": "29.5.14",
"@types/lodash": "4.17.14",
"@types/node": "^22.10.10",
"@types/nodemailer": "6.4.17",
"@types/pug": "^2.0.10",
"@typescript-eslint/eslint-plugin": "8.21.0",
"@typescript-eslint/parser": "8.21.0",
"husky": "9.1.7",
"jest": "29.7.0",
"lint-staged": "15.2.2",
"nodemailer": "6.9.13",
"nodemailer-mock": "2.0.6",
"prettier": "3.2.5",
"preview-email": "3.0.19",
"lint-staged": "15.4.2",
"nodemailer": "6.9.16",
"nodemailer-mock": "2.0.8",
"prettier": "3.4.2",
"preview-email": "^3.1.0",
"reflect-metadata": "0.2.2",
"rimraf": "5.0.5",
"rimraf": "6.0.1",
"rxjs": "7.8.1",
"standard-version": "9.5.0",
"ts-jest": "29.1.2",
"ts-jest": "29.2.5",
"ts-node": "10.9.2",
"tslib": "2.6.2",
"typescript": "5.4.5",
"yarn-audit-fix": "10.0.7"
"tslib": "2.8.1",
"typescript": "5.7.3",
"yarn-audit-fix": "10.1.1"
},
"peerDependencies": {
"@nestjs/common": ">=7.0.9",
"@nestjs/core": ">=7.0.9",
"@types/ejs": ">=3.0.3",
"@types/pug": ">=2.0.6",
"@types/mjml": ">=4.7.4",
"nodemailer": ">=6.4.6",
"@types/pug": ">=2.0.6",
"ejs": ">=3.1.2",
"handlebars": ">=4.7.6",
"mjml": ">=4.15.3",
"pug": ">=3.0.1",
"liquidjs": ">=10.8.2",
"preview-email": ">=3.0.19"
"mjml": ">=4.15.3",
"nodemailer": ">=6.4.6",
"preview-email": ">=3.0.19",
"pug": ">=3.0.1"
}
}
Loading