Skip to content

Commit

Permalink
Simplify API for HtmlHelper::nestedList and complete documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Apr 10, 2014
1 parent f0a8792 commit bcb7d79
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/View/Helper/HtmlHelper.php
Expand Up @@ -1076,18 +1076,19 @@ public function media($path, array $options = array()) {
/**
* Build a nested list (UL/OL) out of an associative array.
*
* Options for $itemOptions:
*
* - `even` - Class to use for even rows.
* - `odd` - Class to use for odd rows.
*
* @param array $list Set of elements to list
* @param string|array $options Additional HTML attributes of the list (ol/ul) tag or if ul/ol use that as tag
* @param array $itemOptions Additional HTML attributes of the list item (LI) tag
* @param string $tag Type of list tag to use (ol/ul)
* @return string The nested list
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::nestedList
*/
public function nestedList($list, $options = array(), array $itemOptions = array(), $tag = 'ul') {
if (is_string($options)) {
$tag = $options;
$options = array();
}
public function nestedList(array $list, array $options = array(), array $itemOptions = array(), $tag = 'ul') {
$items = $this->_nestedListItem($list, $options, $itemOptions, $tag);
return $this->formatTemplate($tag, [
'attrs' => $this->templater()->formatAttributes($options),
Expand All @@ -1105,7 +1106,7 @@ public function nestedList($list, $options = array(), array $itemOptions = array
* @return string The nested list element
* @see HtmlHelper::nestedList()
*/
protected function _nestedListItem($items, $options, array $itemOptions, $tag) {
protected function _nestedListItem($items, $options, $itemOptions, $tag) {
$out = '';

$index = 1;
Expand Down
5 changes: 1 addition & 4 deletions tests/TestCase/View/Helper/HtmlHelperTest.php
Expand Up @@ -1318,7 +1318,7 @@ public function testNestedList() {
);
$this->assertTags($result, $expected);

$result = $this->Html->nestedList($list, null);
$result = $this->Html->nestedList($list);
$this->assertTags($result, $expected);

$result = $this->Html->nestedList($list, array(), array(), 'ol');
Expand Down Expand Up @@ -1351,9 +1351,6 @@ public function testNestedList() {
);
$this->assertTags($result, $expected);

$result = $this->Html->nestedList($list, 'ol');
$this->assertTags($result, $expected);

$result = $this->Html->nestedList($list, array('class' => 'list'));
$expected = array(
array('ul' => array('class' => 'list')),
Expand Down

0 comments on commit bcb7d79

Please sign in to comment.