context and identifier

This commit is contained in:
harttle
2016-06-14 00:31:24 +08:00
parent 5a33b4b84a
commit d502860ca9
6 changed files with 181 additions and 2 deletions
+26
View File
@@ -0,0 +1,26 @@
const _ = require('lodash');
const identifier = require('./identifier.js');
var context = {
get: function(str){
if(identifier.isLiteral(str)){
return identifier.parseLiteral(str);
}
if(identifier.isVariable(str)){
return _.get(this.context, str);
}
return '';
},
init: function(ctx){
this.context = ctx;
},
merge: function(ctx){
_.merge(this.context, ctx);
}
};
exports.factory = function(_ctx){
var ctx = Object.create(context);
ctx.init(_ctx);
return ctx;
};