Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STRF-7393 fix renderTheme function to work with Stencil CLI #181

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

@ncheikh ncheikh Oct 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test cover the case we were seeing with partials not be rendered?

Copy link
Contributor Author

@bc-williamkwon bc-williamkwon Oct 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pages/partial is in pages/product and its content is part of the value for pages/product in the object. The issue with renderTheme function was that the for in loop was using numeric indices and thus not grabbing the actual values of elements in templatePath.

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();
});
});
});
});