Skip to content

Commit

Permalink
Merge pull request #622 from /issues/621@v2
Browse files Browse the repository at this point in the history
Add browser.js+bemhtml+bemtree tech
  • Loading branch information
Vyacheslav Aristov committed May 14, 2015
2 parents fe392e9 + 67c2600 commit 3168e50
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
16 changes: 16 additions & 0 deletions .bem/techs/browser.js+bemhtml+bemtree.js
@@ -0,0 +1,16 @@
exports.baseTechName = 'browser.js+bemhtml';

exports.techMixin = {
getBuildResults : function(decl, levels, output, opts) {
var _this = this;

return this.__base(decl, levels, output, opts)
.then(function(res) {

return _this.concatBemxjst('bemtree', res, output, opts)
.then(function() {
return res;
});
});
}
};
27 changes: 16 additions & 11 deletions .bem/techs/browser.js+bemhtml.js
Expand Up @@ -8,6 +8,9 @@ exports.techMixin = {
getBuildResults : function(decl, levels, output, opts) {
var _this = this;

// ugly hack for https://github.com/bem/bem-core/issues/392
opts.force = true;

return this.__base(decl, levels, output, opts)
.then(function(res) {

Expand All @@ -20,6 +23,10 @@ exports.techMixin = {
},

concatBemhtml : function(res, output, opts) {
return this.concatBemxjst('bemhtml', res, output, opts);
},

concatBemxjst : function(tech, res, output, opts) {
var _this = this,
context = this.context,
declaration = context.opts.declaration;
Expand All @@ -29,33 +36,31 @@ exports.techMixin = {

decl = decl.depsByTechs;

if(!decl || !decl.js || !decl.js.bemhtml) return;
if(!decl || !decl.js || !decl.js[tech]) return;

decl = { deps : decl.js.bemhtml };
decl = { deps : decl.js[tech] };

var bemhtmlTech = context.createTech('bemhtml');
var bemxjstTech = context.createTech(tech);

if(bemhtmlTech.API_VER !== 2) return Q.reject(new Error(_this.getTechName() +
' can’t use v1 bemhtml tech to concat bemhtml content. Configure level to use v2 bemhtml.'));
if(bemxjstTech.API_VER !== 2) return Q.reject(new Error(_this.getTechName() +
' can’t use v1 ' + tech + ' tech to concat ' + tech + ' content. Configure level to use v2 ' + tech + '.'));

// ugly hack for https://github.com/bem/bem-core/issues/392
opts.force = true;
var bemhtmlResults = bemhtmlTech.getBuildResults(
var bemxjstResults = bemxjstTech.getBuildResults(
decl,
context.getLevels(),
output,
opts
);

return bemhtmlResults
return bemxjstResults
.then(function(r) {

// put bemhtml templates at the bottom of builded js file
// put templates at the bottom of builded js file
Object.keys(res).forEach(function(suffix) {
// test for array as in i18n.js+bemhtml tech
// there's hack to create symlink for default lang
// so 'js' key is a string there
Array.isArray(res[suffix]) && res[suffix].push(r['bemhtml.js']);
Array.isArray(res[suffix]) && res[suffix].push(r[tech + '.js']);
});

});
Expand Down

0 comments on commit 3168e50

Please sign in to comment.