mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 20:30:39 -07:00
27 lines
580 B
JavaScript
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;
|
|
};
|