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-4237: Split off rendering functionality #130

Merged
merged 1 commit into from
Jan 24, 2018
Merged

STRF-4237: Split off rendering functionality #130

merged 1 commit into from
Jan 24, 2018

Conversation

mattolson
Copy link
Contributor

@mattolson mattolson commented Dec 21, 2017

  • Split off actual rendering functionality into new module called paper-handlebars, which encapsulates the use of Handlebars for rendering. This split allows us to introduce Handlebars v4 and potentially other template engines in the future, without changing the Paper interface.
  • Remove helpers (these have been moved to paper-handlebars).
  • Add rendererType parameter to Paper constructor. This defaults to handlebars (the current v3 implementation). If you pass handlebars-v4, it will use 4.0.11.
  • Add Node 8.x to Travis
  • Updated package.json to use ~ instead of ^ and updated dependencies to match what we're currently using.

Breaking changes

  • Removed the direct access of contentServiceContext for setting page content. From now on, use addContent() and getContent().
  • Removed getTemplateProcessor(). This is an internal concern of paper-handlebars and is used by loadTemplates.
  • Removed loadTemplatesSync(). This was only used by helper tests and is no longer needed.
  • Removed handlebars instance variable. Hopefully nobody is accessing that directly. Any helpers that were accessing it have been updated in paper-handlebars to use the global context they are given rather than accessing Paper directly at all.
  • The translator attribute has been moved to paper-handlebars and is no longer accessible directly on Paper.
  • The decorators attribute has been moved to paper-handlebars and is no longer accessible directly on Paper.
  • The settings attribute has been renamed to siteSettings. This should only be accessed by paper-handlebars.
  • The cdnify() function has been moved into a helper library in paper-handlebars.
  • The inject attribute has been removed. This is storage used by two of the helpers, and the implementation has moved to paper-handlebars.

@mattolson
Copy link
Contributor Author

@bigcommerce/storefront-team

index.js Outdated
case 'handlebars-v4':
this.renderer = new HandlebarsRenderer(this.siteSettings, this.themeSettings, 'v4');
break;
case 'handlebars':
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just use default 🍹

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer to keep this explicit, even just as documentation

index.js Outdated
*/
loadTemplates(path, callback) {
let processor = this.getTemplateProcessor();
let preProcessor = this.renderer.getPreProcessor();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move this call to the constructor as a variable so we don't make this call for each path in the list ?

Copy link
Contributor

@junedkazi junedkazi left a comment

Choose a reason for hiding this comment

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

👏 Really excited about this PR as it will open up possibilities in terms of all different templating engines we can support.

* Split off actual rendering functionality into new module
  called paper-handlebars. This encapsulates rendering with
  Handlebars v3. This split allows us to introduce Handlebars
  v4 and potentially other template engines in the future,
  without changing the Paper interface.
@mattolson
Copy link
Contributor Author

@bigcommerce/storefront-team ♻️

"main": "index.js",
"author": "Bigcommerce",
"license": "BSD-4-Clause",
"scripts": {
"test": "lab -l -t 90"
"linter": "eslint .",
Copy link
Contributor

Choose a reason for hiding this comment

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

yay! i love the minimalism of using npm scripts over grunt/gulp tasks. :)

helpers.forEach(helper => helper(this));
}
// Build renderer based on type
switch(rendererType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🍹 part of me wants to reduce this to something like:

this.renderer = new HandlebarsRenderer(this.siteSettings, this.themeSettings, rendererType.split(/-/).pop();

but being explicit is probably a better idea

@@ -3,9 +3,7 @@ sudo: false
node_js:
- 4
- 6

- 8
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we drop node 4 from the list ? Since all our prod & dev envs are node 6 & above ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We still need to support CLI, which supports Node 4 still.

Copy link
Contributor

@mjschock mjschock left a comment

Choose a reason for hiding this comment

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

overall lgtm 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants