Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Updates commit-related sources to use Commit class

AuthorDave Jarvis <email>
Date2026-02-22 17:57:59 GMT-0800
Commit6ff67fbc3751981fef3974576363e4588afb1fd2
Parenta8ea8a8
Commit.php
public function render( CommitRenderer $renderer ): void {
- $renderer->renderRow(
+ $renderer->render(
$this->sha,
$this->message,
}
}
+
pages/CommitsPage.php
require_once __DIR__ . '/../UrlBuilder.php';
require_once __DIR__ . '/../Commit.php';
-require_once __DIR__ . '/../render/CommitRenderer.php';
+require_once __DIR__ . '/../render/HtmlCommitRenderer.php';
-class CommitsPage extends BasePage implements CommitRenderer {
+class CommitsPage extends BasePage {
private const PER_PAGE = 100;
$this->renderPagination( $nav );
+
+ $renderer = new HtmlCommitRenderer(
+ $this->currentRepo['safe_name']
+ );
foreach( $commits as $commit ) {
- $commit->render( $this );
+ $commit->render( $renderer );
}
echo '</div>';
$this->renderPagination( $nav );
}
}, $this->currentRepo );
- }
-
- public function renderRow(
- string $sha,
- string $message,
- string $author,
- int $date
- ): void {
- $msg = htmlspecialchars( explode( "\n", $message )[0] );
- $url = (new UrlBuilder())
- ->withRepo( $this->currentRepo['safe_name'] )
- ->withAction( 'commit' )
- ->withHash( $sha )
- ->build();
-
- echo '<div class="commit-row">';
- echo '<a href="' . $url . '" class="sha">' .
- substr( $sha, 0, 7 ) . '</a>';
- echo '<span class="message">' . $msg . '</span>';
- echo '<span class="meta">' . htmlspecialchars( $author ) .
- ' &bull; ' . date( 'Y-m-d', $date ) . '</span>';
- echo '</div>';
}
-
- public function renderTime( int $timestamp ): void {}
private function renderPagination( array $nav ): void {
pages/HomePage.php
require_once __DIR__ . '/../UrlBuilder.php';
require_once __DIR__ . '/../Commit.php';
+require_once __DIR__ . '/../render/HtmlCommitRenderer.php';
class HomePage extends BasePage {
$this->git->history( 'HEAD', 1, function( Commit $c ) use( $repo ) {
- $renderer = new HtmlFileRenderer( $repo['safe_name'] );
+ $renderer = new HtmlCommitRenderer( $repo['safe_name'] );
$c->renderTime( $renderer );
render/CommitRenderer.php
<?php
interface CommitRenderer {
- public function renderRow(
+ public function render(
string $sha,
string $message,
string $author,
int $date
): void;
public function renderTime( int $timestamp ): void;
}
+
render/HtmlCommitRenderer.php
}
- public function renderRow(
+ public function render(
string $sha,
string $message,
string $author,
int $date
): void {
- $msg = \htmlspecialchars( \explode( "\n", $message )[0] );
+ $msg = htmlspecialchars( explode( "\n", $message )[0] );
$url = (new UrlBuilder())
->withRepo( $this->repoSafeName )
->withAction( 'commit' )
->withHash( $sha )
->build();
echo '<div class="commit-row">';
echo '<a href="' . $url . '" class="sha">' .
- \substr( $sha, 0, 7 ) . '</a>';
+ substr( $sha, 0, 7 ) . '</a>';
echo '<span class="message">' . $msg . '</span>';
- echo '<span class="meta">' . \htmlspecialchars( $author ) .
- ' &bull; ' . \date( 'Y-m-d', $date ) . '</span>';
+ echo '<span class="meta">' . htmlspecialchars( $author ) .
+ ' &bull; ' . date( 'Y-m-d', $date ) . '</span>';
echo '</div>';
}
public function renderTime( int $timestamp ): void {
- if( !$timestamp ) {
- echo 'never';
- return;
- }
-
- $diff = \time() - $timestamp;
-
- if( $diff < 5 ) {
- echo 'just now';
- return;
- }
-
$tokens = [
- 31536000 => 'year',
- 2592000 => 'month',
- 604800 => 'week',
- 86400 => 'day',
- 3600 => 'hour',
- 60 => 'minute',
- 1 => 'second'
+ 31536000 => 'year', 2592000 => 'month', 604800 => 'week',
+ 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second'
];
+ $diff = $timestamp ? time() - $timestamp : null;
+ $result = 'never';
- foreach( $tokens as $unit => $text ) {
- if( $diff < $unit ) {
- continue;
+ if( $diff && $diff >= 5 ) {
+ foreach( $tokens as $unit => $text ) {
+ if( $diff < $unit ) continue;
+ $num = floor( $diff / $unit );
+ $result = $num . ' ' . $text . ($num > 1 ? 's' : '') . ' ago';
+ break;
}
-
- $num = \floor( $diff / $unit );
-
- echo $num . ' ' . $text . ($num > 1 ? 's' : '') . ' ago';
- return;
+ } elseif( $diff ) {
+ $result = 'just now';
}
+
+ echo $result;
}
}
+
Delta33 lines added, 62 lines removed, 29-line decrease