Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gfarrell/resourcescontroller

A CakePHP plugin to manage resources like javascript and css files as separated modules, sorted into packages.
https://github.com/gfarrell/resourcescontroller

Last synced: 2 months ago
JSON representation

A CakePHP plugin to manage resources like javascript and css files as separated modules, sorted into packages.

Awesome Lists containing this project

README

        

ResourcesController Plugin
===========================

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.

1. [License](#license-)
2. [Usage](#usage-)
3. [Sample Config](#sampleconfig-)
4. [Configuration File Documentation](#configurationfiledocumentation-)
5. [People](#people-)
6. [Other Credits](#othercredits-)

License
----------------------------

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.

Usage
---------------------------

First you need to have a config file *ResourcesController.xml* in your app's *Config* directory. See the [Sample Config](#sampleconfig-) 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`.

Sample Config
---------------------------------------------





OtherPackage:speciallib
CoolLibrary



OtherPackage:otherscript




...

Configuration File Documentation
-------------------------------------------------------------------------------

### \ *root node*
This root node is required.

### \ *package definition*
##### Required attributes:
- *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*)

##### Optional attributes:
- *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.

### \ *defines imported files/packages*
The import tag has no attributes, but contains either `` tags or `` tags.

##### \ *imported files*
Should be formatted as `package:file`

##### \ *imported packages*
Should just contain the package name.

### \ *the files in this package*
Each `` 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.

##### \ *file requirements*
There can be multiple `` nodes for each ``. 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 `` node).

People
------------------------------

* Originally developed by Gideon Farrell [](mailto:[email protected])

Other Credits
-------------------------------------

* JavascriptPacker from [http://joliclic.free.fr/php/javascript-packer/en/](http://joliclic.free.fr/php/javascript-packer/en/)
* LessPHP by leafo: [https://github.com/leafo/lessphp](https://github.com/leafo/lessphp)