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

Commit

Permalink
added basic-usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestalmage committed Dec 19, 2014
1 parent de54b0c commit e1aebb5
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 3 deletions.
2 changes: 1 addition & 1 deletion example.md → advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@


##### feel free to use colors in your content strings, column widths will be calculated correctly
![table image](https://cdn.rawgit.com/jamestalmage/cli-table2/aa38495e152ccf9893a36e43295a6aceb6f1043f/examples/screenshots/truncation-with-colors.png)
![table image](https://cdn.rawgit.com/jamestalmage/cli-table2/de54b0caeb4584dad16c9ad3067b07a850bc6657/examples/screenshots/truncation-with-colors.png)
```javascript
var table = new Table({colWidths:[5],style:{head:[],border:[]}});

Expand Down
99 changes: 99 additions & 0 deletions basic-usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
##### Basic Usage
┌──────┬─────────────────────┬─────────────────────────┬─────────────────┐
│ Rel │ Change │ By │ When │
├──────┼─────────────────────┼─────────────────────────┼─────────────────┤
│ v0.1 │ Testing something … │ rauchg@gmail.com │ 7 minutes ago │
├──────┼─────────────────────┼─────────────────────────┼─────────────────┤
│ v0.1 │ Testing something … │ rauchg@gmail.com │ 8 minutes ago │
└──────┴─────────────────────┴─────────────────────────┴─────────────────┘
```javascript
var table = new Table({
head: ['Rel', 'Change', 'By', 'When']
, style: {
'padding-left': 1
, 'padding-right': 1
, head: []
, border: []
}
, colWidths: [6, 21, 25, 17]
});

table.push(
['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago']
, ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago']
);

```


##### Create vertical tables by adding objects a single key that contains an array
┌────┬──────────────────────┐
│v0.1│Testing something cool│
├────┼──────────────────────┤
│v0.1│Testing something cool│
└────┴──────────────────────┘
```javascript
var table = new Table({ style: {'padding-left':0, 'padding-right':0, head:[], border:[]} });

table.push(
{'v0.1': 'Testing something cool'}
, {'v0.1': 'Testing something cool'}
);

```


##### Cross tables are similar to vertical tables, but include an empty string for the first header
┌────────┬────────┬──────────────────────┐
│ │Header 1│Header 2 │
├────────┼────────┼──────────────────────┤
│Header 3│v0.1 │Testing something cool│
├────────┼────────┼──────────────────────┤
│Header 4│v0.1 │Testing something cool│
└────────┴────────┴──────────────────────┘
```javascript
var table = new Table({ head: ["", "Header 1", "Header 2"], style: {'padding-left':0, 'padding-right':0, head:[], border:[]} }); // clear styles to prevent color output

table.push(
{"Header 3": ['v0.1', 'Testing something cool'] }
, {"Header 4": ['v0.1', 'Testing something cool'] }
);

```


##### Stylize the table with custom border characters
╔══════╤═════╤══════╗
║ foo │ bar │ baz ║
╟──────┼─────┼──────╢
║ frob │ bar │ quuz ║
╚══════╧═════╧══════╝
```javascript
var table = new Table({
chars: {
'top': ''
, 'top-mid': ''
, 'top-left': ''
, 'top-right': ''
, 'bottom': ''
, 'bottom-mid': ''
, 'bottom-left': ''
, 'bottom-right': ''
, 'left': ''
, 'left-mid': ''
, 'right': ''
, 'right-mid': ''
},
style: {
head: []
, border: []
}
});

table.push(
['foo', 'bar', 'baz']
, ['frob', 'bar', 'quuz']
);

```

125 changes: 125 additions & 0 deletions examples/basic-usage-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,129 @@ module.exports = function(runTest,screenshot) {
runTest(name, result[0], result[1]);
}

it('Basic Usage', function (){
function makeTable(){
var table = new Table({
head: ['Rel', 'Change', 'By', 'When']
, style: {
'padding-left': 1
, 'padding-right': 1
, head: []
, border: []
}
, colWidths: [6, 21, 25, 17]
});

table.push(
['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago']
, ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago']
);

return table;
}

var expected = [
'┌──────┬─────────────────────┬─────────────────────────┬─────────────────┐'
, '│ Rel │ Change │ By │ When │'
, '├──────┼─────────────────────┼─────────────────────────┼─────────────────┤'
, '│ v0.1 │ Testing something … │ rauchg@gmail.com │ 7 minutes ago │'
, '├──────┼─────────────────────┼─────────────────────────┼─────────────────┤'
, '│ v0.1 │ Testing something … │ rauchg@gmail.com │ 8 minutes ago │'
, '└──────┴─────────────────────┴─────────────────────────┴─────────────────┘'
];

return [makeTable,expected];
});


it('Create vertical tables by adding objects a single key that contains an array', function() {
function makeTable(){
var table = new Table({ style: {'padding-left':0, 'padding-right':0, head:[], border:[]} });

table.push(
{'v0.1': 'Testing something cool'}
, {'v0.1': 'Testing something cool'}
);

return table;
}

var expected = [
'┌────┬──────────────────────┐'
, '│v0.1│Testing something cool│'
, '├────┼──────────────────────┤'
, '│v0.1│Testing something cool│'
, '└────┴──────────────────────┘'
];

return [makeTable,expected];
});

it('Cross tables are similar to vertical tables, but include an empty string for the first header', function() {
function makeTable(){
var table = new Table({ head: ["", "Header 1", "Header 2"], style: {'padding-left':0, 'padding-right':0, head:[], border:[]} }); // clear styles to prevent color output

table.push(
{"Header 3": ['v0.1', 'Testing something cool'] }
, {"Header 4": ['v0.1', 'Testing something cool'] }
);

return table;
}

var expected = [
'┌────────┬────────┬──────────────────────┐'
, '│ │Header 1│Header 2 │'
, '├────────┼────────┼──────────────────────┤'
, '│Header 3│v0.1 │Testing something cool│'
, '├────────┼────────┼──────────────────────┤'
, '│Header 4│v0.1 │Testing something cool│'
, '└────────┴────────┴──────────────────────┘'
];

return [makeTable,expected];
});

it('Stylize the table with custom border characters', function (){
function makeTable(){
var table = new Table({
chars: {
'top': '═'
, 'top-mid': '╤'
, 'top-left': '╔'
, 'top-right': '╗'
, 'bottom': '═'
, 'bottom-mid': '╧'
, 'bottom-left': '╚'
, 'bottom-right': '╝'
, 'left': '║'
, 'left-mid': '╟'
, 'right': '║'
, 'right-mid': '╢'
},
style: {
head: []
, border: []
}
});

table.push(
['foo', 'bar', 'baz']
, ['frob', 'bar', 'quuz']
);

return table;
}

var expected = [
'╔══════╤═════╤══════╗'
, '║ foo │ bar │ baz ║'
, '╟──────┼─────┼──────╢'
, '║ frob │ bar │ quuz ║'
, '╚══════╧═════╧══════╝'
];

return [makeTable,expected];
});

};
8 changes: 6 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ gulp.task('example',function(){
* Do NOT run this in the same commit when you are adding images.
* Commit the images, then run this.
*/
gulp.task('example-md',function(cb){
printExample.mdExample(require('./examples/col-and-row-span-examples'),'example.md',cb);
gulp.task('example-md',['example-md-basic','example-md-advanced']);
gulp.task('example-md-basic',function(cb){
printExample.mdExample(require('./examples/basic-usage-examples'),'basic-usage.md',cb);
});
gulp.task('example-md-advanced',function(cb){
printExample.mdExample(require('./examples/col-and-row-span-examples'),'advanced-usage.md',cb);
});

function coverage(opts){
Expand Down

0 comments on commit e1aebb5

Please sign in to comment.