Skip to content

Commit

Permalink
feat: allow await in custom code handlebars
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhendumadhukar committed Aug 4, 2023
1 parent ceefc9b commit 9957355
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/handlebar/CsvHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class CsvHelper {
* @returns {void}
*/
register = () => {
this.Handlebars.registerHelper("csv", (context: any) => {
this.Handlebars.registerHelper("csv", async (context: any) => {
/* eslint-disable no-unused-vars */
const request: express.Request = context.data.root.request;
/* eslint-disable no-unused-vars */
Expand Down Expand Up @@ -55,7 +55,7 @@ export class CsvHelper {
return jsonObj[key] === value;
});
}
const code = eval(context.fn(this));
const code = await eval(context.fn(this));
code["CamouflageResponseType"] = "code";
return JSON.stringify(code);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/handlebar/InjectHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export class InjectHelper {
* @returns {void}
*/
register = () => {
this.Handlebars.registerHelper("inject", (context: any) => {
this.Handlebars.registerHelper("inject", async (context: any) => {
/* eslint-disable no-unused-vars */
const request: express.Request = context.data.root.request;
const logger = context.data.root.logger;
/* eslint-disable no-unused-vars */
const result = eval(context.fn(this));
const result = await eval(context.fn(this));
return result;
});
};
Expand Down
4 changes: 2 additions & 2 deletions src/handlebar/loadCustomHandlebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ const registerCustomHandlebars = (Handlebars: any, extHelpers: string) => {
logger.error(`Cannot override custom helper ${customHandlebar.name}`);
} else {
logger.info(`Registering custom handlebars: ${customHandlebar.name}`);
Handlebars.registerHelper(customHandlebar.name, (context: any) => {
Handlebars.registerHelper(customHandlebar.name, async (context: any) => {
/* eslint-disable no-unused-vars */
const request: express.Request = context.data.root.request;
const logger = context.data.root.logger;
/* eslint-disable no-unused-vars */
const result = eval(customHandlebar.logic);
const result = await eval(customHandlebar.logic);
return result;
});
}
Expand Down

0 comments on commit 9957355

Please sign in to comment.