Skip to content
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
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/View/Helper/BeautifierHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Cake\Essentials\View\Helper;

use Cake\View\Helper;
use Stringable;

/**
* A helper that provides methods to "beautify" the output of some specific entities and values.
Expand All @@ -28,6 +29,7 @@ class BeautifierHelper extends Helper
'ipAddress' => 'globe-americas',
'linux' => 'ubuntu',
'question' => 'question-circle-fill',
'time' => 'clock',
'unknownDevice' => 'question-circle-fill',
'windows' => 'windows',
],
Expand Down Expand Up @@ -96,6 +98,22 @@ public function questionTooltip(string|array $tooltip, array $options = []): str
return $this->_questionPopoverAndTooltip(options: compact('tooltip') + $options);
}

/**
* Returns a formatted time representation.
*
* @param \Stringable|string $text The time text or a stringable object representing time
* @param array<string, mixed> $options Additional options for formatting
* @return string The formatted time as a string
*/
public function time(Stringable|string $text, array $options = []): string
{
$options += [
'icon' => $this->getConfig('icon.time'),
];

return $this->Html->time(text: (string)$text, options: $options);
}

/**
* Returns the user agent, wrapped in a `code` tag and with icon.
*
Expand Down
11 changes: 11 additions & 0 deletions tests/TestCase/View/Helper/BeautifierHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ public function testQuestionTooltipWithCustomIconFromConfig(): void
$this->assertStringContainsString('<i class="opacity-75 text-body-tertiary fa fas-question"></i>', $result);
}

/**
* @link \Cake\Essentials\View\Helper\BeautifierHelper::time()
*/
#[Test]
public function testTime(): void
{
$expected = '<time><i class="bi bi-clock"></i> 12:34:56</time>';
$result = $this->Beautifier->time('12:34:56');
$this->assertSame($expected, $result);
}

/**
* @link \Cake\Essentials\View\Helper\BeautifierHelper::userAgent()
*/
Expand Down
Loading