Skip to content

Commit

Permalink
add BoostCakeHtml::image() for holder.js
Browse files Browse the repository at this point in the history
  • Loading branch information
slywalker committed Jul 19, 2013
1 parent d5c19ab commit a8e412a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Test/Case/View/Helper/BoostCakeHtmlHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,16 @@ public function testUseTag() {
));
}

public function testImage() {
$result = $this->Html->image('', array('data-src' => 'holder.js/24x24'));
$this->assertTags($result, array(
'img' => array('src' => '/', 'data-src' => 'holder.js/24x24', 'alt' => '')
));

$result = $this->Html->image('some.jpg', array('data-src' => 'holder.js/24x24'));
$this->assertTags($result, array(
'img' => array('src' => '/img/some.jpg', 'alt' => '')
));
}

}
39 changes: 39 additions & 0 deletions View/Helper/BoostCakeHtmlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,43 @@ public function useTag($tag) {
return $html;
}

/**
* Creates a formatted IMG element.
*
* This method will set an empty alt attribute if one is not supplied.
*
* ### Usage:
*
* Create a regular image:
*
* `echo $this->Html->image('cake_icon.png', array('alt' => 'CakePHP'));`
*
* Create an image link:
*
* `echo $this->Html->image('cake_icon.png', array('alt' => 'CakePHP', 'url' => 'http://cakephp.org'));`
*
* ### Options:
*
* - `url` If provided an image link will be generated and the link will point at
* `$options['url']`.
* - `fullBase` If true the src attribute will get a full address for the image file.
* - `plugin` False value will prevent parsing path as a plugin
* - `data-src` For holder.js options. If `$path` is not empty, then unset `$options['data-src']`.
*
* @param string $path Path to the image file, relative to the app/webroot/img/ directory.
* @param array $options Array of HTML attributes. See above for special options.
* @return string completed img tag
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::image
*/
public function image($path, $options = array()) {
if (empty($path)) {
$path = '/';
} else {
if (isset($options['data-src'])) {
unset($options['data-src']);
}
}
return parent::image($path, $options);
}

}

0 comments on commit a8e412a

Please sign in to comment.