2017 © Pedro Peláez
 

symfony-bundle assetic-importer-bundle

Integrates resource projects into Symfony2

image

apnet/assetic-importer-bundle

Integrates resource projects into Symfony2

  • Friday, July 8, 2016
  • by covex-nn
  • Repository
  • 0 Watchers
  • 1 Stars
  • 1,253 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 1 % Grown

The README.md

Assetic Importer Bundle

Travis-ci status SensioLabsInsight, (*1)

The main purpose of a Bundle is to exclude cssrewrite filter and to bypass known issue that causes the cssrewrite to fail when using the @AcmeFooBundle syntax for CSS Stylesheets., (*2)

Bundle allows you to import files from non-public directories via assetic directly into routing. These files can either be a result of an external program, or created on the fly from Symfony. Bundle и assetic keep track of changes to files automatically on every request., (*3)

Installation

Add requirements to composer.json:, (*4)

``` json { "require" : { "apnet/assetic-importer-bundle" : "~1.0" } }, (*5)


Register the bundle ------------------- Register the bundle in the `AppKernel.php` file ``` php // ...other bundles ... $bundles[] = new Apnet\AsseticImporterBundle\ApnetAsseticImporterBundle(); if ($this->getEnvironment() == 'dev') { // ...other bundles ... $bundles[] = new Apnet\AsseticWatcherBundle\ApnetAsseticWatcherBundle(); }

Configuration

Let's assume that you have two directories inside app/Resources:, (*6)

  1. app/Resources/simple_dir with style1.css file
  2. app/Resources/compass_dir with config.rb and all other compass-project files (e.g. sass/style2.scss and stylesheets/style2.css)

Then add the configuration into your config.yml, (*7)

``` yml apnet_assetic_importer: assets: dir1: source: %kernel.root_dir%/Resources/simple_dir target: example1 dir2: source: %kernel.root_dir%/Resources/compass_dir/config.rb target: example2 importer: compass, (*8)


After these changes two css files will be accessible via `/app_dev.php` 1. `/app_dev.php/example1/style1.css` 2. `/app_dev.php/example2/stylesheets/style2.css`. Also all files inside `css_dir`, `images_dir`, `javascripts_dir`, `fonts_dir` will ba available. `sass_dir` directory contents will be private. All files will be dumped with `assetic:dump` command. Twig ---- To include your CSS into Twig template use **imported_asset** function: ``` html <link href="{{ imported_asset('example1/style1.css') }}" rel="stylesheet" type="text/css" /> <link href="{{ imported_asset('example2/stylesheets/style2.css') }}" rel="stylesheet" type="text/css" />

Assetic Watcher Bundle

Actualy there are two bundles inside apnet/assetic-importer-bundle:, (*9)

  1. Apnet\AsseticImporterBundle
  2. Apnet\AsseticWatcherBundle

Watcher is a tool, that could be used with dev environment to compile compass project without any external file watchers or IDE., (*10)

  • Of course Apache user needs write permissions to the compass_dir/stylesheets directory

AsseticWatcherBundle is disabled by default., (*11)

Configuration

First, to enable Assetic Watcher add these lines to config_dev.yml, (*12)

``` yml apnet_assetic_watcher: compiler_root: %kernel.root_dir%/Resources enabled: true, (*13)


And second, add `watcher` parameter to imported asset configuration in `config.yml` ``` yml apnet_assetic_importer: assets: # ... dir2: source: %kernel.root_dir%/Resources/compass_dir/config.rb target: example2 importer: compass watcher: true

The Versions