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

Commit

Permalink
Merge pull request #435 from bem/BEM-949
Browse files Browse the repository at this point in the history
Add ability to specify level prototype as a name (close #367, BEM-949)
  • Loading branch information
scf2k committed Sep 13, 2013
2 parents 40074a6 + a03f17a commit 9a7a488
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lib/level.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var PATH = require('./path'),
FS = require('fs'),
INHERIT = require('inherit'),
createTech = require('./tech').createTech,
U = require('util'),
bemUtil = require('./util'),
LOGGER = require('./logger'),
isRequireable = bemUtil.isRequireable,
Expand All @@ -19,13 +20,32 @@ var PATH = require('./path'),
return BEM;
},

getLevelClass = function(path, optional) {
var level = optional && !isRequireable(path) ? {} : requireLevel(path);
getLevelClass = function(path, optional, stack) {
stack = stack || [];

var level;
try {
level = optional && !isRequireable(path) ? {} : requireLevel(path);
} catch(error) {
throw new Error(U.format(
'level module %s can not be found %s %s%s\n',
path,
stack.length > 0? 'but required by the level': '',
stack.length > 1? 'inheritance tree:\n\t': '',
stack.join('\n\t')));
}

stack.push(path);

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

if (level.Level) return level.Level;
return INHERIT(level.baseLevelPath? getLevelClass(level.baseLevelPath) : Level, level);

var baseLevelPath = (level.baseLevelName?
PATH.join(__dirname, 'levels', level.baseLevelName):
null) || level.baseLevelPath;

return INHERIT(baseLevelPath? getLevelClass(baseLevelPath, false, stack) : Level, level);
},

requireLevel = function(path) {
Expand Down

0 comments on commit 9a7a488

Please sign in to comment.