Skip to content

Do not treat multivalue property values as a whole when truncating #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ dev-master

### Features

- [shell] Added "shell:clear" command to support clearing the console output
- [general] The shell supports being embedded as a dependency
- [node:edit] New command `node:edit` enables editing of entire node

### Bug Fixes

- [shell] Multivalue (and so multiline) property values are truncated as a single string (#70)

alpha-4
-------

Expand Down
8 changes: 8 additions & 0 deletions spec/PHPCR/Shell/Console/Helper/ResultFormatterHelperSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PHPCR\Shell\Console\Helper\TextHelper;

class ResultFormatterHelperSpec extends ObjectBehavior
{
function let(
TextHelper $textHelper
)
{
$this->beConstructedWith($textHelper);
}

function it_is_initializable()
{
$this->shouldHaveType('PHPCR\Shell\Console\Helper\ResultFormatterHelper');
Expand Down
5 changes: 3 additions & 2 deletions src/PHPCR/Shell/Console/Application/ShellApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,16 @@ public function init()
protected function registerHelpers()
{
$phpcrHelper = new PhpcrHelper($this->transportRegistry, $this->profile);
$textHelper = new TextHelper();

$helpers = array(
$textHelper,
new ConfigHelper(),
new EditorHelper(),
new NodeHelper(),
new PathHelper(),
new RepositoryHelper($phpcrHelper),
new ResultFormatterHelper(),
new TextHelper(),
new ResultFormatterHelper($textHelper),
new TableHelper(),
$phpcrHelper
);
Expand Down
2 changes: 1 addition & 1 deletion src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private function renderProperties($currentNode, $table, $spacers)
unset($propertyNames[$name]);
}

$valueCell = $this->textHelper->truncate($this->formatter->formatValue($property), 55);
$valueCell = $this->formatter->formatValue($property);

} catch (\Exception $e) {
$valueCell = '<error>' . $e->getMessage() . '</error>';
Expand Down
13 changes: 11 additions & 2 deletions src/PHPCR/Shell/Console/Helper/ResultFormatterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPCR\PropertyType;
use PHPCR\NodeInterface;
use PHPCR\PropertyInterface;
use PHPCR\Shell\Console\Helper\TextHelper;

/**
* Provide methods for formatting PHPCR objects
Expand All @@ -17,6 +18,13 @@
*/
class ResultFormatterHelper extends Helper
{
protected $textHelper;

public function __construct(TextHelper $textHelper)
{
$this->textHelper = $textHelper;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -87,7 +95,7 @@ public function normalizeValue($value)
} else {
$value = $value;
}
$value = '[' . $i . '] ' . $value;
$value = '[' . $i . '] ' . $this->textHelper->truncate($value);
$values[] = $value;
}

Expand All @@ -98,7 +106,7 @@ public function normalizeValue($value)
return $value->format('c');
}

return $value;
return $this->textHelper->truncate($value);
}

public function formatValue(PropertyInterface $value, $showBinary = false)
Expand Down Expand Up @@ -133,6 +141,7 @@ public function formatValue(PropertyInterface $value, $showBinary = false)
return $value->getValue()->getIdentifier();
case PropertyType::URI :
case PropertyType::STRING :
return $this->textHelper->truncate($value->getValue());
case PropertyType::NAME :
case PropertyType::LONG :
case PropertyType::DOUBLE :
Expand Down
12 changes: 11 additions & 1 deletion src/PHPCR/Shell/Console/Helper/TextHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
*/
class TextHelper extends Helper
{
/**
* @todo: Make this configurable
* @var integer
*/
protected $truncateLength = 75;

/**
* {@inheritDoc}
*/
Expand All @@ -29,8 +35,12 @@ public function getName()
*
* @return string
*/
public function truncate($string, $length, $alignment = null, $delimString = null)
public function truncate($string, $length = null, $alignment = null, $delimString = null)
{
if (null === $length) {
$length = $this->truncateLength;
}

$alignment = $alignment === null ? 'left' : $alignment;
$delimString = $delimString === null ? '...' : $delimString;
$delimLen = strlen($delimString);
Expand Down