Skip to content

Commit

Permalink
Merge pull request #216 from loic425/semantic_ui
Browse files Browse the repository at this point in the history
Add support for semantic ui
  • Loading branch information
Sam Partington committed Feb 14, 2017
2 parents b69b72c + 68aa59a commit 6fce52c
Show file tree
Hide file tree
Showing 5 changed files with 522 additions and 25 deletions.
File renamed without changes.
74 changes: 49 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/whiteoctober/Pagerfanta.png?branch=master)](https://travis-ci.org/whiteoctober/Pagerfanta) [![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/whiteoctober/Pagerfanta/badges/quality-score.png?s=1ee480491644c07812b5206cf07d33a5035d0118)](https://scrutinizer-ci.com/g/whiteoctober/Pagerfanta/) [![Code Coverage](https://scrutinizer-ci.com/g/whiteoctober/Pagerfanta/badges/coverage.png?s=284be0616a9ba0439ee1123bcaf5fb3f6bfb0e50)](https://scrutinizer-ci.com/g/whiteoctober/Pagerfanta/) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/9e710230-b088-4904-baef-5f5e2d62e681/mini.png)](https://insight.sensiolabs.com/projects/9e710230-b088-4904-baef-5f5e2d62e681) [![Latest Stable Version](https://poser.pugx.org/pagerfanta/pagerfanta/v/stable.png)](https://packagist.org/packages/pagerfanta/pagerfanta) [![Total Downloads](https://poser.pugx.org/pagerfanta/pagerfanta/downloads.png)](https://packagist.org/packages/pagerfanta/pagerfanta)

Pagination for PHP 5.3
Pagination for PHP >= 5.3

## Usage

Expand All @@ -26,7 +26,7 @@ $currentPageResults = $pagerfanta->getCurrentPageResults();

$pagerfanta->getNbPages();

$pagerfanta->haveToPaginate(); // whether the number of results if higher than the max per page
$pagerfanta->haveToPaginate(); // whether the number of results is higher than the max per page

$pagerfanta->hasPreviousPage();
$pagerfanta->getPreviousPage();
Expand Down Expand Up @@ -336,8 +336,8 @@ $adapter = new FixedAdapter($nbResults, $results);
## Views

Views are to render pagerfantas, this way you can reuse your
pagerfantas' html in several projects, share them and use another
ones from another developers.
pagerfantas' HTML in several projects, share them and use another
ones from another developer's.

The views implement the `Pagerfanta\View\ViewInterface` interface,
which has two methods:
Expand Down Expand Up @@ -374,10 +374,10 @@ $routeGenerator = function($page) {
return '/path?page='.$page;
}
```

Pagerfanta comes with three views, the default one, one for
[Twitter Bootstrap](https://github.com/twitter/bootstrap) and
an special optionable view.
Pagerfanta comes with five views: The default one, two for
[Twitter Bootstrap](https://github.com/twitter/bootstrap), one for
[Semantic UI](https://github.com/Semantic-Org/Semantic-UI) and
a special optionable view.

### DefaultView

Expand Down Expand Up @@ -406,8 +406,6 @@ Options (default):
* page_template (<a href="%href%">%text%</a>)
* span_template (<span class="%class%">%text%</span>)

![Pagerfanta DefaultView](http://img813.imageshack.us/img813/601/pagerfanta.png)

CSS:

```css
Expand Down Expand Up @@ -467,11 +465,13 @@ COLORS:
}
```

### TwitterBootstrapView
### TwitterBootstrapView and TwitterBootstrap3View

This view generates a pagination for
These views generate paginators designed for use with
[Twitter Bootstrap](https://github.com/twitter/bootstrap).

`TwitterBootstrapView` is for Bootstrap 2; `TwitterBootstrap3View` is for Bootstrap 3.

```php
<?php

Expand All @@ -498,6 +498,38 @@ Options (default):
* css_dots_class (disabled)
* css_active_class (active)

### SemanticUiView

This view generates a pagination for
[Semantic UI](https://github.com/Semantic-Org/Semantic-UI).

```php
<?php

use Pagerfanta\View\SemanticUiView;

$view = new SemanticUiView();
$options = array('proximity' => 3);
$html = $view->render($pagerfanta, $routeGenerator, $options);
```

Options (default):

* proximity (3)
* prev_message (&larr; Previous)
* prev_disabled_href ()
* next_message (Next &rarr;)
* next_disabled_href ()
* dots_message (&hellip;)
* dots_href ()
* css_container_class (pagination)
* css_item_class (item)
* css_prev_class (prev)
* css_next_class (next)
* css_disabled_class (disabled)
* css_dots_class (disabled)
* css_active_class (active)

### OptionableView

This view is to reuse options in different views.
Expand All @@ -522,20 +554,12 @@ $pagerfantaHtml = $myView2->render($pagerfanta, $routeGenerator);
$pagerfantaHtml = $myView2->render($pagerfanta, $routeGenerator, array('next_message' => 'Siguiente!!'));
```

## Todo

## Author

Pablo Díez - <[email protected]>

## License

Pagerfanta is licensed under the MIT License. See the LICENSE file for full details.
## Acknowledgements

## Sponsors
Pagerfanta is inspired by [Zend Paginator](https://github.com/zendframework/zf2).

[WhiteOctober](http://www.whiteoctober.co.uk/)
Thanks also to Pablo Díez ([email protected]) for most of the work on the first versions of Pagerfanta.

## Acknowledgements
## Licence

Pagerfanta is inspired by [Zend Paginator](https://github.com/zendframework/zf2).
Pagerfanta is licensed under the [MIT License](LICENCE).
44 changes: 44 additions & 0 deletions src/Pagerfanta/View/SemanticUiView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the Pagerfanta package.
*
* (c) Pablo Díez <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Pagerfanta\View;

use Pagerfanta\View\Template\SemanticUiTemplate;

/**
* SemanticUiView.
*
* View that can be used with the pagination module
* from the Semantic UI CSS Toolkit
* http://semantic-ui.com/
*
* @author Loïc Frémont <[email protected]>
*/
class SemanticUiView extends DefaultView
{
protected function createDefaultTemplate()
{
return new SemanticUiTemplate();
}

protected function getDefaultProximity()
{
return 3;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'semantic_ui';
}
}
142 changes: 142 additions & 0 deletions src/Pagerfanta/View/Template/SemanticUiTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

/*
* This file is part of the Pagerfanta package.
*
* (c) Pablo Díez <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Pagerfanta\View\Template;

/**
* @author Loïc Frémont <[email protected]>
*/
class SemanticUiTemplate extends Template
{
static protected $defaultOptions = array(
'prev_message' => '&larr; Previous',
'next_message' => 'Next &rarr;',
'dots_message' => '&hellip;',
'active_suffix' => '',
'css_container_class' => 'ui stackable fluid pagination menu',
'css_item_class' => 'item',
'css_prev_class' => 'prev',
'css_next_class' => 'next',
'css_disabled_class' => 'disabled',
'css_dots_class' => 'disabled',
'css_active_class' => 'active',
);

public function container()
{
return sprintf('<div class="%s">%%pages%%</div>',
$this->option('css_container_class')
);
}

public function page($page)
{
$text = $page;

return $this->pageWithText($page, $text);
}

public function pageWithText($page, $text)
{
$class = null;

return $this->pageWithTextAndClass($page, $text, $class);
}

private function pageWithTextAndClass($page, $text, $class)
{
$href = $this->generateRoute($page);

return $this->link($class, $href, $text);
}

public function previousDisabled()
{
$class = $this->previousDisabledClass();
$text = $this->option('prev_message');

return $this->div($class, $text);
}

private function previousDisabledClass()
{
return $this->option('css_prev_class').' '.$this->option('css_disabled_class');
}

public function previousEnabled($page)
{
$text = $this->option('prev_message');
$class = $this->option('css_prev_class');

return $this->pageWithTextAndClass($page, $text, $class);
}

public function nextDisabled()
{
$class = $this->nextDisabledClass();
$text = $this->option('next_message');

return $this->div($class, $text);
}

private function nextDisabledClass()
{
return $this->option('css_next_class').' '.$this->option('css_disabled_class');
}

public function nextEnabled($page)
{
$text = $this->option('next_message');
$class = $this->option('css_next_class');

return $this->pageWithTextAndClass($page, $text, $class);
}

public function first()
{
return $this->page(1);
}

public function last($page)
{
return $this->page($page);
}

public function current($page)
{
$text = trim($page.' '.$this->option('active_suffix'));
$class = $this->option('css_active_class');

return $this->div($class, $text);
}

public function separator()
{
$class = $this->option('css_dots_class');
$text = $this->option('dots_message');

return $this->div($class, $text);
}

private function link($class, $href, $text)
{
$item_class = $this->option('css_item_class');

return sprintf('<a class="%s %s" href="%s">%s</a>', $item_class, $class, $href, $text);
}

private function div($class, $text)
{
$item_class = $this->option('css_item_class');

return sprintf('<div class="%s %s">%s</div>', $item_class, $class, $text);
}
}
Loading

0 comments on commit 6fce52c

Please sign in to comment.