Skip to content

Commit

Permalink
Merge branch 'nchankov-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
slywalker committed Jul 4, 2013
2 parents efc3959 + afcd019 commit c59110d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ If you want to simplify the options, you can develop WrapBoostCake plugin.
* Add `div` wrapping input
* Add content before and after `input`
* Add error class in outer `div`
* Change pgination tags
* Change SessionHelper::flash()`s tmplate
* Change pagination tags
* Change SessionHelper::flash()`s template
10 changes: 10 additions & 0 deletions Test/Case/View/Helper/BoostCakeHtmlHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public function testUseTag() {
' label',
'/label'
));

$result = $this->Html->useTag(
'radio', 'one', 'two', array('class' => 'radio-inline', 'three' => 'four'), '<label for="one">label</label>'
);
$this->assertTags($result, array(
'label' => array('class' => 'radio-inline', 'for' => 'one'),
'input' => array('type' => 'radio', 'name' => 'one', 'id' => 'two', 'three' => 'four'),
' label',
'/label'
));
}

}
10 changes: 8 additions & 2 deletions View/Helper/BoostCakeHtmlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ class BoostCakeHtmlHelper extends HtmlHelper {
*/
public function useTag($tag) {
$args = func_get_args();

if ($tag === 'radio') {
$class = (isset($args[3]['class'])) ? $args[3]['class'] : 'radio';
unset($args[3]['class']);
}

$html = call_user_func_array(array('parent', 'useTag'), $args);

if ($tag === 'radio') {
$regex = '/(<label)(.*?>)/';
if (preg_match($regex, $html, $match)) {
$html = $match[1] . ' class="radio"' . $match[2] . preg_replace($regex, ' ', $html);
$html = $match[1] . ' class="' . $class . '"' . $match[2] . preg_replace($regex, ' ', $html);
}
}

return $html;
}

}
}

0 comments on commit c59110d

Please sign in to comment.