Adding rel attributes for first and last links. These attribute values are part of the html5 spec, and fit with the intention of #370

This commit is contained in:
mark_story 2010-12-27 10:48:38 -05:00
parent fd88d57513
commit e003bd6ea9
2 changed files with 18 additions and 10 deletions

View file

@ -743,14 +743,14 @@ class PaginatorHelper extends AppHelper {
$options = array_merge( $options = array_merge(
array( array(
'tag' => 'span', 'tag' => 'span',
'after'=> null, 'after' => null,
'model' => $this->defaultModel(), 'model' => $this->defaultModel(),
'separator' => ' | ', 'separator' => ' | ',
'ellipsis' => '...', 'ellipsis' => '...'
), ),
(array)$options); (array)$options);
$params = array_merge(array('page'=> 1), (array)$this->params($options['model'])); $params = array_merge(array('page' => 1), (array)$this->params($options['model']));
unset($options['model']); unset($options['model']);
if ($params['pageCount'] <= 1) { if ($params['pageCount'] <= 1) {
@ -773,6 +773,7 @@ class PaginatorHelper extends AppHelper {
} }
$out .= $after; $out .= $after;
} elseif ($params['page'] > 1) { } elseif ($params['page'] > 1) {
$options += array('rel' => 'first');
$out = $this->Html->tag($tag, $this->link($first, array('page' => 1), $options)) $out = $this->Html->tag($tag, $this->link($first, array('page' => 1), $options))
. $after; . $after;
} }
@ -830,6 +831,7 @@ class PaginatorHelper extends AppHelper {
} }
$out = $before . $out; $out = $before . $out;
} elseif ($params['page'] < $params['pageCount']) { } elseif ($params['page'] < $params['pageCount']) {
$options += array('rel' => 'last');
$out = $before . $this->Html->tag( $out = $before . $this->Html->tag(
$tag, $this->link($last, array('page' => $params['pageCount']), $options $tag, $this->link($last, array('page' => $params['pageCount']), $options
)); ));

View file

@ -1179,7 +1179,7 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->numbers(true); $result = $this->Paginator->numbers(true);
$expected = array( $expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), 'first', '/a', '/span', array('span' => array()), array('a' => array('href' => '/index/page:1', 'rel' => 'first')), 'first', '/a', '/span',
' | ', ' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' | ', ' | ',
@ -1199,7 +1199,7 @@ class PaginatorHelperTest extends CakeTestCase {
' | ', ' | ',
array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span', array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
' | ', ' | ',
array('span' => array()), array('a' => array('href' => '/index/page:15')), 'last', '/a', '/span', array('span' => array()), array('a' => array('href' => '/index/page:15', 'rel' => 'last')), 'last', '/a', '/span',
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
@ -1779,7 +1779,7 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->first('<<', array('tag' => 'li')); $result = $this->Paginator->first('<<', array('tag' => 'li'));
$expected = array( $expected = array(
'<li', '<li',
'a' => array('href' => '/index/page:1'), 'a' => array('href' => '/index/page:1', 'rel' => 'first'),
'&lt;&lt;', '&lt;&lt;',
'/a', '/a',
'/li' '/li'
@ -1841,7 +1841,9 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->first(); $result = $this->Paginator->first();
$expected = array( $expected = array(
'<span', '<span',
array('a' => array('href' => FULL_BASE_URL . '/index/page:1/sort:Article.title/direction:DESC')), array('a' => array(
'href' => FULL_BASE_URL . '/index/page:1/sort:Article.title/direction:DESC', 'rel' => 'first'
)),
'&lt;&lt; first', '&lt;&lt; first',
'/a', '/a',
'/span', '/span',
@ -1858,7 +1860,7 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->first(); $result = $this->Paginator->first();
$expected = array( $expected = array(
'<span', '<span',
'a' => array('href' => '/index/page:1'), 'a' => array('href' => '/index/page:1', 'rel' => 'first'),
'&lt;&lt; first', '&lt;&lt; first',
'/a', '/a',
'/span' '/span'
@ -1888,7 +1890,7 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->last(); $result = $this->Paginator->last();
$expected = array( $expected = array(
'<span', '<span',
'a' => array('href' => '/index/page:7'), 'a' => array('href' => '/index/page:7', 'rel' => 'last'),
'last &gt;&gt;', 'last &gt;&gt;',
'/a', '/a',
'/span' '/span'
@ -1947,7 +1949,11 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->last(); $result = $this->Paginator->last();
$expected = array( $expected = array(
'<span', '<span',
array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), 'last &gt;&gt;', '/a', array('a' => array(
'href' => '/index/page:15/sort:Client.name/direction:DESC',
'rel' => 'last'
)),
'last &gt;&gt;', '/a',
'/span', '/span',
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);