Skip to content

Commit

Permalink
When dispatching assets, urls that cannot be dispatched, should be le…
Browse files Browse the repository at this point in the history
…ft intact

Closes #5
  • Loading branch information
bajb committed Jul 15, 2014
1 parent 54bc9bd commit 7ccb5ca
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 16 deletions.
8 changes: 7 additions & 1 deletion src/Assets/AbstractDispatchableAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ protected function _dispatchNestedUrl($uri)
}

$path = ltrim($path, '/');
$url = $this->_assetManager->getResourceUri(
build_path_unix($prefix, $path)
);

$url = $this->_assetManager->getResourceUri(build_path_unix($prefix, $path));
if(empty($url))
{
return $uri[0];
}

if(!empty($append))
{
Expand Down
9 changes: 8 additions & 1 deletion src/Assets/JavascriptAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public function getContent()
return $data;
}

return Minifier::minify($data);
try
{
return Minifier::minify($data);
}
catch(\Exception $e)
{
return $data;
}
}
}
41 changes: 27 additions & 14 deletions tests/DispatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,6 @@ public function urlProvider()
{alert("Hello\nHow are you?");}'
];

/**
* Do not minify .min.ext files
* @link https://github.com/packaged/dispatch/issues/1
* */
$tests[] = [
array_merge($baseConfig, []),
'res/p/domain/b/filehash/test.min.js',
'www.packaged.in',
'function myFunction()
{
alert("Hello\nHow are you?");
}'
];

$tests[] = [
array_merge($baseConfig, []),
'res/p/domain/b/filehash/test.css',
Expand Down Expand Up @@ -271,6 +257,33 @@ public function urlProvider()
'body { background: yellow url(x.jpg); }'
];

/**
* Do not minify .min.ext files
* @link https://github.com/packaged/dispatch/issues/1
* */
$tests[] = [
array_merge($baseConfig, []),
'res/p/domain/b/filehash/test.min.js',
'www.packaged.in',
'function myFunction()
{
alert("Hello\nHow are you?");
}'
];

/**
* Invalid dispatch links should remain as the default
* @link https://github.com/packaged/dispatch/issues/5
* */
$tests[] = [
array_merge($baseConfig, []),
'res/p/domain/b/filehash/dispatch.test.js',
'www.packaged.in',
'function f(){setCss(\'background:url(https://),url(https://),'
. 'red url(https://)\');return(/(url\s*\(.*?){3}/).'
. 'test(mStyle.background);}'
];

return $tests;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/asset/dispatch.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function f() {
// Setting multiple images AND a color on the background shorthand property
// and then querying the style.background property value for the number of
// occurrences of "url(" is a reliable method for detecting ACTUAL support for this!

setCss('background:url(https://),url(https://),red url(https://)');

// If the UA supports multiple backgrounds, there should be three occurrences
// of the string "url(" in the return value for elemStyle.background

return (/(url\s*\(.*?){3}/).test(mStyle.background);
}

0 comments on commit 7ccb5ca

Please sign in to comment.