Skip to content
This repository was archived by the owner on Jun 9, 2024. It is now read-only.

Commit 7c4da7e

Browse files
committed
clean up sub-classes and move html code to properties
1 parent 4e7cb41 commit 7c4da7e

File tree

4 files changed

+153
-226
lines changed

4 files changed

+153
-226
lines changed

src/Pagination.php

Lines changed: 114 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,52 @@ class Pagination implements PresenterContract {
2424
protected $window;
2525

2626
/**
27-
* Create a new Bootstrap presenter instance.
27+
* Pagination wrapper HTML.
2828
*
29-
* @param \Illuminate\Contracts\Pagination\Paginator $paginator
30-
* @param \Illuminate\Pagination\UrlWindow|null $window
31-
* @return void
29+
* @var string
30+
*/
31+
protected $paginationWrapper = '<ul class="pagination">%s %s %s</ul>';
32+
33+
/**
34+
* Available page wrapper HTML.
35+
*
36+
* @var string
37+
*/
38+
protected $availablePageWrapper = '<li><a href="%s">%s</a></li>';
39+
40+
/**
41+
* Get active page wrapper HTML.
42+
*
43+
* @var string
44+
*/
45+
protected $activePageWrapper = '<li class="active"><span>%s</span></li>';
46+
47+
/**
48+
* Get disabled page wrapper HTML.
49+
*
50+
* @var string
51+
*/
52+
protected $disabledPageWrapper = '<li class="disabled"><span>%s</span></li>';
53+
54+
/**
55+
* Previous button text.
56+
*
57+
* @var string
58+
*/
59+
protected $previousButtonText = '&laquo;';
60+
61+
/**
62+
* Next button text.
63+
*
64+
* @var string
65+
*/
66+
protected $nextButtonText = '&raquo;';
67+
68+
/**
69+
* Create a new Pagination presenter instance.
70+
*
71+
* @param \Illuminate\Contracts\Pagination\Paginator $paginator
72+
* @param \Illuminate\Pagination\UrlWindow|null $window
3273
*/
3374
public function __construct(PaginatorContract $paginator, UrlWindow $window = null)
3475
{
@@ -47,7 +88,61 @@ public function hasPages()
4788
}
4889

4990
/**
50-
* Convert the URL window into Bootstrap HTML.
91+
* Get pagination wrapper HTML.
92+
*
93+
* @return string
94+
*/
95+
protected function getPaginationWrapperHTML() {
96+
return $this->paginationWrapper;
97+
}
98+
99+
/**
100+
* Get available page wrapper HTML.
101+
*
102+
* @return string
103+
*/
104+
protected function getAvailablePageWrapperHTML() {
105+
return $this->availablePageWrapper;
106+
}
107+
108+
/**
109+
* Get active page wrapper HTML.
110+
*
111+
* @return string
112+
*/
113+
protected function getActivePageWrapperHTML() {
114+
return $this->activePageWrapper;
115+
}
116+
117+
/**
118+
* Get disabled page wrapper HTML.
119+
*
120+
* @return string
121+
*/
122+
protected function getDisabledPageWrapperHTML() {
123+
return $this->disabledPageWrapper;
124+
}
125+
126+
/**
127+
* Get previous button text.
128+
*
129+
* @return string
130+
*/
131+
protected function getPreviousButtonText() {
132+
return $this->previousButtonText;
133+
}
134+
135+
/**
136+
* Get next button text.
137+
*
138+
* @return string
139+
*/
140+
protected function getNextButtonText() {
141+
return $this->nextButtonText;
142+
}
143+
144+
/**
145+
* Convert the URL window into Pagination HTML.
51146
*
52147
* @return string
53148
*/
@@ -56,7 +151,7 @@ public function render()
56151
if ($this->hasPages())
57152
{
58153
return sprintf(
59-
'<ul class="pagination">%s %s %s</ul>',
154+
$this->getPaginationWrapperHTML(),
60155
$this->getPreviousButton(),
61156
$this->getLinks(),
62157
$this->getNextButton()
@@ -71,15 +166,11 @@ public function render()
71166
*
72167
* @param string $url
73168
* @param int $page
74-
* @param string|null $rel
75-
* @param string $class
76169
* @return string
77170
*/
78-
protected function getAvailablePageWrapper($url, $page, $rel = null, $class = '')
171+
protected function getAvailablePageWrapper($url, $page)
79172
{
80-
$rel = is_null($rel) ? '' : ' rel="'.$rel.'"';
81-
82-
return '<li class="'.$class.'"><a href="'.htmlentities($url).'"'.$rel.'>'.$page.'</a></li>';
173+
return sprintf($this->getAvailablePageWrapperHTML(),$url, $page);
83174
}
84175

85176
/**
@@ -90,7 +181,7 @@ protected function getAvailablePageWrapper($url, $page, $rel = null, $class = ''
90181
*/
91182
protected function getDisabledTextWrapper($text)
92183
{
93-
return '<li class="disabled"><span>'.$text.'</span></li>';
184+
return sprintf($this->getDisabledPageWrapperHTML(), $text);
94185
}
95186

96187
/**
@@ -101,7 +192,7 @@ protected function getDisabledTextWrapper($text)
101192
*/
102193
protected function getActivePageWrapper($text)
103194
{
104-
return '<li class="active"><span>'.$text.'</span></li>';
195+
return sprintf($this->getActivePageWrapperHTML(), $text);
105196
}
106197

107198
/**
@@ -139,60 +230,55 @@ protected function lastPage()
139230
*
140231
* @param string $url
141232
* @param int $page
142-
* @param string|null $rel
143-
* @param string $class
144233
* @return string
145234
*/
146-
protected function getPageLinkWrapper($url, $page, $rel = null, $class = '')
235+
protected function getPageLinkWrapper($url, $page)
147236
{
148237
if ($page == $this->paginator->currentPage())
149238
{
150239
return $this->getActivePageWrapper($page);
151240
}
152241

153-
return $this->getAvailablePageWrapper($url, $page, $rel, $class);
242+
return $this->getAvailablePageWrapper($url, $page);
154243
}
155244

156245
/**
157246
* Get the previous page pagination element.
158-
*
159-
* @param string $text
160247
* @return string
248+
* @internal param string $text
161249
*/
162-
protected function getPreviousButton($text = '&laquo;')
250+
protected function getPreviousButton()
163251
{
164252
// If the current page is less than or equal to one, it means we can't go any
165253
// further back in the pages, so we will render a disabled previous button
166254
// when that is the case. Otherwise, we will give it an active "status".
167255
if ($this->paginator->currentPage() <= 1) {
168-
return $this->getDisabledTextWrapper($text);
256+
return $this->getDisabledTextWrapper($this->getPreviousButtonText());
169257
}
170258

171259
$url = $this->paginator->url(
172260
$this->paginator->currentPage() - 1
173261
);
174262

175-
return $this->getPageLinkWrapper($url, $text, 'prev');
263+
return $this->getPageLinkWrapper($url, $this->getPreviousButtonText());
176264
}
177265

178266
/**
179267
* Get the next page pagination element.
180-
*
181-
* @param string $text
182268
* @return string
183269
*/
184-
protected function getNextButton($text = '&raquo;')
270+
protected function getNextButton()
185271
{
186272
// If the current page is greater than or equal to the last page, it means we
187273
// can't go any further into the pages, as we're already on this last page
188274
// that is available, so we will make it the "next" link style disabled.
189275
if (!$this->paginator->hasMorePages()) {
190-
return $this->getDisabledTextWrapper($text);
276+
return $this->getDisabledTextWrapper($this->getNextButtonText());
191277
}
192278

193279
$url = $this->paginator->url($this->paginator->currentPage() + 1);
194280

195-
return $this->getPageLinkWrapper($url, $text, 'next');
281+
return $this->getPageLinkWrapper($url, $this->getNextButtonText());
196282
}
197283

198284
}

src/SemanticUI.php

Lines changed: 18 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,104 +3,45 @@
33
class SemanticUI extends Pagination {
44

55
/**
6-
* Convert the URL window into Bootstrap HTML.
6+
* Pagination wrapper HTML.
77
*
8-
* @return string
8+
* @var string
99
*/
10-
public function render()
11-
{
12-
if ($this->hasPages())
13-
{
14-
return sprintf(
15-
'<div class="ui pagination menu">%s %s %s</div>',
16-
$this->getPreviousButton(),
17-
$this->getLinks(),
18-
$this->getNextButton()
19-
);
20-
}
21-
22-
return '';
23-
}
10+
protected $paginationWrapper = '<div class="ui pagination menu">%s %s %s</div>';
2411

2512
/**
26-
* Get HTML wrapper for an available page link.
13+
* Available page wrapper HTML.
2714
*
28-
* @param string $url
29-
* @param int $page
30-
* @param string|null $rel
31-
* @param string $class
32-
* @return string
15+
* @var string
3316
*/
34-
protected function getAvailablePageWrapper($url, $page, $rel = null, $class = 'item')
35-
{
36-
$rel = is_null($rel) ? '' : ' rel="'.$rel.'"';
37-
38-
return '<a class="item'.($class ? ' ' . $class : '').'" href="'.htmlentities($url).'"'.$rel.'>'.$page.'</a>';
39-
}
17+
protected $availablePageWrapper = '<a href="%s" class="item">%s</a>';
4018

4119
/**
42-
* Get HTML wrapper for disabled text.
20+
* Get active page wrapper HTML.
4321
*
44-
* @param string $text
45-
* @param string $class
46-
* @return string
22+
* @var string
4723
*/
48-
protected function getDisabledTextWrapper($text, $class = '')
49-
{
50-
return '<div class="item disabled'.( $class ? ' ' .$class : '').'">'.$text.'</div>';
51-
}
24+
protected $activePageWrapper = '<div class="item active">%s</div>';
5225

5326
/**
54-
* Get HTML wrapper for active text.
27+
* Get disabled page wrapper HTML.
5528
*
56-
* @param string $text
57-
* @return string
29+
* @var string
5830
*/
59-
protected function getActivePageWrapper($text)
60-
{
61-
return '<div class="item active">'.$text.'</div>';
62-
}
31+
protected $disabledPageWrapper = '<div class="item disabled">%s</div>';
6332

6433
/**
65-
* Get the previous page pagination element.
34+
* Previous button text.
6635
*
67-
* @param string $text
68-
* @return string
36+
* @var string
6937
*/
70-
protected function getPreviousButton($text = '<i class="left arrow icon"></i>')
71-
{
72-
// If the current page is less than or equal to one, it means we can't go any
73-
// further back in the pages, so we will render a disabled previous button
74-
// when that is the case. Otherwise, we will give it an active "status".
75-
if ($this->paginator->currentPage() <= 1) {
76-
return $this->getDisabledTextWrapper($text, 'icon');
77-
}
78-
79-
$url = $this->paginator->url(
80-
$this->paginator->currentPage() - 1
81-
);
82-
83-
return $this->getPageLinkWrapper($url, $text, null, 'icon');
84-
}
38+
protected $previousButtonText = '<i class="left arrow icon"></i>';
8539

8640
/**
87-
* Get the next page pagination element.
41+
* Next button text.
8842
*
89-
* @param string $text
90-
* @return string
43+
* @var string
9144
*/
92-
protected function getNextButton($text = '<i class="right arrow icon"></i>')
93-
{
94-
// If the current page is greater than or equal to the last page, it means we
95-
// can't go any further into the pages, as we're already on this last page
96-
// that is available, so we will make it the "next" link style disabled.
97-
if (!$this->paginator->hasMorePages()) {
98-
return $this->getDisabledTextWrapper($text, 'icon');
99-
}
100-
101-
$url = $this->paginator->url($this->paginator->currentPage() + 1);
102-
103-
return $this->getPageLinkWrapper($url, $text, null, 'icon');
104-
}
45+
protected $nextButtonText = '<i class="right arrow icon"></i>';
10546

10647
}

0 commit comments

Comments
 (0)