saxulum / saxulum-assetic-twig-provider
Saxulum Assetic Twig Provider
Installs: 1 675
Dependents: 1
Suggesters: 1
Security: 0
Stars: 6
Watchers: 0
Forks: 2
Open Issues: 0
pkg:composer/saxulum/saxulum-assetic-twig-provider
Requires
- php: >=5.3.3,<8.0
- kriswallsmith/assetic: ~1.2
- pimple/pimple: >=2.1,<4
- symfony/finder: ~2.3|~3.0
- symfony/http-foundation: ~2.3|~3.0
- twig/twig: ~1.2
Requires (Dev)
- cssmin/cssmin: ~3.0.1
- leafo/scssphp: v0.4
- mrclay/minify: ~2.2.0
- oyejorge/less.php: ~1.7
- phpunit/phpunit: ~4.1
- psr/log: ~1.0
- silex/api: ~2.0@dev
- silex/providers: ~2.0@dev
Suggests
- cssmin/cssmin: ~3.0.1
- leafo/scssphp: v0.4
- mrclay/minify: ~2.2.0
- oyejorge/less.php: ~1.7
- psr/log: ~1.0
- saxulum/saxulum-console: ~3.1
- silex/api: ~2.0@dev
- silex/providers: ~2.0@dev
README
works with plain silex-php
Features
- Add assetic support for twig templates
Requirements
- PHP 5.3+
- Kriswallsmith's Assets Framework (Assetic) 1.2+
- Symfony Finder Component 2.3+
- Twig 1.2+
Installation
Through Composer as saxulum/saxulum/saxulum-assetic-twig-provider.
$app->register(new TwigServiceProvider());
$app['twig.loader.filesystem'] = $app->share($app->extend('twig.loader.filesystem',
    function (\Twig_Loader_Filesystem $twigLoaderFilesystem) {
        $twigLoaderFilesystem->addPath('/path/to/the/views', 'SomeNamespace');
        return $twigLoaderFilesystem;
    }
));
$app->register(new AsseticTwigProvider(), array(
    'assetic.asset.root' => '/path/to/project/root',
    'assetic.asset.asset_root' => '/path/to/asset/root',
));
Configuration
This filter are preconfigured, and active per default:
- csscopyfile
- lessphp
- scssphp
- cssmin
- csscompress
- jsmin
If you want to disable a default filter:
$app['assetic.filters'] = $container->share(
    $app->extend('assetic.filters', function ($filters) use ($app) {
        $filters['cssmin'] = false;
        return $filters;
    })
);
If you want to add more filters, which aren't preconfigured:
$container['assetic.filterinstances'] = $container->share(
    $app->extend('assetic.filterinstances', function ($filterInstances) use ($container) {
        $filterInstances['jsminplus'] = new JSMinPlusFilter();
        return $filterInstances;
    })
);
Usage
CSS example
{% stylesheets
    'relative/from/path/to/project/root/*.css'
    output='relative/from/path/to/asset/root/css/test.css'
    filter='cssmin'
%}
    {{ asset_url }}
{% endstylesheets %}
JS example
{% javascripts
    'relative/from/path/to/project/root/*.js'
    output='relative/from/path/to/asset/root/css/test.js'
    filter='jsmin'
%}
    {{ asset_url }}
{% endjavascripts %}
Copyright
- Dominik Zogg [email protected]