mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
refactor: merge render register into scope
This commit is contained in:
+2
-7
@@ -42,7 +42,7 @@ var render = {
|
||||
if (template.name === 'break') {
|
||||
return Promise.reject(new RenderBreak('break'));
|
||||
}
|
||||
return template.render(scope, this.register);
|
||||
return template.render(scope);
|
||||
},
|
||||
|
||||
evalOutput: function(template, scope) {
|
||||
@@ -50,7 +50,7 @@ var render = {
|
||||
var val = Syntax.evalExp(template.initial, scope);
|
||||
template.filters.some(filter => {
|
||||
if (filter.error) {
|
||||
if (this.register.strict_filters) {
|
||||
if (scope.get('liquid.strict_filters')) {
|
||||
throw filter.error;
|
||||
} else {
|
||||
val = ''
|
||||
@@ -60,16 +60,11 @@ var render = {
|
||||
val = filter.render(val, scope);
|
||||
});
|
||||
return val;
|
||||
},
|
||||
|
||||
initRegister: function(opts) {
|
||||
return this.register = opts;
|
||||
}
|
||||
};
|
||||
|
||||
function factory() {
|
||||
var instance = Object.create(render);
|
||||
instance.register = {};
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
+6
-3
@@ -26,7 +26,7 @@ var Scope = {
|
||||
},
|
||||
get: function(str) {
|
||||
var val = this.safeGet(str);
|
||||
if (val === undefined && this.opts.strict) {
|
||||
if (val === undefined && this.opts.strict_variables) {
|
||||
throw new Error(`[strict_variables] undefined variable: ${str}`);
|
||||
}
|
||||
return val;
|
||||
@@ -149,9 +149,12 @@ function matchRightBracket(str, begin) {
|
||||
|
||||
exports.factory = function(ctx, opts) {
|
||||
opts = _.assign({
|
||||
strict: false,
|
||||
blocks: {}
|
||||
strict_variables: false,
|
||||
strict_filters: false,
|
||||
blocks: {},
|
||||
root: []
|
||||
}, opts);
|
||||
|
||||
ctx = _.assign(ctx, {
|
||||
liquid: opts
|
||||
});
|
||||
|
||||
+2
-2
@@ -18,9 +18,9 @@ module.exports = function() {
|
||||
var tagImpls = {};
|
||||
|
||||
var _tagInstance = {
|
||||
render: function(scope, register) {
|
||||
render: function(scope) {
|
||||
var obj = hash(this.token.args, scope);
|
||||
return this.tagImpl.render && this.tagImpl.render(scope, obj, register) || Promise.resolve('');
|
||||
return this.tagImpl.render && this.tagImpl.render(scope, obj) || Promise.resolve('');
|
||||
},
|
||||
parse: function(token, tokens){
|
||||
this.type = 'tag';
|
||||
|
||||
Reference in New Issue
Block a user