-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: mark count() methods as <0, max> range * feat: paginator
- Loading branch information
Showing
28 changed files
with
432 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the yassg project. | ||
* | ||
* (c) sigwin.hr | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sigwin\YASSG\Bridge\Twig\Extension; | ||
|
||
use Sigwin\YASSG\DatabaseProvider; | ||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
final class PaginatorExtension extends AbstractExtension | ||
{ | ||
private DatabaseProvider $provider; | ||
|
||
public function __construct(DatabaseProvider $provider) | ||
{ | ||
$this->provider = $provider; | ||
} | ||
|
||
public function getFunctions(): array | ||
{ | ||
return [ | ||
new TwigFunction('yassg_pages', function (string $name, ?string $condition = null, ?int $limit = null) { | ||
$database = $this->provider->getDatabase($name); | ||
$count = $database->count($condition); | ||
|
||
return range(1, ceil($count / ($limit ?? $database->getPageLimit()))); | ||
}), | ||
new TwigFunction('yassg_paginate', function (string $name, int $page, array $conditions = []) { | ||
$database = $this->provider->getDatabase($name); | ||
|
||
$conditions['limit'] ??= $database->getPageLimit(); | ||
$conditions['offset'] = ($page - 1) * $conditions['limit']; | ||
|
||
return $database->findAll(...$conditions); | ||
}), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: Lists! | ||
slug: lists | ||
publishedAt: "2022-07-19 12:13:00" | ||
--- | ||
|
||
## Ordered lists | ||
|
||
1. one | ||
2. two | ||
3. three | ||
|
||
## Unordered lists | ||
|
||
- a thing | ||
- another thing | ||
- yet another thing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
title: Paragraphs! | ||
slug: paragraphs | ||
publishedAt: "2022-07-19 12:09:00" | ||
--- | ||
Paragraph. | ||
|
||
Paragraph. | ||
|
||
Paragraph. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: Welcome to the world of tomorrow! | ||
slug: world-of-tomorrow | ||
publishedAt: "9999-12-31 23:59:59" | ||
--- | ||
Welcome! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: Titles! | ||
slug: titles | ||
publishedAt: "2022-07-19 12:11:00" | ||
--- | ||
|
||
# Title 1 | ||
|
||
## Title 2 | ||
|
||
### Title 3 | ||
|
||
#### Title 4 | ||
|
||
##### Title 5 | ||
|
||
###### Title 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
tests/functional/site/fixtures/en/article/lists/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<script src="https://cdn.tailwindcss.com?plugins=typography"></script> | ||
|
||
<title>Lists!</title> | ||
|
||
<link rel="stylesheet" href="/sub/dir/another/assets/app.d4da4e7e.css" integrity="sha384-t9qUhz8OfBEKvYdnnNndPZAf+S5Q3p0dBnxLn+5SShoNhInHUF+Bu8WJTo+FQJYJ"> | ||
</head> | ||
<body> | ||
|
||
<main class="min-h-full flex flex-col justify-center py-12 sm:px-6 lg:px-8"> | ||
<div class="mt-8 sm:mx-auto sm:w-full sm:max-w-xl"> | ||
<div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10 prose"> | ||
<h1>Lists!</h1> | ||
<p>19.07.2022. 12:13</p> | ||
<h2>Ordered lists</h2> | ||
<ol> | ||
<li>one</li> | ||
<li>two</li> | ||
<li>three</li> | ||
</ol> | ||
<h2>Unordered lists</h2> | ||
<ul> | ||
<li>a thing</li> | ||
<li>another thing</li> | ||
<li>yet another thing</li> | ||
</ul> | ||
|
||
</div> | ||
</div> | ||
</main> | ||
|
||
<script src="/sub/dir/another/assets/runtime.4d1205b9.js" integrity="sha384-J2jFm3DPgrcqyvls0fZlS51nUYgiBB+JLwWiU5v7vxEbLwKolmaHrRuz4BjP6qaE"></script><script src="/sub/dir/another/assets/app.9267444a.js" integrity="sha384-WbAUi92ziCGFD1kGZRzpOP8Nxymnw5vXM3szOB1JmBrCU+MVGXBRReCttizXHDdI"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.