A CakePHP plugin designed to handle the modular packaging of resources such as CSS and Javascript files without having to do tedious building/processing beforehand.
This software is licensed under the MIT X11 License (http://www.opensource.org/licenses/mit-license.php)
Copyright (c) 2009-present Gideon Farrell
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
First you need to have a config file ResourcesController.xml in your app's Config directory. See the Sample Config section to understand the format of this.
Load the plugin in app/Config/bootstrap.php:
CakePlugin::load('ResourcesController');
The plugin defines custom routes so it is advised to also load its configuration files:
CakePlugin::load(array(
'ResourcesController' => array('routes'=>true)
));
Then all you need to do is fetch resources using URLs like http://myapp.dev/resources/package
or http://myapp.dev/resources/package/file
. If you have not loaded the routes configuration, then you will have to use slightly messier URLs: http://myapp.dev/resources_controller/resources/resource/package
and http://myapp.dev/resources_controller/resources/resource/package/file
.
You can turn compression on or off (as long as forcecompression isn't set in the configuration) using compressed:false
or compressed:true
as the last parameter in the url, e.g. http://myapp.dev/resources/package/compressed:false
.
<?xml version="1.0"?>
<packages>
<package name="MyPackage" lang="js" path="/app/webroot/js/mypackage" forcecompression="true">
<import>
<file>OtherPackage:speciallib</file>
<package>CoolLibrary</package>
</import>
<files>
<file name="myscript">
<requires>OtherPackage:otherscript</requires>
</file>
<file name="no_requirements" />
</files>
</package>
...
</packages>
This root node is required.
- name the package name
- lang the package language (currently supported are 'js', 'css' and 'less')
- path the path to the package files (from the ROOT)
- forcecompression whether or not to force file compression, default is false. If this is false, then both compressed and uncompressed versions can be requested from the plugin, whereas if it is true, then only compressed versions will be served.
The import tag has no attributes, but contains either <file>
tags or <package>
tags.
Should be formatted as package:file
Should just contain the package name.
Each <file>
node must have a name
attribute, which is the filename without the extension. The lang
attribute of the package will be used as the file extension. A file can have requirements, either from external packages or from within the same package.
There can be multiple <requires>
nodes for each <file>
. The requirement can either be a file from another package, in which case it should be formatted as package:file
or from the same package, in which case it should just contain the file name (same as the name
attribute for the relevant <file>
node).
- Originally developed by Gideon Farrell me@gideonfarrell.co.uk
- JavascriptPacker from http://joliclic.free.fr/php/javascript-packer/en/
- LessPHP by leafo: https://github.com/leafo/lessphp