Less Service Provider for Silex
Simple less php service provider for Silex that uses https://github.com/leafo/lessphp as parser., (*1)
You'll find the following topics in this README:
* Dependencies
* Installation
* Configuration
* Usage, (*2)
Dependencies
Installation
You basically have three options to add this extension to your Silex project. We'd strongly recommend the first option!, (*3)
composer.json
http://packagist.org/packages/fredjuvaux/silex-less-provider, (*4)
php composer.phar require fredjuvaux/silex-less-provider dev-master
Or add to the dependencies in your projects composer.json file and update your dependencies::, (*5)
"fredjuvaux/silex-less-provider": "dev-master"
php composer.phar update
This is by far the easiest way, since it automatically adds the Doctrine dependencies and adds everything to the autoloading mechanism supplied by Composer., (*6)
More information on Composer can be found on getcomposer.org., (*7)
Git
Another option is to clone the project:, (*8)
cd /path/to/your_project/vendor
git clone git@github.com:fredjuvaux/silex-less-provider.git
Or you can add it as a submodule if your project is in a git repository too:, (*9)
cd /path/to/your_project
git submodule add git@github.com:fredjuvaux/silex-less-provider.git
This will require you to manually install all the dependencies. Also note that you'll need to add the provider to the Silex autoloader (or whatever autoloading mechanism) by hand. More on both subjects can be found below., (*10)
Download an archive
GitHub also gives you the option to download an ZIP-archive, which you can extract in your vendor folder. This method will also require you to manually install all the dependencies and add everything to your autoloader., (*11)
Configuration
Registering the Less Service Provider is rather straight forward:, (*12)
<?php
/* ... */
use Less\Provider\LessServiceProvider;
$app->register(new LessServiceProvider(), array(
'less.source_dir' => array(__DIR__.'/../web/less/'), // specify one or serveral directories for sources
'less.cache_dir' => __DIR__.'/../var/cache/', // specify one directory for caching files
'less.target_dir' => __DIR__.'/../web/css/', // specify one directory for compiled files
));
Use
The Less files have to be in sources directories. The files are cached and regenerated if it's needed.
In the Twig view, you have to call the css generated files (in less.target_dir)., (*13)