assetic.rst 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. AsseticServiceProvider
  2. ================
  3. The *AsseticServiceProvider* provides powerful asset management
  4. through Kris Wallsmith's `Assetic <https://github.com/kriswallsmith/assetic>`_
  5. library.
  6. Parameters
  7. ----------
  8. * **assetic.path_to_web**: Location where to dump all generated files
  9. * **assetic.options**: An associative array of assetic options.
  10. * **assetic.options => debug** (defaults to false, optional):
  11. * **assetic.options => formulae_cache_dir** (optional): When formulae_cache_dir is set, Assetic
  12. will cache assets generated trough formulae in this folder to improve performance. Remember,
  13. assets added trough the AssetManager need to care about their own cache.
  14. * **assetic.options => auto_dump_assets** (defaults to true,optional): Whether to write all the assets
  15. to filesystem on every request.
  16. Services
  17. --------
  18. * **assetic**: Instance of AssetFactory for
  19. holding filters and assets (not formulae)
  20. * **assetic.asset_manager**: Instance of AssetManager
  21. for adding assets (implements AssetInterface)
  22. Example usage::
  23. $asset = new FileAsset(__DIR__ . '/extra/*.css');
  24. $app['assetic.asset_manager']->set('extra_css', $asset);
  25. * **assetic.filter_manager**: Instance of FilterManager
  26. for adding filters (implements FilterInterface)
  27. Example usage::
  28. $filter = new CssMinFilter();
  29. $app['assetic.filter_manager']->set('css_min', $filter);
  30. * **assetic.asset_writer**: If you need it, feel free to use.
  31. * **assetic.lazy_asset_manager**: Instance of LazyAssetManager
  32. to enable passing-in assets as formulae
  33. Example usage::
  34. $app['assetic.lazy_asset_manager']->setFormula('extra_css', array(
  35. array(__DIR__ . '/extra/*.css'),
  36. array('yui_css'),
  37. array('output' => 'css/extra')
  38. ));
  39. * **assetic.dumper**: Instance of SilexAssetic\Assetic\Dumper. Contains methods
  40. to dump assets.
  41. Registering
  42. -----------
  43. Example registration and configuration::
  44. $app->register(new SilexAssetic\AsseticServiceProvider());
  45. $app['assetic.path_to_web'] = __DIR__ . '/assets';
  46. $app['assetic.options'] = array(
  47. 'debug' => true,
  48. );
  49. $app['assetic.filter_manager'] = $app->share(
  50. $app->extend('assetic.filter_manager', function($fm, $app) {
  51. $fm->set('yui_css', new Assetic\Filter\Yui\CssCompressorFilter(
  52. '/usr/share/yui-compressor/yui-compressor.jar'
  53. ));
  54. $fm->set('yui_js', new Assetic\Filter\Yui\JsCompressorFilter(
  55. '/usr/share/yui-compressor/yui-compressor.jar'
  56. ));
  57. return $fm;
  58. })
  59. );
  60. $app['assetic.asset_manager'] = $app->share(
  61. $app->extend('assetic.asset_manager', function($am, $app) {
  62. $am->set('styles', new Assetic\Asset\AssetCache(
  63. new Assetic\Asset\GlobAsset(
  64. __DIR__ . '/resources/css/*.css',
  65. array($app['assetic.filter_manager']->get('yui_css'))
  66. ),
  67. new Assetic\Cache\FilesystemCache(__DIR__ . '/cache/assetic')
  68. ));
  69. $am->get('styles')->setTargetPath('css/styles.css');
  70. return $am;
  71. })
  72. );