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