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

Simplify support for templates as commonJS files #465

Open
tadatuta opened this issue Jun 6, 2017 · 0 comments
Open

Simplify support for templates as commonJS files #465

tadatuta opened this issue Jun 6, 2017 · 0 comments

Comments

@tadatuta
Copy link
Member

tadatuta commented Jun 6, 2017

Now to use templates in commonJS format one must:

  1. Provide all the methods listed in BEMXJST.prototype.locals in exactly the same order to exported function
  2. Make first empty call of compile as first template is always considered to be string

E.g.

// b1.bemtree.js
module.exports = function(
  match,
  block,
  elem,
  mod,
  elemMod,
  oninit,
  xjstOptions,
  
) {
    block('b1').content()('i am b1');
};

// server.node.js
const bemtree = require('bem-xjst').bemtree;

const b1 = require('./blocks/b1.bemtree');

const tmpl = bemtree
    .compile() // this is the second point, expected to be not necessary 
    .compile(b1);

const bemjson = tmpl.apply({ block: 'b1' });

Let's support possibility to call template function with just one object argument having all needed methods so it could be used like this:

module.exports = function({block}) {
    block('b1').content()('i am b1');
};

I believe it should be possible to support such behavior as an option to make it backward compatible .

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

No branches or pull requests

2 participants