Skip to content

Commit

Permalink
New matrix annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusmr13 committed Aug 11, 2016
1 parent bb72c70 commit 06bd1aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/SheetsTemplater.gs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) {
FOR_EACH: processForEach,
INSERT_FORMULA: insertFormula,
COMPLETE_CELL: completeCell,
SET_MATRIX: setMatrix,
NONE: function (properties) {
return;
}
Expand All @@ -13,7 +14,8 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) {
'=': annotationFunctions.REPLACE_TEXT,
'~': annotationFunctions.FOR_EACH,
'#': annotationFunctions.INSERT_FORMULA,
'*': annotationFunctions.COMPLETE_CELL
'*': annotationFunctions.COMPLETE_CELL,
'+': annotationFunctions.SET_MATRIX

};
var _config = {
Expand Down Expand Up @@ -97,7 +99,6 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) {
};

var getAnnotationType = function (text) {

if (isAnottation(text)) {
if (isValidAnnotation(text.split(':')[0])) {
return annotationType[text[1]] || annotationFunctions.NONE;
Expand Down Expand Up @@ -216,6 +217,16 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) {
setCellProperties(sheet, cellProperties);
};

function setMatrix(properties) {
var row = properties.i + 1,
col = properties.j + 1,
sheet = properties.sheet,
json = properties.json;
if (typeof json == 'array' && json[0] && typeof json[0] == 'array') {
sheet.getRange(row, col, json.length, json[0].length).setValue(json);
}
};

function insertFormula(properties) {
var row = properties.i + 1,
col = properties.j + 1,
Expand Down
5 changes: 5 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ describe('QuickDrive functions', function () {
assert.equal(QuickDrive.annotationFunctions.INSERT_FORMULA, QuickDrive.getAnnotationType('{#my.formula}'));
assert.equal(QuickDrive.annotationFunctions.INSERT_FORMULA, QuickDrive.getAnnotationType('{#foo.bar.with.many.properties.myList}'));
});
it('it should set matrix annotation', function () {
assert.equal(QuickDrive.annotationFunctions.SET_MATRIX, QuickDrive.getAnnotationType('{+myMatrix}'));
assert.equal(QuickDrive.annotationFunctions.SET_MATRIX, QuickDrive.getAnnotationType('{+my.matrix}'));
assert.equal(QuickDrive.annotationFunctions.SET_MATRIX, QuickDrive.getAnnotationType('{+foo.bar.with.many.properties.myMatrix}'));
});
});
describe('validateConfig', function () {
var createQuickDriveWithConfig = function (propertie, value) {
Expand Down

0 comments on commit 06bd1aa

Please sign in to comment.