From 57f3a3832e3544234bc353e181a3ec7214d99e87 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 | 3 ++- package.json | 2 +- spec/index.js | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 2 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..8ba16ed4 100644 --- a/index.js +++ b/index.js @@ -249,7 +249,8 @@ class Paper { // If templatePath is an array (multiple templates using render_with option), // compile all the template required files into an object result = {}; - for (let path in templatePath) { + for (let i = 0; i < templatePath.length; i++) { + const path = templatePath[i]; renderPromises.push(this.render(path, data.context).then(html => { result[path] = html; })); 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..7fc0f37a 100644 --- a/spec/index.js +++ b/spec/index.js @@ -122,3 +122,36 @@ describe('render()', function() { }); }); }); + +describe('renderTheme()', function() { + const assembler = { + getTemplates: (path, processor) => { + return Promise.resolve(processor({ + 'pages/product': '{{> pages/partial}}', + 'pages/partial': '

Hello world

', + 'pages/greet': '

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

', + 'pages/pre': '

Let it go!

', + })); + }, + getTranslations: () => { + return Promise.resolve({}); + } + }; + + 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, {}).then(result => { + expect(result).to.be.equal({ + 'pages/product': '

Hello world

', + 'pages/partial': '

Hello world

', + 'pages/greet': '

good morning

', + 'pages/pre': '

Let it go!

' } + ); + done(); + }); + }); + }); +});