Skip to content
This repository has been archived by the owner on Jan 13, 2018. It is now read-only.

Commit

Permalink
backport BEM-930 into 0.6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergej Tatarincev authored and Vladimir Alaev committed Sep 16, 2013
1 parent 817b224 commit 0f4be5d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/tech/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@ var TechV1 = exports.Tech = require('./v1').Tech,
Q = require('q'),
U = require('../util'),

BEM,
getBem = function() {
if (!BEM) BEM = require('../..');

return BEM;
};
/**
* Return tech class for the tech module path.
*
* @param {String|Object} module Path to tech module or module object.
* @param {Level} [level] Level object to resolve techs by name.
* @returns {Tech} Tech class.
*/
getTechClass = exports.getTechClass = function(module, level) {
var getTechClass = exports.getTechClass = function(module, level) {

var tech = typeof module === 'string'? require(module) : module;

if (typeof tech === 'function') tech = tech(getBem());

var tech = typeof module === 'string'? require(module) : module,
requiredVersion = tech.API_VER,
var requiredVersion = tech.API_VER,
TechClass = requiredVersion > 1 ? TechV2 : TechV1;

// link to tech class found in Tech property
Expand Down
11 changes: 11 additions & 0 deletions test/data/techs/function-tech.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

module.exports = function(BEM) {
return {
techMixin: {
getBuildResults: function() {
return BEM.require.resolve('./techs/js');
}
}
};
};
6 changes: 6 additions & 0 deletions test/tech.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ describe('tech', function() {

});

it('for module with function-style code', function() {
var T = getTechClass(require.resolve('./data/techs/function-tech.js'));
T = new T('function-tech', 'function-tech');
assert.equal(T.getBuildResults(), BEM.require.resolve('./techs/js.js'));
});

it('throws an error when baseTechName is unresolvable', function() {
assert.throws(function() {
var level = new Level('', '');
Expand Down

0 comments on commit 0f4be5d

Please sign in to comment.