mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 14:00:39 -07:00
context and identifier
This commit is contained in:
+26
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user