Skip to content

Commit

Permalink
Merge pull request #720 from /issues/719@v2
Browse files Browse the repository at this point in the history
bem-tools: Support `require`  in BEMJSON and BEMHTML
  • Loading branch information
Vyacheslav Aristov committed May 14, 2015
2 parents 3168e50 + da7f0b0 commit 1d46e48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
21 changes: 15 additions & 6 deletions .bem/techs/html.js
@@ -1,6 +1,7 @@
var BEM = require('bem'),
Q = BEM.require('q'),
VM = require('vm');
VM = require('vm'),
REQF = require('reqf');

exports.API_VER = 2;

Expand All @@ -11,10 +12,12 @@ exports.techMixin = {
var path = this.getPath(prefix, 'bemhtml.js');
return BEM.util.readFile(path)
.then(function(c) {
/* global BEMHTML */
/** @name BEMHTML variable appears after runInThisContext() call */
VM.runInThisContext(c, path);
return BEMHTML;
var ctx = VM.createContext({
require : REQF(path, module),
console : console
});
VM.runInContext(c, ctx, path);
return ctx.BEMHTML;
});

},
Expand All @@ -24,7 +27,13 @@ exports.techMixin = {
var path = this.getPath(prefix, 'bemjson.js');
return BEM.util.readFile(path)
.then(function(c) {
return VM.runInThisContext(c, path);
return VM.runInNewContext(
c,
{
require : REQF(path, module),
console : console
},
path);
});

},
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -30,6 +30,7 @@
"bower": "1.3.12",
"istanbul": "~0.3.2",
"vow": "0.4.8",
"reqf": "^1.0.0",
"bem-naming": "0.5.1",
"enb": "0.15.0",
"enb-bem-techs": "^1.0.4",
Expand Down

0 comments on commit 1d46e48

Please sign in to comment.