Skip to content

Commit

Permalink
Add asset to includedAssets after url is resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
Walther Lalk committed Jun 12, 2014
1 parent 2e3e33a commit 67893fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
27 changes: 13 additions & 14 deletions src/View/Helper/HtmlHelper.php
Expand Up @@ -91,10 +91,7 @@ class HtmlHelper extends Helper {
*
* @var array
*/
protected $_includedAssets = array(
'css' => array(),
'script' => array()
);
protected $_includedAssets = array();

/**
* Options for the currently opened script block buffer if any.
Expand Down Expand Up @@ -408,19 +405,19 @@ public function css($path, array $options = array()) {
return;
}

if ($options['once'] && isset($this->_includedAssets['css'][$path])) {
return '';
}
unset($options['once']);
$this->_includedAssets['css'][$path] = true;

if (strpos($path, '//') !== false) {
$url = $path;
} else {
$url = $this->assetUrl($path, $options + array('pathPrefix' => Configure::read('App.cssBaseUrl'), 'ext' => '.css'));
$options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null));
}

if ($options['once'] && isset($this->_includedAssets[$url])) {
return '';
}
unset($options['once']);
$this->_includedAssets[$url] = true;

if ($options['rel'] === 'import') {
$out = $this->formatTemplate('style', [
'attrs' => $this->templater()->formatAttributes($options, ['rel', 'block']),
Expand Down Expand Up @@ -492,15 +489,17 @@ public function script($url, array $options = array()) {
}
return null;
}
if ($options['once'] && isset($this->_includedAssets['script'][$url])) {
return null;
}
$this->_includedAssets['script'][$url] = true;

if (strpos($url, '//') === false) {
$url = $this->assetUrl($url, $options + array('pathPrefix' => Configure::read('App.jsBaseUrl'), 'ext' => '.js'));
$options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null));
}

if ($options['once'] && isset($this->_includedAssets[$url])) {
return null;
}
$this->_includedAssets[$url] = true;

$out = $this->formatTemplate('javascriptlink', [
'url' => $url,
'attrs' => $this->templater()->formatAttributes($options, ['block', 'once']),
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/View/Helper/HtmlHelperTest.php
Expand Up @@ -515,7 +515,7 @@ public function testCssLink() {
);
$this->assertTags($result, $expected);

$result = $this->Html->css('screen.css');
$result = $this->Html->css('screen.css', array('once' => false));
$this->assertTags($result, $expected);

Plugin::load('TestPlugin');
Expand Down

0 comments on commit 67893fa

Please sign in to comment.