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

Commit

Permalink
Break init into two stages 1) mergeTableOptions and 2) init
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestalmage committed Dec 15, 2014
1 parent 2f59df7 commit 87ec835
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 84 deletions.
29 changes: 16 additions & 13 deletions src/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ Cell.prototype.setOptions = function(options){
this.rowSpan = options.rowSpan || 1;
};

Cell.prototype.mergeTableOptions = function(tableOptions){
this.options.style = this.options.style || {};

if(this.options.chars){
this.chars = _.extend({},tableOptions.chars,this.options.chars);
}
else {
this.chars = tableOptions.chars;
}

this.truncate = this.options.truncate || tableOptions.truncate;

this.paddingLeft = findOption(this.options.style, tableOptions.style, 'paddingLeft', 'padding-left');
this.paddingRight = findOption(this.options.style, tableOptions.style, 'paddingRight', 'padding-right');
};

/**
* Initializes the Cells data structure.
*
Expand All @@ -37,25 +53,12 @@ Cell.prototype.setOptions = function(options){
* @param y - The row this cell is in (with row 0 being at the top).
*/
Cell.prototype.init = function(tableOptions, x, y){
this.options.style = this.options.style || {};
if(this.options.chars){
this.chars = _.extend({},tableOptions.chars,this.options.chars);
}
else {
this.chars = tableOptions.chars;
}

this.truncate = this.options.truncate || tableOptions.truncate;

this.width = findDimension(tableOptions.colWidths, x, this.colSpan);
this.height = findDimension(tableOptions.rowHeights, y, this.rowSpan);

this.hAlign = this.options.hAlign || tableOptions.colAligns[x];
this.vAlign = this.options.vAlign || tableOptions.rowAligns[y];

this.paddingLeft = findOption(this.options.style, tableOptions.style, 'paddingLeft', 'padding-left');
this.paddingRight = findOption(this.options.style, tableOptions.style, 'paddingRight', 'padding-right');

this.drawRight = x + this.colSpan == tableOptions.colWidths.length;

this.x = x;
Expand Down
3 changes: 1 addition & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,4 @@ module.exports = {
pad:pad,
truncate:truncate,
mergeOptions:mergeOptions
};

};
Loading

0 comments on commit 87ec835

Please sign in to comment.