Created
November 26, 2012 01:05
-
-
Save dcsg/4146071 to your computer and use it in GitHub Desktop.
phplx - Introduction to Assetic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// require 'path/to/vendor/autoload.php'; | |
use Assetic\Asset\FileAsset; | |
$asset = new FileAsset('path/to/file.js'); | |
header('Content-Type: application/javasript'); | |
echo $asset->dump(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// require 'path/to/vendor/autoload.php'; | |
use Assetic\Asset\FileAsset; | |
use Assetic\Asset\GlobAsset; | |
use Assetic\Filter\Yui\JsCompressorFilter; | |
$filter = new JsCompressorFilter('path/to/yui/compressor.jar'); | |
$collection = new AssetCollection(array( | |
new FileAsset('/path/to/js/site.js'), | |
new GlobAsset('/path/to/js/jquery/*.js') | |
), array($filter)); | |
header('Content-Type: application/javasript'); | |
echo $collection->dump(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// require 'path/to/vendor/autoload.php'; | |
use Assetic\Asset\GlobAsset; | |
use Assetic\Filter\Yui\CssCompressorFilter; | |
use Assetic\Filter\LessFilter; | |
$filter = new CssCompressorFilter('path/to/yui/compressor.jar'); | |
$collection = new AssetCollection(array( | |
new AssetCollection( | |
array(new FileAsset('path/to/less/file.less')), | |
array(new LessFilter()) | |
), | |
new GlobAsset('/path/to/css/*.css') | |
), array($filter)); | |
header('Content-Type: text/css'); | |
echo $collection->dump(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// require 'path/to/vendor/autoload.php'; | |
// require 'path/to/asset_manager_and_reference.php'; | |
// require 'path/to/filter_manager.php'; | |
use Assetic\Factory\AssetFactory; | |
$factory = new AssetFactory('/path/to/assets/directory/'); | |
$factory->setAssetManager($assetManager); | |
$factory->setFilterManager($filterManager); | |
$factory->setDebug(true); | |
$js = $factory->createAsset( | |
array( | |
'@custom_plugin', // load the asset manager's "custom_plugin" asset | |
'js/3rd-party/*.js', // load every js files from "/path/to/assets/directory/js/3rd-party/" | |
), | |
array( | |
'?yui_js', // will not be used in debug mode | |
) | |
); | |
header('Content-Type: application/javasript'); | |
echo $js->dump(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// require 'path/to/vendor/autoload.php'; | |
use Assetic\Asset\FileAsset; | |
use Assetic\Asset\AssetReference; | |
use Assetic\AssetManager; | |
use Assetic\Filter\Yui\JsCompressorFilter; | |
$filter = new JsCompressorFilter('path/to/yui/compressor.jar'); | |
// Simple usage of Asset Manager | |
$assetManager = new AssetManager(); | |
$assetManager->set('jquery', new FileAsset('path/to/js/jquery.js', array($filter))); | |
// Add the asset reference to avoid duplication | |
$assetManager->set('custom_plugin', new AssetCollection(array( | |
new AssetReference($manager, 'jquery'), | |
new FileAsset('path/to/js/jquery.plugin.js') | |
), array($filter))); | |
header('Content-Type: application/js'); | |
//echo $assetManager->get('jquery')->dump(); | |
echo $assetManager->get('custom_plugin')->dump(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// require 'path/to/vendor/autoload.php'; | |
use Assetic\Asset\FileAsset; | |
use Assetic\Filter\Yui\JsCompressorFilter; | |
$filter = new JsCompressorFilter('path/to/yui/compressor.jar'); | |
$asset = new FileAsset('path/to/file.js', array($filter)); | |
header('Content-Type: application/javasript'); | |
echo $asset->dump(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// require 'path/to/vendor/autoload.php'; | |
use Assetic\FilterManager; | |
use Assetic\Filter\Sass\SassFilter; | |
use Assetic\Filter\LessFilter; | |
use Assetic\Filter\Yui\JsCompressorFilter; | |
$filterManager = new FilterManager(); | |
$filterManager->set('sass', new SassFilter('/path/to/sass/parser')); | |
$filterManager->set('less', new LessFilter()); | |
$filterManager->set('yui_js', new JsCompressorFilter('/path/to/yuicompressor.jar')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment