Skip to content

Commit

Permalink
Merge pull request #3 from ravelll/fix-1column-tabling
Browse files Browse the repository at this point in the history
Fix 1 column tabling
  • Loading branch information
hypermkt authored Feb 27, 2017
2 parents afb29fd + ef81ebd commit a54936a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
15 changes: 3 additions & 12 deletions copyAsMarkdown.spBundle/command.plist
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,13 @@ class CopyAsMarkdown
$result = [];
$str = '';
foreach ($columns as $column) {
if (!empty($str)) {
$str .= "|";
}
$str .= $column;
$str .= "|" . $column;
}
$result[] = $str;
$str = '';
for($i=0; $i<count($columns); $i++) {
if (!empty($str)) {
$str .= "|";
}
$str .= "---";
$str .= "|---";
}
$result[] = $str;
Expand All @@ -85,10 +79,7 @@ class CopyAsMarkdown
foreach ($rows as $row) {
$str = '';
foreach ($row as $val) {
if (!empty($str)) {
$str .= "|";
}
$str .= str_replace(array("\n", "\r"), '', nl2br($val));
$str .= "|" . str_replace(array("\n", "\r"), '', nl2br($val));
}
$result[] = $str;
}
Expand Down
15 changes: 3 additions & 12 deletions lib/CopyAsMarkdown/CopyAsMarkdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,13 @@ protected function _createHeaderRows(array $columns)
$result = [];
$str = '';
foreach ($columns as $column) {
if (!empty($str)) {
$str .= "|";
}
$str .= $column;
$str .= "|" . $column;
}
$result[] = $str;

$str = '';
for($i=0; $i<count($columns); $i++) {
if (!empty($str)) {
$str .= "|";
}
$str .= "---";
$str .= "|---";
}
$result[] = $str;

Expand All @@ -78,10 +72,7 @@ protected function _createDataRows(array $rows)
foreach ($rows as $row) {
$str = '';
foreach ($row as $val) {
if (!empty($str)) {
$str .= "|";
}
$str .= str_replace(array("\n", "\r"), '', nl2br($val));
$str .= "|" . str_replace(array("\n", "\r"), '', nl2br($val));
}
$result[] = $str;
}
Expand Down
24 changes: 19 additions & 5 deletions tests/lib/CopyAsMarkdown/CopyAsMarkdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ public function setUp()

public function testCreateHeaderRows()
{
$expected = 'hoge|fuga
---|---';
$expected = '|hoge|fuga
|---|---';
$this->assertEquals($expected, $this->copyAsMarkdown->createHeaderRows(array('hoge', 'fuga')));
}

public function testCreateHeaderRows_WhenHasOneColumn()
{
$expected = '|hoge
|---';
$this->assertEquals($expected, $this->copyAsMarkdown->createHeaderRows(array('hoge')));
}

public function testCalculateColumnCount()
{
Expand All @@ -26,17 +32,25 @@ public function testCalculateColumnCount()

public function testCreateDataRows()
{
$expected = 'a|b|c
d|e|f';
$expected = '|a|b|c
|d|e|f';
$this->assertEquals($expected, $this->copyAsMarkdown->createDataRows(array(
array('a', 'b', 'c'),
array('d', 'e', 'f'),
)));
}

public function testCreateDataRows_WhenHasOneColumn()
{
$expected = '|a';
$this->assertEquals($expected, $this->copyAsMarkdown->createDataRows(array(
array('a'),
)));
}

public function testCreateDataRows_ReturnLineFeedRemovedData_WhenHasLineFeedInData()
{
$expected = 'a|b1<br />b2<br />b3|c';
$expected = '|a|b1<br />b2<br />b3|c';
$this->assertEquals($expected, $this->copyAsMarkdown->createDataRows(array(
array('a', 'b1
b2
Expand Down

0 comments on commit a54936a

Please sign in to comment.