Updating formatting to match coding standards.

This commit is contained in:
mark_story 2010-06-28 22:53:33 -04:00
parent 5e79a450b8
commit 1c47702cb9
2 changed files with 48 additions and 66 deletions

View file

@ -580,52 +580,38 @@ class HtmlHelper extends AppHelper {
/**
* Returns breadcrumbs as a (x)html list
*
*
* This method uses HtmlHelper::tag() to generate list and its elements. Works
* similiary to HtmlHelper::getCrumbs(), so it uses options which every
* crumb was added with.
*
* @param array $list_options options to render list
*
*
* @param array $options Array of html attributes to apply to the generated list elements.
* @return string breadcrumbs html list
*
* @access public
*/
function getCrumbList($list_options = array()) {
if (!empty($this->_crumbs)) {
$result = '';
$crumb_count = count($this->_crumbs);
foreach ($this->_crumbs as $which => $crumb) {
$options = array();
if (empty($crumb[1])) {
$element_content = $crumb[0];
} else {
$element_content = $this->link(
$crumb[0],
$crumb[1],
$crumb[2]
);
}
if ($which == 0) {
$options['class'] = 'first';
} elseif ($which == $crumb_count - 1) {
$options['class'] = 'last';
}
$result .= $this->tag(
'li',
$element_content,
$options
);
}
return $this->tag(
'ul',
$result,
$list_options
);
} else {
return null;
}
}
function getCrumbList($options = array()) {
if (!empty($this->_crumbs)) {
$result = '';
$crumbCount = count($this->_crumbs);
foreach ($this->_crumbs as $which => $crumb) {
$options = array();
if (empty($crumb[1])) {
$elementContent = $crumb[0];
} else {
$elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]);
}
if ($which == 0) {
$options['class'] = 'first';
} elseif ($which == $crumbCount - 1) {
$options['class'] = 'last';
}
$result .= $this->tag('li', $elementContent, $options);
}
return $this->tag('ul', $result, $options);
} else {
return null;
}
}
/**
* Creates a formatted IMG element. If `$options['url']` is provided, an image link will be

View file

@ -1282,31 +1282,27 @@ class HtmlHelperTest extends CakeTestCase {
* @return void
*/
function testCrumbList() {
$this->Html->addCrumb('Home', '/', array('class' => 'home'));
$this->Html->addCrumb('Some page', '/some_page');
$this->Html->addCrumb('Another page');
$result = $this->Html->getCrumbList(
array('class' => 'breadcrumbs')
);
$this->assertTags(
$result,
array(
array('ul' => array('class' => 'breadcrumbs')),
array('li' => array('class' => 'first')),
array('a' => array('class' => 'home', 'href' => '/')),
'Home',
'/a',
'/li',
'<li',
array('a' => array('href' => '/some_page')),
'Some page',
'/a',
'/li',
array('li' => array('class' => 'last')),
'Another page',
'/li',
'/ul'
)
);
$this->Html->addCrumb('Home', '/', array('class' => 'home'));
$this->Html->addCrumb('Some page', '/some_page');
$this->Html->addCrumb('Another page');
$result = $this->Html->getCrumbList(
array('class' => 'breadcrumbs')
);
$this->assertTags(
$result,
array(
array('ul' => array('class' => 'breadcrumbs')),
array('li' => array('class' => 'first')),
array('a' => array('class' => 'home', 'href' => '/')), 'Home', '/a',
'/li',
'<li',
array('a' => array('href' => '/some_page')), 'Some page', '/a',
'/li',
array('li' => array('class' => 'last')),
'Another page',
'/li',
'/ul'
)
);
}
}