Skip to content

Commit

Permalink
Updating doc blocks.
Browse files Browse the repository at this point in the history
Renaming inline param for style() to oneline.
Removing escape parameters from div() and tag()
  • Loading branch information
markstory committed Oct 17, 2009
1 parent 8e2f58d commit 3c1d134
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 36 deletions.
62 changes: 32 additions & 30 deletions cake/libs/view/helpers/html.php
Expand Up @@ -187,15 +187,16 @@ function addCrumb($name, $link = null, $options = null) {
* Returns a doctype string.
*
* Possible doctypes:
* + html4-strict: HTML4 Strict.
* + html4-trans: HTML4 Transitional.
* + html4-frame: HTML4 Frameset.
* + xhtml-strict: XHTML1 Strict.
* + xhtml-trans: XHTML1 Transitional.
* + xhtml-frame: XHTML1 Frameset.
* + xhtml11: XHTML1.1.
*
* @param string $type Doctype to use.
*
* - html4-strict: HTML4 Strict.
* - html4-trans: HTML4 Transitional.
* - html4-frame: HTML4 Frameset.
* - xhtml-strict: XHTML1 Strict.
* - xhtml-trans: XHTML1 Transitional.
* - xhtml-frame: XHTML1 Frameset.
* - xhtml11: XHTML1.1.
*
* @param string $type Doctype to use.
* @return string Doctype string
* @access public
*/
Expand Down Expand Up @@ -361,7 +362,7 @@ function link($title, $url = null, $options = array(), $confirmMessage = false)
* 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 array $options Array of HTML attributes.
* @return string CSS <link /> or <style /> tag, depending on the type of link.
* @access public
*/
Expand Down Expand Up @@ -549,19 +550,19 @@ function scriptEnd() {
* Builds CSS style data from an array of CSS properties
*
* @param array $data Style data array
* @param boolean $inline Whether or not the style block should be displayed inline
* @param boolean $online Whether or not the style block should be displayed on one line.
* @return string CSS styling data
* @access public
*/
function style($data, $inline = true) {
function style($data, $oneline = true) {
if (!is_array($data)) {
return $data;
}
$out = array();
foreach ($data as $key=> $value) {
$out[] = $key.':'.$value.';';
}
if ($inline) {
if ($oneline) {
return join(' ', $out);
}
return join("\n", $out);
Expand Down Expand Up @@ -597,7 +598,8 @@ function getCrumbs($separator = '&raquo;', $startText = false) {

/**
* Creates a formatted IMG element. If `$options['url']` is provided, an image link will be
* generated with the link pointed at `$options['url']`
* generated with the link pointed at `$options['url']`. This method will set an empty
* alt attribute if one is not supplied.
*
* @param string $path Path to the image file, relative to the app/webroot/img/ directory.
* @param array $options Array of HTML attributes.
Expand Down Expand Up @@ -629,7 +631,6 @@ function image($path, $options = array()) {
if ($url) {
return $this->output(sprintf($this->tags['link'], $this->url($url), null, $image));
}

return $this->output($image);
}

Expand Down Expand Up @@ -708,52 +709,53 @@ function tableCells($data, $oddTrOptions = null, $evenTrOptions = null, $useCoun
/**
* Returns a formatted block tag, i.e DIV, SPAN, P.
*
* ## Attributes
* #### Options
*
* - `escape` Whether or not the contents should be html_entity escaped.
*
* @param string $name Tag name.
* @param string $text String content that will appear inside the div element.
* If null, only a start tag will be printed
* @param array $attributes Additional HTML attributes of the DIV tag, see above.
* @param array $options Additional HTML attributes of the DIV tag, see above.
* @param boolean $escape If true, $text will be HTML-escaped (Deprecated, use $attributes[escape])
* @return string The formatted tag element
* @access public
*/
function tag($name, $text = null, $attributes = array(), $escape = false) {
if ($escape || isset($attributes['escape']) && $attributes['escape']) {
if (is_array($attributes)) {
unset($attributes['escape']);
}
function tag($name, $text = null, $options = array()) {
if (is_array($options) && isset($options['escape']) && $options['escape']) {
$text = h($text);
unset($options['escape']);
}
if (!is_array($attributes)) {
$attributes = array('class' => $attributes);
if (!is_array($options)) {
$options = array('class' => $options);
}
if ($text === null) {
$tag = 'tagstart';
} else {
$tag = 'tag';
}
return $this->output(sprintf($this->tags[$tag], $name, $this->_parseAttributes($attributes, null, ' ', ''), $text, $name));
return $this->output(sprintf($this->tags[$tag], $name, $this->_parseAttributes($options, null, ' ', ''), $text, $name));
}

/**
* Returns a formatted DIV tag for HTML FORMs.
*
* #### Options
*
* - `escape` Whether or not the contents should be html_entity escaped.
*
* @param string $class CSS class name of the div element.
* @param string $text String content that will appear inside the div element.
* If null, only a start tag will be printed
* @param array $attributes Additional HTML attributes of the DIV tag
* @param boolean $escape If true, $text will be HTML-escaped
* @return string The formatted DIV element
* @access public
*/
function div($class = null, $text = null, $attributes = array(), $escape = false) {
if ($class != null && !empty($class)) {
$attributes['class'] = $class;
function div($class = null, $text = null, $options = array()) {
if (!empty($class)) {
$options['class'] = $class;
}
return $this->tag('div', $text, $attributes, $escape);
return $this->tag('div', $text, $options);
}

/**
Expand Down
9 changes: 3 additions & 6 deletions cake/tests/cases/libs/view/helpers/html.test.php
Expand Up @@ -1166,14 +1166,11 @@ function testTag() {
$result = $this->Html->tag('div', 'text');
$this->assertTags($result, '<div', 'text', '/div');

$result = $this->Html->tag('div', '<text>', array('class' => 'class-name'), true);
$this->assertTags($result, array('div' => array('class' => 'class-name'), '&lt;text&gt;', '/div'));
$result = $this->Html->tag('div', '<text>', 'class-name');
$this->assertTags($result, array('div' => array('class' => 'class-name'), 'preg:/<text>/', '/div'));

$result = $this->Html->tag('div', '<text>', array('class' => 'class-name', 'escape' => true));
$this->assertTags($result, array('div' => array('class' => 'class-name'), '&lt;text&gt;', '/div'));

$result = $this->Html->tag('div', '<text>', 'class-name', true);
$this->assertTags($result, array('div' => array('class' => 'class-name'), '&lt;text&gt;', '/div'));
}

/**
Expand All @@ -1189,7 +1186,7 @@ function testDiv() {
$result = $this->Html->div('class-name', 'text');
$this->assertTags($result, array('div' => array('class' => 'class-name'), 'text', '/div'));

$result = $this->Html->div('class-name', '<text>', array(), true);
$result = $this->Html->div('class-name', '<text>', array('escape' => true));
$this->assertTags($result, array('div' => array('class' => 'class-name'), '&lt;text&gt;', '/div'));
}

Expand Down

0 comments on commit 3c1d134

Please sign in to comment.