Skip to content

Commit 0af2cb5

Browse files
committed
feat: (strf-8630) fix template engine values
1 parent fc62b19 commit 0af2cb5

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

server/plugins/renderer/responses/pencil-response.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ const getTemplatePath = (request, data) => {
6060
*/
6161
const isSupportedHandlebarsVersion = version => ['handlebars-v3', 'handlebars-v4'].includes(version);
6262

63+
/**
64+
* Node.js projects are using variables in format: handlebars-v3, handlebars-v4;
65+
* Storefront and db are using format: handlebars_v3, handlebars_v4;
66+
* This function converts _v3 to -v3
67+
*
68+
* @param {String} version
69+
*/
70+
const compatibilizeTemplateEngine = version => version.replace('_', '-');
6371

6472
/**
6573
* Output post-processing
@@ -93,7 +101,7 @@ const makeDecorator = (request, context) => content => {
93101

94102
module.exports = function (data, assembler) {
95103
this.respond = function (request, h) {
96-
const templateEngine = data.context.template_engine || "handlebars-v3";
104+
const templateEngine = compatibilizeTemplateEngine(data.context.template_engine || "handlebars-v3");
97105

98106
if (!isSupportedHandlebarsVersion(templateEngine)) {
99107
throw new Error('Provided Handlebars version is not supported! Please use:handlebars-v3, handlebars-v4');

server/plugins/renderer/responses/pencil-response.spec.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,21 @@ describe('PencilResponse', () => {
5858
expect(h.response).toHaveBeenCalledTimes(1);
5959
});
6060

61-
it('should default to handlebars_v3 when the template_engine doesn\'t exist', async () => {
61+
it('should default to handlebars-v3 when the template_engine doesn\'t exist', async () => {
6262
delete data.context.template_engine;
6363

6464
const pencilResponse = new PencilResponse(data, assembler);
6565
await pencilResponse.respond(request, h);
6666

6767
expect(h.response).toHaveBeenCalledTimes(1);
6868
});
69+
70+
it('should make compatible handlbers_v3 variable', async () => {
71+
data.context.template_engine = 'handlebars_v3';
72+
73+
const pencilResponse = new PencilResponse(data, assembler);
74+
await pencilResponse.respond(request, h);
75+
76+
expect(h.response).toHaveBeenCalledTimes(1);
77+
});
6978
});

0 commit comments

Comments
 (0)