Adding asset filters for CSS and JS, set using 'Asset.filter.css' and 'Asset.filter.js', fixes #2233

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6287 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-12-31 05:19:00 +00:00
parent 18110fe97a
commit 368b085c94
7 changed files with 36 additions and 6 deletions

View file

@ -158,7 +158,14 @@
*
* To use, prefix the CSS link URL with '/ccss/' instead of '/css/' or use HtmlHelper::css().
*/
define('COMPRESS_CSS', false);
//Configure::write('Asset.filter.css', 'css.php');
/**
* Plug in your own custom JavaScript compressor by dropping a script in your webroot to handle the
* output, and setting the config below to the name of the script.
*
* To use, prefix your JavaScript link URLs with '/cjs/' instead of '/js/' or use JavaScriptHelper::link().
*/
//Configure::write('Asset.filter.js', 'custom_javascript_output_filter.php');
/**
* The classname and database used in CakePHP's
* access control lists.

View file

@ -154,7 +154,14 @@
*
* To use, prefix the CSS link URL with '/ccss/' instead of '/css/' or use HtmlHelper::css().
*/
define('COMPRESS_CSS', false);
//Configure::write('Asset.filter.css', 'css.php');
/**
* Plug in your own custom JavaScript compressor by dropping a script in your webroot to handle the
* output, and setting the config below to the name of the script.
*
* To use, prefix your JavaScript link URLs with '/cjs/' instead of '/js/' or use JavaScriptHelper::link().
*/
//Configure::write('Asset.filter.js', 'custom_javascript_output_filter.php');
/**
* The classname and database used in CakePHP's
* access control lists.

View file

@ -636,7 +636,10 @@ class Dispatcher extends Object {
*/
function cached($url) {
if (strpos($url, 'ccss/') === 0) {
include WWW_ROOT . DS . 'css.php';
include WWW_ROOT . DS . Configure::read('Asset.filter.css');
exit();
} elseif (strpos($url, 'cjs/') === 0) {
include WWW_ROOT . DS . Configure::read('Asset.filter.js');
exit();
}

View file

@ -355,10 +355,9 @@ class HtmlHelper extends AppHelper {
}
}
if (COMPRESS_CSS) {
$path = str_replace('css/', 'ccss/', $path);
if (Configure::read('Asset.filter.css')) {
$path = str_replace(CSS_URL, 'ccss/', $path);
}
$url = $this->webroot($path);
}

View file

@ -163,6 +163,10 @@ class JavascriptHelper extends AppHelper {
if (strpos($url, '://') === false) {
$url = $this->webroot(JS_URL . $url);
if (Configure::read('Asset.filter.js')) {
$url = str_replace(JS_URL, 'cjs/', $url);
}
}
$out = $this->output(sprintf($this->tags['javascriptlink'], $url));

View file

@ -123,6 +123,11 @@ class HtmlHelperTest extends UnitTestCase {
$result = $this->Html->css('cake.generic');
$this->assertPattern('/^<link[^<>]+href=".*css\/cake\.generic\.css\?[0-9]+"[^<>]+\/>$/', $result);
Configure::write('Asset.timestamp', false);
Configure::write('Asset.filter.css', 'css.php');
$result = $this->Html->css('cake.generic');
$this->assertPattern('/^<link[^<>]+href=".*ccss\/cake\.generic\.css"[^<>]+\/>$/', $result);
Configure::write('Asset.filter.css', false);
}
function testBreadcrumb() {

View file

@ -75,6 +75,11 @@ class JavascriptTest extends UnitTestCase {
$result = $this->Javascript->link('jquery-1.1.2');
$this->assertPattern('/^<script[^<>]+src=".*js\/jquery-1\.1\.2\.js\?"[^<>]*>/', $result);
Configure::write('Asset.timestamp', false);
Configure::write('Asset.filter.js', 'js.php');
$result = $this->Javascript->link('jquery-1.1.2');
$this->assertPattern('/^<script[^<>]+src=".*cjs\/jquery-1\.1\.2\.js"[^<>]*>/', $result);
Configure::write('Asset.filter.js', false);
}
function testObjectGeneration() {