Skip to content

Commit

Permalink
Several changes:
Browse files Browse the repository at this point in the history
* Updated the less compiler to the latest version
* Added code to prevent adding the same asset more than once
* Added an option to defer processing/combining assets to a controller
* Reorganized Casset to be a Facade
  • Loading branch information
mmanos committed Sep 10, 2014
1 parent 99dab0f commit 846a4a4
Show file tree
Hide file tree
Showing 8 changed files with 320 additions and 58 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ Casset is an asset manager for Laravel 4 applications. Some things it can do:
* Accept assets from Laravel package public directories. `"package::/js/file.js"`
* Define dependencies for an asset.
* Define global dependencies for all assets of the same file type.
* Define an optional CDN for asset URLs.
* Optionally defer processing/combining assets to a controller (useful when distributing page requests across multiple servers).

Installation via Composer
-------------------------

Add this to you composer.json file, in the require object:
Add this to your composer.json file, in the require object:

```javascript
"mmanos/laravel-casset": "dev-master"
Expand All @@ -36,7 +38,7 @@ Add a class alias to `app/config/app.php`, within the `aliases` array.
```php
'aliases' => array(
// ...
'Casset' => 'Mmanos\Casset\Casset',
'Casset' => 'Mmanos\Casset\Facades\Casset',
)
```

Expand All @@ -56,6 +58,18 @@ Edit public/assets/cache/.gitignore.
!.gitignore
```

Upgrading to 1.3 from 1.2.x
---------------------------

Simply update the class alias in `app/config/app.php` to point to the new Facade:

```php
'aliases' => array(
// ...
'Casset' => 'Mmanos\Casset\Facades\Casset',
)
```

Usage
-----

Expand Down Expand Up @@ -96,6 +110,12 @@ Casset::add('jquery::/jquery.min.js');
Render HTML tags to load assets for a container:

```php
echo Casset::container('default')->styles();
echo Casset::container('layout')->scripts();
{{ Casset::container('default')->styles() }}
{{ Casset::container('layout')->scripts() }}
```

Generate a URL to an asset on the CDN server:

```php
<img src="{{ Casset::cdn('logo.png') }}" />
```
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
"require": {
"php": ">=5.3.0",
"illuminate/support": "4.x",
"oyejorge/less.php": "1.6.*"
"oyejorge/less.php": "1.7.*"
},
"autoload": {
"classmap": [
"src/migrations"
"src/migrations",
"src/controllers"
],
"psr-0": {
"Mmanos\\Casset": "src/"
Expand Down
27 changes: 12 additions & 15 deletions src/Mmanos/Casset/Casset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Casset
*
* @var array
*/
public static $containers = array();
protected $containers = array();

/**
* Retrieve the requested asset container object.
Expand All @@ -16,28 +16,25 @@ class Casset
*
* @return Container
*/
public static function container($container = 'default')
public function container($container = 'default')
{
if (!isset(static::$containers[$container])) {
static::$containers[$container] = new Container($container);
if (!isset($this->containers[$container])) {
$this->containers[$container] = new Container($container);
}

return static::$containers[$container];
return $this->containers[$container];
}

/**
* Magic Method for calling methods on the default container.
* Provide convenient access to methods on the default container.
*
* <code>
* // Call the "add" method on the default container
* Casset::add('js/jquery.js');
*
* // Or load an asset from a package
* Casset::add('package::js/file.js')
* </code>
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public static function __callStatic($method, $parameters)
public function __call($method, array $parameters)
{
return call_user_func_array(array(static::container(), $method), $parameters);
return call_user_func_array(array($this->container(), $method), $parameters);
}
}
21 changes: 14 additions & 7 deletions src/Mmanos/Casset/CassetServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?php namespace Mmanos\Casset;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Config;

class CassetServiceProvider extends ServiceProvider {

class CassetServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

/**
* Bootstrap the application events.
*
Expand All @@ -19,18 +21,24 @@ class CassetServiceProvider extends ServiceProvider {
public function boot()
{
$this->package('mmanos/laravel-casset');

if ($route = Config::get('laravel-casset::route')) {
Route::get(trim($route, '/') . '/{type}', 'Mmanos\Casset\CassetController@getIndex');
}
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
$this->app->bindShared('casset', function ($app) {
return new Casset;
});
}

/**
* Get the services provided by the provider.
*
Expand All @@ -40,5 +48,4 @@ public function provides()
{
return array();
}

}
Loading

0 comments on commit 846a4a4

Please sign in to comment.