Skip to content

Commit

Permalink
Replace php code in bundle file
Browse files Browse the repository at this point in the history
  • Loading branch information
hypermkt committed Feb 27, 2017
1 parent 93f9a3c commit 814e2f7
Showing 1 changed file with 61 additions and 61 deletions.
122 changes: 61 additions & 61 deletions copyAsMarkdown.spBundle/command.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,82 +9,82 @@
<?php
if (!isset($_ENV['TEST_ENV'])) {
$c = new CopyAsMarkdown();
$c->exec(fopen("php://stdin", "r"));
$c = new CopyAsMarkdown();
$c->exec(fopen('php://stdin', 'r'));
}
class CopyAsMarkdown
{
protected $_output;
protected $_columnCount;
protected $output;
protected $columnCount;
public function exec($stdin)
{
$cmd = 'echo ' . escapeshellarg($this->convert($this->read($stdin))) .' | __CF_USER_TEXT_ENCODING='.posix_getuid().':0x8000100:0x8000100 pbcopy';
exec($cmd);
}
protected function read($stdin)
{
$result = [];
while($row = fgetcsv($stdin, 0)) {
array_push($result, $row);
public function exec($stdin)
{
$cmd = 'echo ' . escapeshellarg($this->convert($this->read($stdin))) . ' | __CF_USER_TEXT_ENCODING=' . posix_getuid() . ':0x8000100:0x8000100 pbcopy';
exec($cmd);
}
return $result;
}
protected function convert(array $rows)
{
$this->_columnCount = $this->_calculateColumnCount($rows);
$columns = array_shift($rows);
$result = [];
$result[] =$this->_createHeaderRows($columns);
$result[] = $this->_createDataRows($rows);
return implode("\n", $result);
}
protected function _createHeaderRows(array $columns)
{
$result = [];
$str = '';
foreach ($columns as $column) {
$str .= "|" . $column;
protected function read($stdin)
{
$result = [];
while ($row = fgetcsv($stdin, 0)) {
array_push($result, $row);
}
return $result;
}
$result[] = $str;
$str = '';
for($i=0; $i<count($columns); $i++) {
$str .= "|---";
protected function convert(array $rows)
{
$this->columnCount = $this->calculateColumnCount($rows);
$columns = array_shift($rows);
$result = [];
$result[] = $this->createHeaderRows($columns);
$result[] = $this->createDataRows($rows);
return implode("\n", $result);
}
$result[] = $str;
return implode("\n", $result);
}
protected function createHeaderRows(array $columns)
{
$result = [];
$str = '';
foreach ($columns as $column) {
$str .= '|' . $column;
}
$result[] = $str;
$str = '';
for ($i = 0; $i < count($columns); $i++) {
$str .= '|---';
}
$result[] = $str;
return implode("\n", $result);
}
protected function _calculateColumnCount(array $rows)
{
$count = 0;
foreach ($rows as $row) {
$c = count($row);
if ($c > $count) {
$count = $c;
}
protected function calculateColumnCount(array $rows)
{
$count = 0;
foreach ($rows as $row) {
$c = count($row);
if ($c > $count) {
$count = $c;
}
}
return $count;
}
return $count;
}
protected function _createDataRows(array $rows)
{
$result = [];
foreach ($rows as $row) {
$str = '';
foreach ($row as $val) {
$str .= "|" . str_replace(array("\n", "\r"), '', nl2br($val));
}
$result[] = $str;
protected function createDataRows(array $rows)
{
$result = [];
foreach ($rows as $row) {
$str = '';
foreach ($row as $val) {
$str .= '|' . str_replace(array("\n", "\r"), '', nl2br($val));
}
$result[] = $str;
}
return implode("\n", $result);
}
return implode("\n", $result);
}
}</string>
<key>input</key>
<string>selectedtablerowsascsv</string>
Expand Down

0 comments on commit 814e2f7

Please sign in to comment.