diff --git a/Test/Case/View/Helper/BoostCakeHtmlHelperTest.php b/Test/Case/View/Helper/BoostCakeHtmlHelperTest.php index 9d7f7f5..59f39fe 100644 --- a/Test/Case/View/Helper/BoostCakeHtmlHelperTest.php +++ b/Test/Case/View/Helper/BoostCakeHtmlHelperTest.php @@ -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' => '') + )); + } + } diff --git a/View/Helper/BoostCakeHtmlHelper.php b/View/Helper/BoostCakeHtmlHelper.php index da45083..e7e56f0 100644 --- a/View/Helper/BoostCakeHtmlHelper.php +++ b/View/Helper/BoostCakeHtmlHelper.php @@ -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); + } + } \ No newline at end of file