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

Commit

Permalink
Add ability to specify level prototype as a name (close #367, BEM-949)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Alaev committed Aug 21, 2013
1 parent 46321b1 commit 7156865
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions lib/level.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,35 @@ var PATH = require('./path'),
FS = require('fs'),
INHERIT = require('inherit'),
createTech = require('./tech').createTech,
util = require('util'),
bemUtil = require('./util'),
LOGGER = require('./logger'),
isRequireable = bemUtil.isRequireable,

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(util.format(
'level module %s can not be found but required by the level %s%s\n',
path,
stack.length > 1? 'inheritance tree:\n\t': '',
stack.join('\n\t')));
}

stack.push(path);

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

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

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

requireLevel = function(path) {
Expand Down

0 comments on commit 7156865

Please sign in to comment.