Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow setting different type on scriptBlock
  • Loading branch information
Gilles Wittenberg committed May 21, 2013
1 parent 28a3b73 commit f19615a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
Expand Up @@ -1067,6 +1067,16 @@ public function testScriptBlock() {
);
$this->assertTags($result, $expected);

$result = $this->Html->scriptBlock('window.foo = 2;', array('type' => 'text/x-handlebars-template'));
$expected = array(
'script' => array('type' => 'text/x-handlebars-template'),
$this->cDataStart,
'window.foo = 2;',
$this->cDataEnd,
'/script',
);
$this->assertTags($result, $expected);

$result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false));
$expected = array(
'script' => array('type' => 'text/javascript'),
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/View/Helper/HtmlHelper.php
Expand Up @@ -98,7 +98,7 @@ class HtmlHelper extends AppHelper {
'ol' => '<ol%s>%s</ol>',
'li' => '<li%s>%s</li>',
'error' => '<div%s>%s</div>',
'javascriptblock' => '<script type="text/javascript"%s>%s</script>',
'javascriptblock' => '<script%s>%s</script>',
'javascriptstart' => '<script type="text/javascript">',
'javascriptlink' => '<script type="text/javascript" src="%s"%s></script>',
'javascriptend' => '</script>'
Expand Down Expand Up @@ -560,7 +560,7 @@ public function script($url, $options = array()) {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::scriptBlock
*/
public function scriptBlock($script, $options = array()) {
$options += array('safe' => true, 'inline' => true);
$options += array('type' => 'text/javascript', 'safe' => true, 'inline' => true);
if ($options['safe']) {
$script = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n";
}
Expand Down

0 comments on commit f19615a

Please sign in to comment.