From 50d977a2b8d154042e5d8f07a82a6970f5ffce7f Mon Sep 17 00:00:00 2001 From: William Kwon Date: Thu, 3 Oct 2019 12:00:31 -0700 Subject: [PATCH] STRF-7393 fix renderTheme function to work with Stencil CLI --- CHANGELOG.md | 3 +++ index.js | 4 ++-- package.json | 2 +- spec/index.js | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95fdc6b3..9d90257a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 3.0.0-rc.23 (2019-10-03) +- Fix renderTheme function so that it may work with Stencil CLI [#181](https://github.com/bigcommerce/paper/pull/181) + ## 3.0.0-rc.22 (2019-10-02) - Bump paper version [#180](https://github.com/bigcommerce/paper/pull/180) diff --git a/index.js b/index.js index 20f57786..5c8040c3 100644 --- a/index.js +++ b/index.js @@ -250,8 +250,8 @@ class Paper { // compile all the template required files into an object result = {}; for (let path in templatePath) { - renderPromises.push(this.render(path, data.context).then(html => { - result[path] = html; + renderPromises.push(this.render(templatePath[path], data.context).then(html => { + result[templatePath[path]] = html; })); } } else { diff --git a/package.json b/package.json index 0a342bc5..ca92c905 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bigcommerce/stencil-paper", - "version": "3.0.0-rc.22", + "version": "3.0.0-rc.23", "description": "A Stencil plugin to load template files and render pages using backend renderer plugins.", "main": "index.js", "author": "Bigcommerce", diff --git a/spec/index.js b/spec/index.js index bbbdb639..a35e53bc 100644 --- a/spec/index.js +++ b/spec/index.js @@ -122,3 +122,41 @@ describe('render()', function() { }); }); }); + +describe('renderTheme()', function() { + const assembler = { + getTemplates: (path, processor) => { + return Promise.resolve(processor({ + 'pages/product': '{{> pages/partial}}', + 'pages/partial': '

{{variable}}

', + 'pages/greet': '

{{lang \'good\'}} {{lang \'morning\'}}

', + 'pages/pre': '{{{pre object}}}', + })); + }, + getTranslations: () => { + return Promise.resolve({}); + } + }; + + const context = { + variable: 'hello world', + object: {} + }; + + const themeComponents = ['pages/product', 'pages/partial', 'pages/greet', 'pages/pre']'' + + it('should render theme', function(done) { + const paper = new Paper(null, null, assembler); + paper.loadTheme(themeComponents, '').then(() => { + paper.renderTheme(themeComponents, context).then(result => { + expect(result).to.be.equal({ + 'pages/product': '

', + 'pages/partial': '

', + 'pages/greet': '

good morning

', + 'pages/pre': '
' }
+                );
+                done();
+            });
+        });
+    });
+});