mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 06:50:47 -07:00
feature: unshift and shift for scope, working on #15
This commit is contained in:
+7
-1
@@ -41,7 +41,13 @@ var Scope = {
|
|||||||
pop: function() {
|
pop: function() {
|
||||||
return this.scopes.pop();
|
return this.scopes.pop();
|
||||||
},
|
},
|
||||||
|
unshift: function(ctx) {
|
||||||
|
if (!ctx) throw new Error('trying to push $(ctx) into scopes');
|
||||||
|
return this.scopes.unshift(ctx);
|
||||||
|
},
|
||||||
|
shift: function() {
|
||||||
|
return this.scopes.shift();
|
||||||
|
},
|
||||||
setPropertyByPath: function(obj, path, val) {
|
setPropertyByPath: function(obj, path, val) {
|
||||||
if (_.isString(path)) {
|
if (_.isString(path)) {
|
||||||
var paths = path.replace(/\[/g, '.').replace(/\]/g, '').split('.');
|
var paths = path.replace(/\[/g, '.').replace(/\]/g, '').split('.');
|
||||||
|
|||||||
@@ -113,5 +113,17 @@ describe('scope', function() {
|
|||||||
scope.pop();
|
scope.pop();
|
||||||
expect(scope.get('foo')).to.equal('zoo');
|
expect(scope.get('foo')).to.equal('zoo');
|
||||||
});
|
});
|
||||||
|
it('should unshift scope', function() {
|
||||||
|
scope.unshift({foo: 'blue', foo1: 'foo1'})
|
||||||
|
scope.get('foo').should.equal('zoo');
|
||||||
|
scope.get('foo1').should.equal('foo1');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should shift scope', function() {
|
||||||
|
scope.unshift({foo: 'blue', foo1: 'foo1'});
|
||||||
|
scope.shift();
|
||||||
|
expect(scope.get('foo')).to.equal('zoo');
|
||||||
|
expect(scope.get('foo1')).to.equal(undefined);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user