CakePHP Plugin - Automatically combine and compress CSS and JS files.
PHP JavaScript
Pull request Compare This branch is 7 commits ahead, 8 commits behind mcurry:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
extras
libs
tests
views/helpers
webroot
README

README

/*
 * Asset Packer CakePHP Plugin
 * Copyright (c) 2010 José Lorenzo Rodríguez
 * Based on the Asset Packer from  Matt Curry (www.PseudoCoder.com) at http://github.com/mcurry/asset
 * @author José Lorenzo Rodríguez <jose.zap@gmail.com>
 * @author Matt Curry <matt@pseudocoder.com>
 * @license MIT
 *
 */

/* Notes */
    * JavaScript packing only works with PHP5. If you're using PHP4 the scripts will still be merged into one file, but not packed.
    * A sample .htaccess file is included in the zip. Rename it and drop it in output dirs for improved performance.

/* Instructions */
   1. You'll need a working version of CakePHP > 1.2 installed. This is running on 1.3-RC1
   2. Download CSSTidy 1.3 or later and put the contents in vendors/csstidy.
   3. Download the plugin to /app/plugins/asset.
   4. Include the helper in any controller that will need it. Most likely you will put it in AppController so that it's available to all your controllers:
      var $helpers = array('Asset.asset');

   5. In your layout and views include Javascript files as you normally would when using the $scripts_for_layout approach:
      $javascript->link('jquery', false);

   6. Similarly include your css with the inline option set to false:
      $html->css('style', null, null, false);

   7. Then in your layout file, in the head section, instead of using $scripts_for_layout call the helper:
      echo $asset->scripts_for_layout();

/* Tips */
    * By default the cached files are written to /app/webroot/cjs and /app/webroot/ccss.  You can change that by setting:
      Configure::write('Asset.jsPath', 'some/path');
      Configure::write('Asset.cssPath', 'some/path');
      Don't include slashes at the beginning or end.  Path will be relative to /app/webroot.  So if set:
      Configure::write('Asset.jsPath', 'js/packed');
      The path will be /app/webroot/js/packed
    * Remember to set the inline option to false for JS and CSS in your layout if you want them to be packed with the view scripts.
    * Setting DEBUG on will cause this helper to output the scripts the same way $scripts_for_layout would, effectifly turning it off while testing.
    * If you get a JavaScript error with a packed version of a file it's most likely missing a semi-colon somewhere.
    * Order is important. If you include script1 then script2 on one view and script2 then script1 on another, they will generate separate packed versions and will be treated by the browser as separate scripts.