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

Improve JavaScript templates #627

Merged
merged 4 commits into from
Jul 26, 2019
Merged

Improve JavaScript templates #627

merged 4 commits into from
Jul 26, 2019

Conversation

zachleat
Copy link
Member

@zachleat zachleat commented Jul 25, 2019

  • When using class-based templates, use a single object instance for data and rendering.
  • Add support for object-based JS templates a la module.exports = { data: function() {}, render: function() {} } and module.exports.data = function() {}; module.exports.render = function() {};
  • Add support for Node v12+ feature: class fields a la:
module.exports = class {
  data = {
    title: 'hi',
  };

  render(data) {
    return `
      <p>${data.title}</p>
    `;
  }
};
  • Fails gracefully when class or object definition is missing a render method (returns ""), behaves similar to a data file.

Fixes #622.

zachleat added 3 commits July 24, 2019 22:28
…lic class fields, one class instance for data and render, as well as multiple exports as described here #622 (comment)

Also adds travis tests for Node 12 (required for public class fields)

#622
@zachleat zachleat added this to the Next Minor Version milestone Jul 25, 2019
@zachleat
Copy link
Member Author

zachleat commented Jul 25, 2019

Okay I think this is good to merge after Travis does its thing.

Thank you for your help here @jakearchibald!

@zachleat zachleat merged commit 90457ff into master Jul 26, 2019
@zachleat zachleat deleted the issue-622 branch July 26, 2019 01:52
@jakearchibald
Copy link

Yay! Glad I was useful

@reubenlillie
Copy link

@jakearchibald, thank you for your work here. @zachleat, thanks for receiving it. Class syntax in JS feels so foreign. This added flexibility makes teaching 11ty to beginners so much easier.

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

Successfully merging this pull request may close these issues.

Support class properties in js templates
3 participants