Skip to content

Commit

Permalink
Start integrating StringTemplate with PaginatorHelper.
Browse files Browse the repository at this point in the history
Add templates() method and constructor use.
  • Loading branch information
markstory committed Sep 22, 2013
1 parent 0072414 commit a71823d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Cake/Test/TestCase/View/Helper/PaginatorHelperTest.php
Expand Up @@ -78,6 +78,23 @@ public function tearDown() {
unset($this->View, $this->Paginator);
}

/**
* Test the templates method.
*
* @return void
*/
public function testTemplates() {
$result = $this->Paginator->templates([
'test' => 'val'
]);
$this->assertNull($result, 'Setting should return null');
$result = $this->Paginator->templates();
$this->assertArrayHasKey('test', $result);
$this->assertEquals('val', $result['test']);

$this->assertEquals('val', $this->Paginator->templates('test'));
}

/**
* testHasPrevious method
*
Expand Down
49 changes: 48 additions & 1 deletion Cake/View/Helper/PaginatorHelper.php
Expand Up @@ -18,6 +18,7 @@
use Cake\Error;
use Cake\Utility\Inflector;
use Cake\View\Helper;
use Cake\View\StringTemplate;
use Cake\View\View;

/**
Expand All @@ -35,7 +36,7 @@ class PaginatorHelper extends Helper {
*
* @var array
*/
public $helpers = array('Html');
public $helpers = ['Html'];

/**
* Holds the default options for pagination links
Expand All @@ -58,6 +59,52 @@ class PaginatorHelper extends Helper {
*/
public $options = [];

/**
* StringTemplate instance.
*
* @var Cake\View\StringTemplate
*/
protected $_templater;

/**
* The default templates used by PaginatorHelper.
*
* @var array
*/
protected $_defaultTemplates = [

];

/**
* Constructor
*
* @param View $View The View this helper is being attached to.
* @param array $settings Configuration settings for the helper.
*/
public function __construct(View $View, $settings = []) {
parent::__construct($View, $settings);

$this->_templater = new StringTemplate();
$this->_templater->add($this->_defaultTemplates);
if (isset($settings['templates'])) {
$this->_templater->load($settings['templates']);
}
}

/**
* Get/set templates to use.
*
* @param string|null|array $templates null or string allow reading templates. An array
* allows templates to be added.
* @return void|string|array
*/
public function templates($templates = null) {
if ($templates === null || is_string($templates)) {
return $this->_templater->get($templates);
}
return $this->_templater->add($templates);
}

/**
* Before render callback. Overridden to merge passed args with url options.
*
Expand Down

0 comments on commit a71823d

Please sign in to comment.