-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Handlerbars RunTime options over Eval handlers
- Loading branch information
1 parent
4ad320a
commit b132d4e
Showing
3 changed files
with
9 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,11 @@ const configurationService = new ConfigurationService(); | |
|
||
async function createPDF(htmlData, data) { | ||
const template = Handlebars.compile(htmlData); | ||
let helpers = Handlebars.compile(await configurationService.addHelpers(HELPERS.CERTIFICATE_HELPER_FUNCTIONS))().toString(); | ||
eval(helpers); | ||
|
||
let certificate = template(data); | ||
const handlers = Handlebars.compile(await configurationService.addHelpers(HELPERS.CERTIFICATE_HELPER_FUNCTIONS))(); | ||
const handlerObj = new Function('return '+handlers)(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
himeshr-egov
Collaborator
|
||
let certificate = template(data, {helpers:handlerObj}); | ||
|
||
const browser = await puppeteer.launch({ | ||
headless: true, | ||
//comment to use default | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
Handlebars.registerHelper("loud", function (aString) { return aString.toString().toUpperCase() }); | ||
Handlebars.registerHelper("small", function (aString) { return aString.toString().toLowerCase() }); | ||
helper={ | ||
This comment has been minimized.
Sorry, something went wrong.
himeshr-egov
Collaborator
|
||
loud: function (aString) { return aString.toString().toUpperCase() }, | ||
small: function (aString) { return aString.toString().toLowerCase() } | ||
} |
Joy and i had a discussion, where we thought, it made sense to move out the compilation, if we were willing to sacrifice flexibility of auto-update of handler functions. So please discuss this with platform team once.