Skip to content

Commit

Permalink
STRF-7393 fix renderTheme function to work with Stencil CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-williamkwon committed Oct 3, 2019
1 parent 5fcf03d commit 57f3a38
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
33 changes: 33 additions & 0 deletions spec/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,36 @@ describe('render()', function() {
});
});
});

describe('renderTheme()', function() {
const assembler = {
getTemplates: (path, processor) => {
return Promise.resolve(processor({
'pages/product': '<html>{{> pages/partial}}</html>',
'pages/partial': '<h1>Hello world</h1>',
'pages/greet': '<h2>{{lang \'good\'}} {{lang \'morning\'}}</h2>',
'pages/pre': '<p>Let it go!</p>',
}));
},
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': '<html><h1>Hello world</h1></html>',
'pages/partial': '<h1>Hello world</h1>',
'pages/greet': '<h2>good morning</h2>',
'pages/pre': '<p>Let it go!</p>' }
);
done();
});
});
});
});

0 comments on commit 57f3a38

Please sign in to comment.