Comparing version 0.2.0 to 0.3.0
'use strict'; | ||
var Spreadsheet = require('./spreadsheet.js'); | ||
var RedisGrilleStorage = require('./storage/redis.js'); | ||
var Grille = function(spreadsheet_id, storage, timeout) { | ||
this.spreadsheet_id = spreadsheet_id; | ||
this.storage = storage; | ||
this.storage = storage || new RedisGrilleStorage(); | ||
this.timeout = timeout; | ||
@@ -9,0 +10,0 @@ this.content = {}; |
@@ -122,18 +122,16 @@ 'use strict'; | ||
var destination = self.meta[collection].collection; | ||
var path = self.meta[collection].collection; | ||
if (type === 'hash') { | ||
self.content[destination] = data; | ||
Spreadsheet.dotSet(self.content, data, path); | ||
} else if (type === 'keyvalue') { | ||
var new_data = Spreadsheet.extractKeyValue(data); | ||
if (!self.content[destination]) { | ||
self.content[destination] = {}; | ||
if (!self.content[path]) { | ||
self.content[path] = {}; | ||
} | ||
// TODO: Break up object on .'s | ||
_.extend(self.content[destination], new_data); | ||
Spreadsheet.dotMerge(self.content, new_data, path); | ||
} else if (type === 'array') { | ||
// TODO: Break up object on .'s | ||
self.content[destination] = Spreadsheet.extractArray(data); | ||
Spreadsheet.dotSet(self.content, Spreadsheet.extractArray(data), path); | ||
} | ||
@@ -168,2 +166,51 @@ | ||
/** | ||
* Sets data in a deep object using dot notation | ||
* | ||
* @param destination Object Tree where we want to put the source | ||
* @param source Mixed What we want to stick in the destination object | ||
* @param path String The location in the tree to put the source, such that x.y.z => destination.x.y.z = source | ||
*/ | ||
Spreadsheet.dotSet = function(destination, source, path) { | ||
var nodes = path.split("."); // e.g. x, y, z | ||
var pointer = destination; | ||
for (var i = 0; i < nodes.length - 1; i++) { | ||
if (!pointer[nodes[i]]) { | ||
pointer[nodes[i]] = {}; | ||
} | ||
pointer = pointer[nodes[i]]; | ||
} | ||
pointer[nodes[nodes.length-1]] = source; | ||
return destination; | ||
}; | ||
/** | ||
* Merges data in a deep object using dot notation | ||
* | ||
* @param destination Object Tree where we want to merge the source | ||
* @param source Mixed What we want to stick in the destination object | ||
* @param path String The location in the tree to put the source, such that x.y.z => destination.x.y.z = source | ||
*/ | ||
Spreadsheet.dotMerge = function(destination, source, path) { | ||
var nodes = path.split("."); // e.g. x, y, z | ||
var pointer = destination; | ||
for (var i = 0; i < nodes.length; i++) { | ||
if (!pointer[nodes[i]]) { | ||
pointer[nodes[i]] = {}; | ||
} | ||
pointer = pointer[nodes[i]]; | ||
} | ||
_.extend(pointer, source); | ||
return destination; | ||
}; | ||
Spreadsheet.ValidationError = ValidationError; | ||
@@ -170,0 +217,0 @@ Spreadsheet.TimeoutError = TimeoutError; |
{ | ||
"name": "grille", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Simple CMS using Google Spreadsheets", | ||
@@ -5,0 +5,0 @@ "main": "lib/grille.js", |
@@ -73,2 +73,93 @@ 'use strict'; | ||
it("dotSet() simple", function() { | ||
var destination = {}; | ||
var source = 'banana'; | ||
var path = 'x'; | ||
Spreadsheet.dotSet(destination, source, path); | ||
assert.deepEqual(destination, { | ||
x: 'banana' | ||
}); | ||
}); | ||
it("dotSet()", function() { | ||
var destination = { | ||
x: { | ||
b: 1 | ||
}, | ||
a: 2 | ||
}; | ||
var source = 'banana'; | ||
var path = 'x.y.z'; | ||
Spreadsheet.dotSet(destination, source, path); | ||
assert.deepEqual(destination, { | ||
x: { | ||
b: 1, | ||
y: { | ||
z: 'banana' | ||
} | ||
}, | ||
a: 2 | ||
}); | ||
}); | ||
it("dotMerge() simple", function() { | ||
var destination = {}; | ||
var source = { | ||
a: 1, | ||
b: 2 | ||
}; | ||
var path = 'x'; | ||
Spreadsheet.dotMerge(destination, source, path); | ||
assert.deepEqual(destination, { | ||
x: { | ||
a: 1, | ||
b: 2 | ||
} | ||
}); | ||
}); | ||
it("dotMerge()", function() { | ||
var destination = { | ||
x: { | ||
b: 1, | ||
keyval: { | ||
dog: 1, | ||
cat: 2, | ||
fish: 3 | ||
} | ||
}, | ||
a: 2 | ||
}; | ||
var source = { | ||
fish: 4, | ||
frog: 5, | ||
horse: 6 | ||
}; | ||
var path = 'x.keyval'; | ||
Spreadsheet.dotMerge(destination, source, path); | ||
assert.deepEqual(destination, { | ||
x: { | ||
b: 1, | ||
keyval: { | ||
dog: 1, | ||
cat: 2, | ||
fish: 4, | ||
frog: 5, | ||
horse: 6 | ||
} | ||
}, | ||
a: 2 | ||
}); | ||
}); | ||
describe("integration tests", function() { | ||
@@ -91,6 +182,5 @@ this.timeout(10 * 1000); | ||
// TODO: These should be split on .'s | ||
assert.deepEqual(spreadsheet.get('levels.0'), data['levels.0']); | ||
assert.deepEqual(spreadsheet.get('levels.1'), data['levels.1']); | ||
assert.deepEqual(spreadsheet.get('levels.secret'), data['levels.secret']); | ||
assert.deepEqual(spreadsheet.get('levels', 0), data.levels[0]); | ||
assert.deepEqual(spreadsheet.get('levels', 1), data.levels[1]); | ||
assert.deepEqual(spreadsheet.get('levels', 'secret'), data.levels.secret); | ||
@@ -97,0 +187,0 @@ assert.deepEqual(spreadsheet.toJSON(), data); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
43023
1198
0