Files
liquidjs/context.js
T
2016-06-14 00:31:24 +08:00

27 lines
580 B
JavaScript

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;
};