Skip to content
This repository has been archived by the owner on Jun 15, 2019. It is now read-only.

Commit

Permalink
clean up old uses of init.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestalmage committed Dec 19, 2014
1 parent d040138 commit b6ae697
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
8 changes: 3 additions & 5 deletions src/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,7 @@ ColSpanCell.prototype.draw = function(){
return '';
};

ColSpanCell.prototype.init = function(tableOptions,x,y){
this.x = x;
this.y = y;
};
ColSpanCell.prototype.init = function(tableOptions){};


/**
Expand All @@ -263,7 +260,8 @@ function RowSpanCell(originalCell){
this.originalCell = originalCell;
}

RowSpanCell.prototype.init = function(tableOptions,x,y){
RowSpanCell.prototype.init = function(tableOptions){
var y = this.y;
var originalY = this.originalCell.y;
this.cellOffset = y - originalY;
this.offset = findDimension(tableOptions.rowHeights,originalY,this.cellOffset);
Expand Down
6 changes: 5 additions & 1 deletion src/layout-manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var _ = require('lodash');
var Cell = require('./cell');
var RowSpanCell = Cell.RowSpanCell;
var ColSpanCell = Cell.ColSpanCell;

(function(){

Expand Down Expand Up @@ -96,7 +97,10 @@ function addColSpanCells(cellRows){
for (var columnIndex = 0; columnIndex < cellColumns.length; columnIndex++) {
var cell = cellColumns[columnIndex];
for (var k = 1; k < cell.colSpan; k++) {
cellColumns.splice(columnIndex + 1, 0, new Cell.ColSpanCell());
var colSpanCell = new ColSpanCell();
colSpanCell.x = cell.x + k;
colSpanCell.y = cell.y;
cellColumns.splice(columnIndex + 1, 0, colSpanCell);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Table.prototype.toString = function(){

_.forEach(cells,function(row,rowIndex){
_.forEach(row,function(cell,cellIndex){
cell.init(this.options,cellIndex,rowIndex);
cell.init(this.options);
},this);
},this);

Expand Down
30 changes: 22 additions & 8 deletions test/cell-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ describe('Cell',function(){
cell = new Cell();
cell.y=1;
cell.mergeTableOptions(tableOptions);
cell.init(tableOptions,0,1);
cell.init(tableOptions);
expect(cell.height).to.equal(10);

cell = new Cell();
Expand Down Expand Up @@ -812,49 +812,63 @@ describe('Cell',function(){

it('drawing top of the next row',function(){
var spanner = new RowSpanCell(original);
spanner.init(tableOptions,0,1);
spanner.x = 0;
spanner.y = 1;
spanner.init(tableOptions);
spanner.draw('top');
expect(original.draw).to.have.been.calledOnce.and.calledWith(2);
});

it('drawing line 0 of the next row',function(){
var spanner = new RowSpanCell(original);
spanner.init(tableOptions,0,1);
spanner.x = 0;
spanner.y = 1;
spanner.init(tableOptions);
spanner.draw(0);
expect(original.draw).to.have.been.calledOnce.and.calledWith(3);
});

it('drawing line 1 of the next row',function(){
var spanner = new RowSpanCell(original);
spanner.init(tableOptions,0,1);
spanner.x = 0;
spanner.y = 1;
spanner.init(tableOptions);
spanner.draw(1);
expect(original.draw).to.have.been.calledOnce.and.calledWith(4);
});

it('drawing top of two rows below',function(){
var spanner = new RowSpanCell(original);
spanner.init(tableOptions,0,2);
spanner.x = 0;
spanner.y = 2;
spanner.init(tableOptions);
spanner.draw('top');
expect(original.draw).to.have.been.calledOnce.and.calledWith(6);
});

it('drawing line 0 of two rows below',function(){
var spanner = new RowSpanCell(original);
spanner.init(tableOptions,0,2);
spanner.x = 0;
spanner.y = 2;
spanner.init(tableOptions);
spanner.draw(0);
expect(original.draw).to.have.been.calledOnce.and.calledWith(7);
});

it('drawing line 1 of two rows below',function(){
var spanner = new RowSpanCell(original);
spanner.init(tableOptions,0,2);
spanner.x = 0;
spanner.y = 2;
spanner.init(tableOptions);
spanner.draw(1);
expect(original.draw).to.have.been.calledOnce.and.calledWith(8);
});

it('drawing bottom',function(){
var spanner = new RowSpanCell(original);
spanner.init(tableOptions,0,1);
spanner.x = 0;
spanner.y = 1;
spanner.init(tableOptions);
spanner.draw('bottom');
expect(original.draw).to.have.been.calledOnce.and.calledWith('bottom');
});
Expand Down

0 comments on commit b6ae697

Please sign in to comment.