mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 23:10:41 -07:00
change: remove deprecated features, coverall
This commit is contained in:
@@ -52,10 +52,6 @@ var _engine = {
|
|||||||
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))
|
||||||
},
|
},
|
||||||
evalOutput: function (str, scope) {
|
|
||||||
console.warn('[liquidjs:deprecated] use .evalValue() instead of .evalOutput')
|
|
||||||
return this.evalValue(str, scope)
|
|
||||||
},
|
|
||||||
evalValue: function (str, scope) {
|
evalValue: function (str, scope) {
|
||||||
var tpl = this.parser.parseValue(str.trim())
|
var tpl = this.parser.parseValue(str.trim())
|
||||||
return this.renderer.evalValue(tpl, scope)
|
return this.renderer.evalValue(tpl, scope)
|
||||||
|
|||||||
+10
-6
@@ -11,9 +11,6 @@ var Scope = {
|
|||||||
return ctx
|
return ctx
|
||||||
},
|
},
|
||||||
get: function (str) {
|
get: function (str) {
|
||||||
if (str === 'liquid') {
|
|
||||||
throw new Error('NO LONGER SUPPORTED: use scope.opts instead of scope.get("liquid")')
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
return this.getPropertyByPath(this.scopes, str)
|
return this.getPropertyByPath(this.scopes, str)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -129,12 +126,19 @@ function setPropertyByPath (obj, path, val) {
|
|||||||
var paths = (path + '').replace(/\[/g, '.').replace(/\]/g, '').split('.')
|
var paths = (path + '').replace(/\[/g, '.').replace(/\]/g, '').split('.')
|
||||||
for (var i = 0; i < paths.length; i++) {
|
for (var i = 0; i < paths.length; i++) {
|
||||||
var key = paths[i]
|
var key = paths[i]
|
||||||
|
if (!_.isObject(obj)) {
|
||||||
|
// cannot set property of non-object
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// for end point
|
||||||
if (i === paths.length - 1) {
|
if (i === paths.length - 1) {
|
||||||
return (obj[key] = val)
|
return (obj[key] = val)
|
||||||
}
|
}
|
||||||
if (undefined === obj[key]) obj[key] = {}
|
// if path not exist
|
||||||
// case for readonly objects
|
if (undefined === obj[key]) {
|
||||||
obj = obj[key] || {}
|
obj[key] = {}
|
||||||
|
}
|
||||||
|
obj = obj[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -63,7 +63,7 @@ function parse (input, file, options) {
|
|||||||
|
|
||||||
function parseHTMLToken (begin, end) {
|
function parseHTMLToken (begin, end) {
|
||||||
var htmlFragment = input.slice(begin, end)
|
var htmlFragment = input.slice(begin, end)
|
||||||
currIndent = _.last((htmlFragment || '').split('\n')).length
|
currIndent = _.last((htmlFragment).split('\n')).length
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'html',
|
type: 'html',
|
||||||
|
|||||||
@@ -121,6 +121,16 @@ describe('scope', function () {
|
|||||||
scope.set('bar.coo', 'COO')
|
scope.set('bar.coo', 'COO')
|
||||||
expect(scope.get('bar.coo')).to.equal('COO')
|
expect(scope.get('bar.coo')).to.equal('COO')
|
||||||
})
|
})
|
||||||
|
it('should keep other properties of parent', function () {
|
||||||
|
scope.push({obj: {foo: 'FOO'}})
|
||||||
|
scope.set('obj.bar', 'BAR')
|
||||||
|
expect(scope.get('obj.foo')).to.equal('FOO')
|
||||||
|
})
|
||||||
|
it('should abort if property cannot be set', function () {
|
||||||
|
scope.push({obj: {foo: 'FOO'}})
|
||||||
|
scope.set('obj.foo.bar', 'BAR')
|
||||||
|
expect(scope.get('obj.foo')).to.equal('FOO')
|
||||||
|
})
|
||||||
it("should set parents' corresponding value", function () {
|
it("should set parents' corresponding value", function () {
|
||||||
scope.push({})
|
scope.push({})
|
||||||
scope.set('foo', 'bar')
|
scope.set('foo', 'bar')
|
||||||
|
|||||||
Reference in New Issue
Block a user