diff --git a/src/SheetsTemplater.gs b/src/SheetsTemplater.gs index d9a3c21..3f0c973 100644 --- a/src/SheetsTemplater.gs +++ b/src/SheetsTemplater.gs @@ -3,6 +3,7 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) { REPLACE_TEXT: replaceValue, FOR_EACH: processForEach, INSERT_FORMULA: insertFormula, + COMPLETE_CELL: completeCell, NONE: function (properties) { return; } @@ -11,7 +12,9 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) { var annotationType = { '=': annotationFunctions.REPLACE_TEXT, '~': annotationFunctions.FOR_EACH, - '#': annotationFunctions.INSERT_FORMULA + '#': annotationFunctions.INSERT_FORMULA, + '*': annotationFunctions.COMPLETE_CELL + }; var _config = { folderId: '0B8cJhvYlR-sCcGR4d3VYWGZaYWM', @@ -179,6 +182,32 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) { sheet.getRange(row, col).setValue(getValueOnJson(json, command.substring(2, command.length - 1))); }; + function completeCell(properties) { + var row = properties.i + 1, + col = properties.j + 1, + command = properties.values[properties.i][properties.j], + sheet = properties.sheet, + json = properties.json, + cellProperties = getValueOnJson(json, command.substring(2, command.length - 1)), + range = sheet.getRange(row, col); + range.setValue(cellProperties.value); + if (cellProperties.backgroundColor) { + range.setBackground(cellProperties.backgroundColor); + } + if (cellProperties.textSize) { + range.setTextSize(cellProperties.textSize); + } + if (cellProperties.color) { + range.setColor(cellProperties.color); + } + if (cellProperties.borderStyle) { + range.setBorderStyle(cellProperties.borderStyle); + } + if (cellProperties.borderColor) { + range.setBorderColor(cellProperties.borderColor); + } + }; + function insertFormula(properties) { var row = properties.i + 1, col = properties.j + 1, diff --git a/test/annotationsTest.js b/test/annotationsTest.js index 7bbdf02..1e2a04c 100644 --- a/test/annotationsTest.js +++ b/test/annotationsTest.js @@ -38,34 +38,35 @@ var jsonMock = { } } }; + describe('QuickDrive functions', function () { describe('get new sheet', function () { it('it should return sheet with text replaced', function () { - var QuickDriveMock = QuickDriveConstructor(DriveApp(), SpreadsheetApp(matrixMockWithReplaceAnnotations)); + var QuickDriveMock = new QuickDriveConstructor(DriveApp(), SpreadsheetApp(matrixMockWithReplaceAnnotations)); var file = QuickDriveMock.processSheet(jsonMock); var range = file.sheet.getRange(1,1,2,2).getCells(); var firstCell = range[0][0]; var secondCell = range[0][1]; var thirdCell = range[1][0]; - assert.equal('the value', firstCell.getValue()); - assert.equal('rgb(100,100,100)', firstCell.getBackgroundColor()); + assert.equal('The value', firstCell.getValue()); + assert.equal('rgb(100,100,100)', firstCell.getBackground()); assert.equal('#F00', firstCell.getColor()); assert.equal(23, firstCell.getTextSize()); assert.equal('DOTTED', firstCell.getBorderStyle()); assert.equal('#00F', firstCell.getBorderColor()); assert.equal('my second value', secondCell.getValue()); - assert.equal('default', secondCell.getBackgroundColor()); + assert.equal('default', secondCell.getBackground()); assert.equal('#F00', secondCell.getColor()); assert.equal('default', secondCell.getTextSize()); - assert.equal('SOLID', secondCell.getBorderStyle()); + assert.equal('default', secondCell.getBorderStyle()); assert.equal('#00F', secondCell.getBorderColor()); assert.equal('', thirdCell.getValue()); - assert.equal('default', thirdCell.getBackgroundColor()); + assert.equal('default', thirdCell.getBackground()); assert.equal('default', thirdCell.getColor()); assert.equal(10, thirdCell.getTextSize()); - assert.equal('SOLID', thirdCell.getBorderStyle()); + assert.equal('default', thirdCell.getBorderStyle()); assert.equal('#00F', thirdCell.getBorderColor()); }); }); diff --git a/test/mock/SpreadsheetApp/Cell.js b/test/mock/SpreadsheetApp/Cell.js index 8e8bec8..8598256 100644 --- a/test/mock/SpreadsheetApp/Cell.js +++ b/test/mock/SpreadsheetApp/Cell.js @@ -1,36 +1,65 @@ var Cell = function (firstValue) { var value = firstValue || '', - backgroundColor = 'white', - borderStyle = 'SOLID'; + backgroundColor = 'default', + borderStyle = 'default', + color = 'default', + textSize = 'default', + borderColor = 'default'; var links = {}; + this.getValue = function () { + return value; + }; this.setValue = function (newValue) { value = newValue; }; this.setFormula = function (newValue) { value = newValue; }; - this.getValue = function () { - return value; + this.getBackground = function () { + return backgroundColor; }; - - this.setBackground = function(newBackground) { + this.setBackground = function (newBackground) { backgroundColor = newBackground; }; - this._configureLinks = function(newLinks) { + this.getBorderColor = function () { + return borderColor; + }; + this.setBorderColor = function (newBorderColor) { + borderColor = newBorderColor; + }; + this.getBorderStyle = function () { + return borderStyle; + }; + this.setBorderStyle = function (newBorderStyle) { + borderStyle = newBorderStyle; + }; + this.getColor = function () { + return color; + }; + this.setColor = function (newColor) { + color = newColor; + }; + this.getTextSize = function () { + return textSize; + }; + this.setTextSize = function (newTextSize) { + textSize = newTextSize; + }; + this._configureLinks = function (newLinks) { links = newLinks; }; - this._left = function() { + this._left = function () { return links.left; }; - this._bottom = function() { + this._bottom = function () { return links.bottom; }; - this._right = function() { + this._right = function () { return links.right; }; - this._top = function() { + this._top = function () { return links.top; }; }; diff --git a/test/mock/SpreadsheetApp/Range.js b/test/mock/SpreadsheetApp/Range.js index a7f78ef..bbbb0cd 100644 --- a/test/mock/SpreadsheetApp/Range.js +++ b/test/mock/SpreadsheetApp/Range.js @@ -13,16 +13,6 @@ var Range = function (myMatrix) { return values; }; - this.setValue = function (value) { - for (var i = 0; i < matrix.length; i++) { - for (var j = 0; j < matrix.length; j++) { - matrix[i][j].setValue(value); - } - } - }; - - this.setFormula = this.setValue; - this._getCells = function() { return matrix; }; @@ -40,9 +30,30 @@ var Range = function (myMatrix) { }; this.setBackground = function (background) { + setSomeValue(background, 'Background'); + }; + this.setValue = function (value) { + setSomeValue(value, 'Value'); + }; + this.setFormula = function (formula) { + setSomeValue(formula, 'Formula'); + }; + this.setTextSize = function (textSize) { + setSomeValue(textSize, 'TextSize'); + }; + this.setColor = function (color) { + setSomeValue(color, 'Color'); + }; + this.setBorderStyle = function (borderStyle) { + setSomeValue(borderStyle, 'BorderStyle'); + }; + this.setBorderColor = function (borderColor) { + setSomeValue(borderColor, 'BorderColor'); + }; + var setSomeValue = function(value, propertie) { for (var i = 0; i < matrix.length; i++) { for (var j = 0; j < matrix[0].length; j++) { - matrix[i][j].setBackground(background); + matrix[i][j]['set' + propertie](value); } } };