mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
refactor: use _.assign
This commit is contained in:
@@ -38,9 +38,11 @@ var _engine = {
|
|||||||
return this.parser.parse(tokens);
|
return this.parser.parse(tokens);
|
||||||
},
|
},
|
||||||
render: function(tpl, ctx, opts) {
|
render: function(tpl, ctx, opts) {
|
||||||
opts = opts || {};
|
opts = _.assign({
|
||||||
opts.strict_variables = opts.strict_variables || false;
|
strict_variables: false,
|
||||||
opts.strict_filters = opts.strict_filters || false;
|
strict_filters: false,
|
||||||
|
root: []
|
||||||
|
}, opts);
|
||||||
this.renderer.initRegister(opts);
|
this.renderer.initRegister(opts);
|
||||||
var scope = Scope.factory(ctx, {
|
var scope = Scope.factory(ctx, {
|
||||||
strict: opts.strict_variables,
|
strict: opts.strict_variables,
|
||||||
@@ -59,7 +61,7 @@ var _engine = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
renderFile: function(filepath, ctx, opts) {
|
renderFile: function(filepath, ctx, opts) {
|
||||||
opts = opts || {};
|
opts = _.assign({}, opts);
|
||||||
return this.getTemplate(filepath, opts.root)
|
return this.getTemplate(filepath, opts.root)
|
||||||
.then(templates => this.render(templates, ctx, opts))
|
.then(templates => this.render(templates, ctx, opts))
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
@@ -122,7 +124,7 @@ var _engine = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function factory(options) {
|
function factory(options) {
|
||||||
options = options || {};
|
options = _.assign({}, options);
|
||||||
options.root = normalizeStringArray(options.root);
|
options.root = normalizeStringArray(options.root);
|
||||||
if (!options.root.length) options.root = ['.'];
|
if (!options.root.length) options.root = ['.'];
|
||||||
|
|
||||||
@@ -148,7 +150,8 @@ factory.evalValue = Syntax.evalValue;
|
|||||||
factory.Types = {
|
factory.Types = {
|
||||||
ParseError: Errors.ParseError,
|
ParseError: Errors.ParseError,
|
||||||
TokenizationEroor: Errors.TokenizationError,
|
TokenizationEroor: Errors.TokenizationError,
|
||||||
RenderBreak: Errors.RenderBreak
|
RenderBreak: Errors.RenderBreak,
|
||||||
|
AssertionError: Errors.AssertionError
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = factory;
|
module.exports = factory;
|
||||||
|
|||||||
+3
-2
@@ -148,8 +148,9 @@ function matchRightBracket(str, begin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.factory = function(_ctx, opts) {
|
exports.factory = function(_ctx, opts) {
|
||||||
opts = opts || {};
|
opts = _.assign({
|
||||||
opts.strict = opts.strict || false;
|
strict: false
|
||||||
|
}, opts);
|
||||||
|
|
||||||
var scope = Object.create(Scope);
|
var scope = Object.create(Scope);
|
||||||
scope.opts = opts;
|
scope.opts = opts;
|
||||||
|
|||||||
@@ -25,6 +25,14 @@ function forOwn(object, iteratee) {
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function assign(dst, src) {
|
||||||
|
dst = dst || {};
|
||||||
|
forOwn(src, function(v, k) {
|
||||||
|
dst[k] = v;
|
||||||
|
});
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
function isArray(value) {
|
function isArray(value) {
|
||||||
return value instanceof Array;
|
return value instanceof Array;
|
||||||
}
|
}
|
||||||
@@ -32,3 +40,4 @@ function isArray(value) {
|
|||||||
exports.isString = isString;
|
exports.isString = isString;
|
||||||
exports.isArray = isArray;
|
exports.isArray = isArray;
|
||||||
exports.forOwn = forOwn;
|
exports.forOwn = forOwn;
|
||||||
|
exports.assign = assign;
|
||||||
|
|||||||
Reference in New Issue
Block a user