Skip to content
Permalink
Browse files

Removing HtmlHelper::css() inline parameter. Use $options[inline] ins…

…tead.

Adding tests for inline = false script and css generation.
  • Loading branch information...
markstory committed Oct 17, 2009
1 parent fc4df2b commit 8e2f58d0861adb74a8eebad0ecaf08b92a47ee4a
Showing with 21 additions and 5 deletions.
  1. +9 −5 cake/libs/view/helpers/html.php
  2. +12 −0 cake/tests/cases/libs/view/helpers/html.test.php
@@ -353,20 +353,24 @@ function link($title, $url = null, $options = array(), $confirmMessage = false)
/**
* Creates a link element for CSS stylesheets.
*
* #### Options
*
* - `inline` If set to false, the generated tag appears in the head tag of the layout.
*
* @param mixed $path The name of a CSS style sheet or an array containing names of
* CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot
* of your application. Otherwise, the path will be relative to your CSS path, usually webroot/css.
* @param string $rel Rel attribute. Defaults to "stylesheet". If equal to 'import' the stylesheet will be imported.
* @param array $htmlAttributes Array of HTML attributes.
* @param boolean $inline If set to false, the generated tag appears in the head tag of the layout.
* @return string CSS <link /> or <style /> tag, depending on the type of link.
* @access public
*/
function css($path, $rel = null, $htmlAttributes = array(), $inline = true) {
function css($path, $rel = null, $options = array()) {
$inline = isset($options['inline']) ? $options['inline'] : true;
if (is_array($path)) {
$out = '';
foreach ($path as $i) {
$out .= "\n\t" . $this->css($i, $rel, $htmlAttributes, $inline);
$out .= "\n\t" . $this->css($i, $rel, $options, $inline);
}
if ($inline) {
return $out . "\n";
@@ -397,12 +401,12 @@ function css($path, $rel = null, $htmlAttributes = array(), $inline = true) {
}
if ($rel == 'import') {
$out = sprintf($this->tags['style'], $this->_parseAttributes($htmlAttributes, null, '', ' '), '@import url(' . $url . ');');
$out = sprintf($this->tags['style'], $this->_parseAttributes($options, null, '', ' '), '@import url(' . $url . ');');
} else {
if ($rel == null) {
$rel = 'stylesheet';
}
$out = sprintf($this->tags['css'], $rel, $url, $this->_parseAttributes($htmlAttributes, null, '', ' '));
$out = sprintf($this->tags['css'], $rel, $url, $this->_parseAttributes($options, null, '', ' '));
}
$out = $this->output($out);
@@ -421,6 +421,12 @@ function testCssLink() {
$expected['link']['href'] = 'preg:/.*css\/vendor\.generic\.css/';
$this->assertTags($result[1], $expected);
$this->assertEqual(count($result), 2);
$view =& ClassRegistry::getObject('view');
$view =& new HtmlHelperMockView();
$view->expectAt(0, 'addScript', array(new PatternExpectation('/css_in_head.css/')));
$result = $this->Html->css('css_in_head', null, array('inline' => false));
$this->assertNull($result);
}
/**
@@ -542,6 +548,12 @@ function testScript() {
'script' => array('type' => 'text/javascript', 'src' => 'js/jquery-1.3.2.js', 'defer' => 'defer', 'encoding' => 'utf-8')
);
$this->assertTags($result, $expected);
$view =& ClassRegistry::getObject('view');
$view =& new HtmlHelperMockView();
$view->expectAt(0, 'addScript', array(new PatternExpectation('/script_in_head.js/')));
$result = $this->Html->script('script_in_head', array('inline' => false));
$this->assertNull($result);
}
/**

0 comments on commit 8e2f58d

Please sign in to comment.
You can’t perform that action at this time.