apnet/assetic-importer-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Integrates resource projects into Symfony2

Installs: 1 425

Dependents: 4

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.4.0 2016-07-08 13:17 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:33:38 UTC


README

Travis-ci status SensioLabsInsight

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.

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.

Installation

Add requirements to composer.json:

{
  "require" : {
    "apnet/assetic-importer-bundle" : "~1.0"
  }
}

Register the bundle

Register the bundle in the AppKernel.php file

// ...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:

  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

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

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:

<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:

  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.

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

AsseticWatcherBundle is disabled by default.

Configuration

First, to enable Assetic Watcher add these lines to config_dev.yml

apnet_assetic_watcher:
    compiler_root: %kernel.root_dir%/Resources
    enabled: true

And second, add watcher parameter to imported asset configuration in config.yml

apnet_assetic_importer:
    assets:
        # ...
        dir2:
            source: %kernel.root_dir%/Resources/compass_dir/config.rb
            target: example2
            importer: compass
            watcher: true