This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/lib/Rails/ActionView/Helper/WillPaginate.delete/BootstrapRenderer.php
2013-10-02 11:14:53 -05:00

52 lines
1.7 KiB
PHP
Executable File

<?php
namespace Rails\ActionView\Helper\WillPaginate;
class BootstrapRenderer extends AbstractRenderer
{
public function toHtml()
{
$html = implode(array_map(function($item){
if (is_int($item))
return $this->pageNumber($item);
else
return $this->$item();
}, $this->pagination()), $this->options['link_separator']);
return $this->htmlContainer($this->tag('ul', $html));
}
protected function pageNumber($page)
{
if ($page != $this->collection->currentPage())
return $this->tag('li', $this->link($page, $page, ['rel' => $this->relValue($page)]));
else
return $this->tag('li', $this->tag('span', $page), ['class' => 'current']);
}
protected function gap()
{
return $this->tag('li', $this->link('&hellip;', "#"), ['class' => 'disabled']);
}
protected function previousPage()
{
$num = $this->collection->currentPage() > 1 ?
$this->collection->currentPage() - 1 : false;
return $this->previousOrNextPage($num, $this->options['previous_label'], 'prev');
}
protected function nextPage()
{
$num = $this->collection->currentPage() < $this->collection->totalPages() ?
$this->collection->currentPage() + 1 : false;
return $this->previousOrNextPage($num, $this->options['next_label'], 'next');
}
protected function previousOrNextPage($page, $text, $classname)
{
if ($page)
return $this->tag('li', $this->link($text, $page), ['class' => $classname]);
else
return $this->tag('li', $this->tag('span', $text), ['class' => $classname . ' disabled']);
}
}