Skip to content

Instantly share code, notes, and snippets.

@iambigd
Forked from notomato/gist:3463043
Created July 30, 2013 09:49
Show Gist options
  • Save iambigd/6111670 to your computer and use it in GitHub Desktop.
Save iambigd/6111670 to your computer and use it in GitHub Desktop.
<?php
namespace app\extensions\helper;
use Assetic\AssetWriter;
use Assetic\AssetManager;
use Assetic\FilterManager;
use Assetic\Asset\AssetCache;
use Assetic\Asset\AssetCollection;
use Assetic\Asset\FileAsset;
use Assetic\Asset\GlobAsset;
use Assetic\Cache\FilesystemCache;
use Assetic\Filter\LessphpFilter;
use Assetic\Filter\Yui;
use lithium\core\Environment;
class Assets extends \lithium\template\Helper {
public function styles() {
$filters = array(
'less' => new LessphpFilter(),
'css' => new Yui\CssCompressorFilter(LITHIUM_APP_PATH.'/vendor/nervo/yuicompressor/yuicompressor.jar')
);
$assets = array(
'bootstrap' => new FileAsset(LITHIUM_APP_PATH . '/assets/less/bootstrap/bootstrap.less', $filters['less']),
'bootstrap-wysihtml5' => new FileAsset(LITHIUM_APP_PATH . '/assets/css/bootstrap-wysihtml5.css'),
'app' => new FileAsset(LITHIUM_APP_PATH . '/assets/less/app.less', $filters['less'])
);
if (Environment::is('production')) {
$assetCollection = new AssetCollection($assets, array($filters['less'], $filters['css']));
} else {
$assetCollection = new AssetCollection($assets, array($filters['less']));
}
$assetCollection->setTargetPath('styles.css');
$cache = new AssetCache(
$assetCollection,
new FilesystemCache(LITHIUM_APP_PATH . '/resources/tmp/cache/assets')
);
$assetManager = new AssetManager();
$assetManager->set('styles', $cache);
$assetWriter = new AssetWriter(LITHIUM_APP_PATH.'/webroot/css');
$assetWriter->writeManagerAssets($assetManager);
echo $this->_context->helper('html')->style('styles') . "\n\t";
}
public function scripts() {
$filters = array(
'js' => new Yui\JsCompressorFilter(LITHIUM_APP_PATH.'/vendor/nervo/yuicompressor/yuicompressor.jar')
);
$assets = array(
'bootstrap' => new GlobAsset(LITHIUM_APP_PATH . '/assets/js/bootstrap/*.js', $filters['js']),
'editor' => new GlobAsset(LITHIUM_APP_PATH . '/assets/js/editor/*.js', $filters['js']),
'plugins' => new GlobAsset(LITHIUM_APP_PATH . '/assets/js/plugins/*.js', $filters['js']),
'application' => new GlobAsset(LITHIUM_APP_PATH . '/assets/js/app/*.js', $filters['js']),
'app' => new FileAsset(LITHIUM_APP_PATH . '/assets/js/app.js', $filters['js']),
);
if (Environment::is('production')) {
$assetCollection = new AssetCollection($assets, array($filters['js']));
} else {
$assetCollection = new AssetCollection($assets);
}
$assetCollection->setTargetPath('scripts.js');
$cache = new AssetCache(
$assetCollection,
new FilesystemCache(LITHIUM_APP_PATH . '/resources/tmp/cache/assets')
);
$assetManager = new AssetManager();
$assetManager->set('scripts', $cache);
$assetWriter = new AssetWriter(LITHIUM_APP_PATH.'/webroot/js');
$assetWriter->writeManagerAssets($assetManager);
echo $this->_context->helper('html')->script('scripts') . "\n\t";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment