Skip to content

Commit

Permalink
Created the method useTag in html, avoiding sprintf with Html tags in…
Browse files Browse the repository at this point in the history
… others helpers.
  • Loading branch information
jrbasso committed Jan 23, 2011
1 parent 41e1aa7 commit 8cd5477
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cake/libs/view/helpers/html.php
Expand Up @@ -763,6 +763,26 @@ public function tag($name, $text = null, $options = array()) {
return sprintf($this->tags[$tag], $name, $this->_parseAttributes($options, null, ' ', ''), $text, $name);
}

/**
* Returns a formatted existent block of $tags
*
* @param string $tag Tag name
* @return string Formatted block
*/
public function useTag($tag) {
if (!isset($this->tags[$tag])) {
return '';
}
$args = func_get_args();
array_shift($args);
foreach ($args as &$arg) {
if (is_array($arg)) {
$arg = $this->_parseAttributes($arg, null, ' ', '');
}
}
return vsprintf($this->tags[$tag], $args);
}

/**
* Returns a formatted DIV tag for HTML FORMs.
*
Expand Down
16 changes: 16 additions & 0 deletions cake/tests/cases/libs/view/helpers/html.test.php
Expand Up @@ -1231,6 +1231,22 @@ function testTag() {
$this->assertTags($result, array('div' => array('class' => 'class-name'), '<text>', '/div'));
}

/**
* testUseTag method
*
* @return void
*/
public function testUseTag() {
$result = $this->Html->useTag('formend');
$this->assertTags($result, '/form');

$result = $this->Html->useTag('form', 'test');
$this->assertEqual($result, '<form test>');

$result = $this->Html->useTag('form', array('test' => 'ok'));
$this->assertTags($result, array('form' => array('test' => 'ok')));
}

/**
* testDiv method
*
Expand Down

0 comments on commit 8cd5477

Please sign in to comment.