mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 06:50:47 -07:00
scope get all
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "shopify-liquid",
|
"name": "shopify-liquid",
|
||||||
"version": "1.1.8",
|
"version": "1.1.9",
|
||||||
"description": "A Shopify Liquid Implementation in Node.js",
|
"description": "A Shopify Liquid Implementation in Node.js",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -4,9 +4,16 @@ const error = require('./error.js');
|
|||||||
|
|
||||||
var scope = {
|
var scope = {
|
||||||
get: function(str) {
|
get: function(str) {
|
||||||
|
var ctx = {};
|
||||||
for (var i = this.scopes.length - 1; i >= 0; i--) {
|
for (var i = this.scopes.length - 1; i >= 0; i--) {
|
||||||
|
if(str === undefined){
|
||||||
|
_.merge(ctx, this.scopes[i]);
|
||||||
|
}
|
||||||
var v = _.get(this.scopes[i], str);
|
var v = _.get(this.scopes[i], str);
|
||||||
if (v !== undefined) return v;
|
if (v !== undefined) return v;
|
||||||
|
if(str === undefined){
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
set: function(k, v) {
|
set: function(k, v) {
|
||||||
|
|||||||
+10
-3
@@ -5,18 +5,25 @@ var expect = chai.expect;
|
|||||||
var Scope = require('../src/scope.js');
|
var Scope = require('../src/scope.js');
|
||||||
|
|
||||||
describe('scope', function() {
|
describe('scope', function() {
|
||||||
var scope;
|
var scope, ctx;
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
scope = Scope.factory({
|
ctx = {
|
||||||
foo: 'bar',
|
foo: 'bar',
|
||||||
bar: ['a', {b: [1, 2]}]
|
bar: ['a', {b: [1, 2]}]
|
||||||
});
|
};
|
||||||
|
scope = Scope.factory(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get property', function() {
|
it('should get property', function() {
|
||||||
scope.get('foo').should.equal('bar');
|
scope.get('foo').should.equal('bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should get all property', function() {
|
||||||
|
scope.get().should.deep.equal(ctx);
|
||||||
|
expect(scope.get('')).to.equal(undefined);
|
||||||
|
expect(scope.get(false)).to.equal(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
it('should set property', function() {
|
it('should set property', function() {
|
||||||
scope.set('foo', 'FOO');
|
scope.set('foo', 'FOO');
|
||||||
scope.get('foo').should.equal('FOO');
|
scope.get('foo').should.equal('FOO');
|
||||||
|
|||||||
Reference in New Issue
Block a user