Skip to content

Commit

Permalink
prepared 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rtmigo committed Mar 20, 2021
1 parent 5497243 commit f540b53
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 65 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.1.0-alpha

- Initial release
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Art Galkin <github.com/rtmigo>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
Dart library for easily displaying tabular data in a visually appealing
ASCII table format.

Tabular is specifically designed to create tables in the Markdown format that Github understands.
Tabular is specifically designed to create tables in the Markdown format that
GitHub understands.

The library is inspired by python's [tabulate](https://pypi.org/project/tabulate/)
and [pretty_table](https://pypi.org/project/prettytable/).
Expand Down Expand Up @@ -57,9 +58,6 @@ Winter | 12 | December | 31 | 258
```





# Formatting

### Add border
Expand Down Expand Up @@ -135,7 +133,7 @@ Winter | 12 | December | 31 | 258
### Sort by 'Days' descending, and then by 'Sun' ascending

``` dart
tabular(data, sort: [Sort('Days', false), Sort('Sun')])
tabular(data, sort: [Sort('Days', ascending: false), Sort('Sun')])
```

``` text
Expand Down
36 changes: 36 additions & 0 deletions example/example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:tabular/tabular.dart';

void main() {
var data = [
['Season', '#', 'Name', 'Days', 'Sun'],
['Winter', 1, 'January', 31, 94],
['Winter', 2, 'February', 28, 123],
['Spring', 3, 'March', 31, 42],
['Spring', 4, 'April', 30, 243],
['Spring', 5, 'May', 31, 5523],
['Summer', 6, 'June', 30, 11251],
['Summer', 7, 'July', 31, 17451],
['Summer', 8, 'August', 31, 18707],
['Autumn', 9, 'September', 30, 7025],
['Autumn', 10, 'October', 31, 5041],
['Autumn', 11, 'November', 30, 2302],
['Winter', 12, 'December', 31, 258],
];

String title(s) => '\n\n$s\n';

print(title('JUST TABLE'));
print(tabular(data));

print(title('WITH BORDER'));
print(tabular(data, outerBorder: true));

print(title('WITH MARKDOWN ":"'));
print(tabular(data, markdownAlign: true));

print(title('SORTED BY FIRST COLUMN'));
print(tabular(data, sort: [Sort(0)]));

print(title('SORTED BY TWO COLUMNS "DAYS" AND "SUN"'));
print(tabular(data, sort: [Sort('Days', ascending: false), Sort('Sun')]));
}
4 changes: 2 additions & 2 deletions lib/src/inner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Align {
}

class Sort {
Sort(this.column, [this.ascending = true]);
Sort(this.column, {this.ascending = true});

dynamic column;
bool ascending;
Expand Down Expand Up @@ -275,7 +275,7 @@ Iterable<dynamic> enumerateColumn(List<List<dynamic>> rows, int colIndex) sync*
}
}

/// @param sorting Determines the sorting order.
/// @param sort Determines the sorting order.
String tabular(List<List<dynamic>> rows,
{List<Side>? headerAlign,
List<Side>? rowAlign,
Expand Down
32 changes: 32 additions & 0 deletions pubpub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
set -e && cd "${0%/*}"

# creates a copy of the project in temporary directory
# and prepares the copy to be published

temp_pub_dir=$(mktemp -d -t pub-XXXXXXX)

echo "$temp_pub_dir"

rsync -Rrv ./ "$temp_pub_dir" \
--exclude=".git" \
--exclude="pubpub.sh" \
--exclude="todo.txt" \
--exclude="benchmark/" \
--exclude="reference/" \
--exclude="README.md" \
--exclude=".github" \
--exclude="labuda/" \
--exclude="draft/" \
--exclude="experiments"

# removing everything before "\n# ", the first header
old_readme=$(cat README.md | tr '\n' '\r')
new_readme=$(echo $old_readme | perl -p0e 's|^.*?\r# |# \1|' | tr '\r' '\n')
echo "$new_readme" > "$temp_pub_dir/README.md"

cd "$temp_pub_dir"
dartfmt -w .
dart pub publish --dry-run
#dart pub publish
#open "$temp_pub_dir"
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: tabular
description: Library for table formatting.
# version: 1.0.0
# homepage: https://www.example.com
description: Dart library for easily displaying tabular data in a visually appealing ASCII table format.
version: 0.1.0-alpha
repository: https://github.com/rtmigo/tabular

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
14 changes: 14 additions & 0 deletions test/common.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: (c) 2021 Art Galkin <github.com/rtmigo>
// SPDX-License-Identifier: MIT

String trimLR(String s, {onlyRight = false}) {
final strippedRows = s.split('\n').map((s) => onlyRight ? s.trimRight() : s.trim()).toList();
while (strippedRows.isNotEmpty && strippedRows.first.isEmpty) {
Expand All @@ -15,6 +18,17 @@ String trimR(String s) {
return trimLR(s, onlyRight: true);
}

final zdata = [
['Continent', 'Country', 'Islands', 'Population', 'Per island'],
['Europe', 'Norway', 55000, 5421241, 98.6],
['North America', 'Canada', 52455, 37742154, 719.5],
['Asia', 'Indonesia', 17508, 273523615, 15622.8],
['Europe', 'Finland', 188000, 5540720, 29.5],
['Asia', 'Japan', 6853, 126476461, 18455.6],
['Europe', 'Sweden', 221800, 10099265, 45.5],
];


final months = [
['Winter', 'Spring', 'Summer', 'Autumn'],
['December', 'March', 'June', 'September'],
Expand Down
50 changes: 0 additions & 50 deletions test/samples.dart

This file was deleted.

10 changes: 5 additions & 5 deletions test/sorting_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() {
});

test('by indices [1, 0] [asc, asc]', () {
final t = tabular(numbers, sort: [Sort(1, true), Sort(0, true)], outerBorder: true);
final t = tabular(numbers, sort: [Sort(1), Sort(0)], outerBorder: true);
//print(t);
expect(t, trimLR('''
| First | Second | Third |
Expand All @@ -37,7 +37,7 @@ void main() {
});

test('by indices [0, 1] [asc, asc]', () {
final t = tabular(numbers, sort: [Sort(0, true), Sort(1, true)], outerBorder: true);
final t = tabular(numbers, sort: [Sort(0), Sort(1)], outerBorder: true);
//print(t);
expect(t, trimLR('''
| First | Second | Third |
Expand All @@ -51,7 +51,7 @@ void main() {
});

test('by two indices, asc-desc', () {
final t = tabular(numbers, sort: [Sort(1, false), Sort(0, true)], outerBorder: true);
final t = tabular(numbers, sort: [Sort(1, ascending: false), Sort(0)], outerBorder: true);
expect(t, trimLR('''
| First | Second | Third |
|-------|--------|-------|
Expand All @@ -64,7 +64,7 @@ void main() {
});

test('by name, asc-desc', () {
final t = tabular(numbers, sort: [Sort('Second', false), Sort('First', true)], outerBorder: true);
final t = tabular(numbers, sort: [Sort('Second', ascending: false), Sort('First')], outerBorder: true);
//print(t);
expect(t, trimLR('''
| First | Second | Third |
Expand All @@ -78,7 +78,7 @@ void main() {
});

test('by name, asc-desc', () {
final t = tabular(numbers, sort: [Sort('Second', false), Sort('First', true)], outerBorder: true);
final t = tabular(numbers, sort: [Sort('Second', ascending: false), Sort('First')], outerBorder: true);
//print(t);
expect(t, trimLR('''
| First | Second | Third |
Expand Down

0 comments on commit f540b53

Please sign in to comment.