Skip to content

Commit

Permalink
Add support for Primer CSS framework
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Sep 20, 2022
1 parent 45b07a7 commit 343c67f
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
'materialize-short',
'materialize1',
'materialize1-short',
'primer',
'primer-short',
'primer20',
'primer20-short',
'semantic-ui',
'semantic-ui-short',
'semantic-ui2',
Expand Down
1 change: 1 addition & 0 deletions guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ The Aplus Framework Pagination Library works with the following front-end framew
- `Bulma <https://bulma.io/>`_
- `Foundation <https://get.foundation/>`_
- `Materialize <https://materializecss.com/>`_
- `Primer <https://primer.style/>`_
- `Semantic UI <https://semantic-ui.com/>`_
- `Tailwind <https://tailwindcss.com/>`_

Expand Down
5 changes: 5 additions & 0 deletions src/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class Pager implements JsonSerializable
'materialize-short' => __DIR__ . '/Views/materialize-short.php',
'materialize1' => __DIR__ . '/Views/materialize.php',
'materialize1-short' => __DIR__ . '/Views/materialize-short.php',
// Primer 20
'primer' => __DIR__ . '/Views/primer.php',
'primer-short' => __DIR__ . '/Views/primer-short.php',
'primer20' => __DIR__ . '/Views/primer.php',
'primer20-short' => __DIR__ . '/Views/primer-short.php',
// Semantic UI 2
'semantic-ui' => __DIR__ . '/Views/semantic-ui.php',
'semantic-ui-short' => __DIR__ . '/Views/semantic-ui-short.php',
Expand Down
37 changes: 37 additions & 0 deletions src/Views/primer-short.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/*
* This file is part of Aplus Framework Pagination Library.
*
* (c) Natan Felles <natanfelles@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @var Framework\Pagination\Pager $pager
*/
$language = $pager->getLanguage();
?>
<nav class="paginate-container" aria-label="Pagination">
<div class="pagination">
<?php if ($pager->getPreviousPage()) : ?>
<a class="previous_page" rel="prev" href="<?= $pager->getPreviousPageUrl() ?>" aria-label="Previous Page">
<?= $language->render('pagination', 'previous') ?>
</a>
<?php else: ?>
<span class="previous_page" aria-disabled="true">
<?= $language->render('pagination', 'previous') ?>
</span>
<?php endif ?>

<?php if ($pager->getNextPage()) : ?>
<a class="next_page" rel="next" href="<?= $pager->getNextPageUrl() ?>" aria-label="Next Page">
<?= $language->render('pagination', 'next') ?>
</a>
<?php else: ?>
<span class="next_page" aria-disabled="true">
<?= $language->render('pagination', 'next') ?>
</span>
<?php endif ?>
</div>
</nav>
88 changes: 88 additions & 0 deletions src/Views/primer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/*
* This file is part of Aplus Framework Pagination Library.
*
* (c) Natan Felles <natanfelles@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @var Framework\Pagination\Pager $pager
*/
$language = $pager->getLanguage();
?>
<nav class="paginate-container" aria-label="Pagination">
<div class="pagination">

<?php if ($pager->getPreviousPage()) : ?>
<a class="previous_page" rel="prev" href="<?=
$pager->getPreviousPageUrl() ?>" aria-label="<?=
$language->render('pagination', 'previous') ?>"><?=
$language->render('pagination', 'previous') ?></a>
<?php else: ?>
<span class="previous_page" aria-disabled="true"><?=
$language->render('pagination', 'previous') ?></span>
<?php endif ?>

<?php
$page = array_key_first($pager->getPreviousPagesUrls());
?>
<?php if ($page > 1): ?>
<a href="<?= $pager->getFirstPageUrl() ?>" aria-label="Page <?= $pager->getFirstPage() ?>" title="<?=
$pager->getLanguage()->render('pagination', 'first') ?>">
<?= $pager->getFirstPage() ?>
</a>
<?php if ($page > 2): ?>
<a href="<?= $pager->getPageUrl(2) ?>" aria-label="Page 2">
2
</a>
<?php if ($page > 3): ?>
<span class="gap"></span>
<?php endif ?>
<?php endif ?>
<?php endif ?>

<?php foreach ($pager->getPreviousPagesUrls() as $p => $url) : ?>
<a href="<?= $url ?>" aria-label="Page <?= $p ?>"><?= $p ?></a>
<?php endforeach ?>

<em aria-current="page"><?= $pager->getCurrentPage() ?></em>

<?php foreach ($pager->getNextPagesUrls() as $p => $url) : ?>
<a href="<?= $url ?>" aria-label="Page <?= $p ?>"><?= $p ?></a>
<?php endforeach ?>

<?php
$page = array_key_last($pager->getNextPagesUrls());
$lastPage = $pager->getLastPage();
?>
<?php if ($page >= $pager->getCurrentPage()): ?>
<?php if ($page < $lastPage - 2): ?>
<span class="gap"></span>
<?php endif ?>
<?php if ($page < $lastPage - 1): ?>
<a href="<?= $pager->getPageUrl($lastPage - 1) ?>" aria-label="Page <?= $lastPage - 1 ?>">
<?= $lastPage - 1 ?>
</a>
<?php endif ?>
<?php if ($page < $lastPage): ?>
<a href="<?= $pager->getLastPageUrl() ?>" aria-label="Page <?= $pager->getLastPage() ?>" title="<?=
$pager->getLanguage()->render('pagination', 'last') ?>">
<?= $pager->getLastPage() ?>
</a>
<?php endif ?>
<?php endif ?>

<?php if ($pager->getNextPage() && $pager->getNextPage() < $pager->getLastPage() + 1) : ?>
<a class="next_page" rel="next" href="<?=
$pager->getNextPageUrl() ?>" aria-label="<?=
$language->render('pagination', 'next') ?>"><?=
$language->render('pagination', 'next') ?></a>
<?php else: ?>
<span class="next_page" aria-disabled="true"><?=
$language->render('pagination', 'next') ?></span>
<?php endif ?>

</div>
</nav>
67 changes: 67 additions & 0 deletions tests/PagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ public function testViews() : void
'materialize-short' => \realpath(__DIR__ . '/../src/Views/materialize-short.php'),
'materialize1' => \realpath(__DIR__ . '/../src/Views/materialize.php'),
'materialize1-short' => \realpath(__DIR__ . '/../src/Views/materialize-short.php'),
'primer' => \realpath(__DIR__ . '/../src/Views/primer.php'),
'primer-short' => \realpath(__DIR__ . '/../src/Views/primer-short.php'),
'primer20' => \realpath(__DIR__ . '/../src/Views/primer.php'),
'primer20-short' => \realpath(__DIR__ . '/../src/Views/primer-short.php'),
'semantic-ui' => \realpath(__DIR__ . '/../src/Views/semantic-ui.php'),
'semantic-ui-short' => \realpath(__DIR__ . '/../src/Views/semantic-ui-short.php'),
'semantic-ui2' => \realpath(__DIR__ . '/../src/Views/semantic-ui.php'),
Expand Down Expand Up @@ -297,6 +301,7 @@ public function viewsProvider() : array
['bulma'],
['foundation'],
['materialize'],
['primer'],
['semantic-ui'],
['tailwind'],
];
Expand All @@ -317,6 +322,68 @@ public function testPaginationViews(string $view) : void
self::assertStringContainsString('Last', $contents);
}

/**
* @return array<array<string>>
*/
public function previousDisabledProvider() : array
{
return [
['primer', 'aria-disabled="true"'],
['primer-short', 'aria-disabled="true"'],
];
}

/**
* @dataProvider previousDisabledProvider
*
* @runInSeparateProcess
*
* @param string $view
* @param string $needle
*/
public function testPreviousIsDisabled(string $view, string $needle) : void
{
$pager = new Pager(1, 10, 100);
$contents = $pager->render($view);
self::assertStringContainsString($needle, $contents);
}

/**
* @return array<array<string>>
*/
public function nextDisabledProvider() : array
{
return [
['primer', 'aria-disabled="true"'],
['primer-short', 'aria-disabled="true"'],
];
}

/**
* @dataProvider nextDisabledProvider
*
* @runInSeparateProcess
*
* @param string $view
* @param string $needle
*/
public function testNextIsDisabled(string $view, string $needle) : void
{
$pager = new Pager(10, 10, 100);
$contents = $pager->render($view);
self::assertStringContainsString($needle, $contents);
}

/**
* @runInSeparateProcess
*/
public function testPrimerGap() : void
{
$pager = new Pager(5, 10, 100);
$contents = $pager->render('primer');
self::assertStringContainsString('<span class="gap">…</span>', $contents);
}

/**
* @dataProvider viewsProvider
*
Expand Down

0 comments on commit 343c67f

Please sign in to comment.