Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Yii application component which wrappes lessphp
PHP
Branch: master
Failed to load latest commit information.
LessCompiler.php Update LessCompiler.php
README.md Update README.md

README.md

NEW REPOSITORY!!!

You can use this version of LessCompiler, but newer versions of this product are here, in new Git repository: https://github.com/Inpassor/yii-EAssetManager

From now LessCompiler made as advanced Asset Manager. .less files are compiled when you're trying to publish them. Like that: CHtml::asset(Yii::app()->basePath.'/vendors/bootstrap/less/bootstrap.less');

Yii_LessCompiler

Yii application component which wrappes lessphp

The main feature of this extention is what you can include .less files with Yii's CClientScript component the same way as .css files. Compiler automatically track all .less files for changes and recompiles output .css file on-the-fly (this feature can be disabled in production mode). Or, you can write command to compile .less files in background.

Author: Inpassor inpassor@mail.ru Link: https://github.com/Inpassor/Yii_LessCompiler Author: Leaf Corcoran leafot@gmail.com Link: http://leafo.net/lessphp

@version 0.3 (2013.10.08)

Installation

  1. Copy the LessCompiler.php file to your protected/extentions folder
  2. Download the latest version of lessphp from http://leafo.net/lessphp and put lessc.inc.php file under protected/extentions/LessCompiler folder
  3. Add a component to your protected/config/main.php like that:

    'components'=>array(

    'less'=>array(
        'class'=>'LessCompiler',
        'compiledPath'=>'application.assets.css', // path to store compiled css files
        'formatter'=>'lessjs', // - lessjs / compressed / classic , see http://leafo.net/lessphp/docs/#output_formatting for details
        'forceCompile'=>false, // passing in true will cause the input to always be recompiled
        'disabled'=>false, // if set to true .less files will not compile if .css file found
    ),
    

    ),

Usage

1)

Yii::app()->less->compileFile($fileInput,$fileOutput,$useCompiledPath);

Compiles less file to a css file. Returns compiled css file path and name.

$fileInput - input .less file to compile $fileOutput - output .css file name (optional). If not set, $fileOutput will have the same name as .less file, but its extention will be .css $useCompiledPath - optional parameter. Defaults to true. If set to false, LessCompiler's compiledPath option will not be used.

Examples:

Yii::app()->clientScript->registerCssFile(CHtml::asset(Yii::app()->less->compileFile(Yii::app()->basePath.'/vendors/bootstrap/less/bootstrap.less'))); Yii::app()->clientScript->registerCssFile(Yii::app()->less->compileFile(Yii::app()->basePath.'/vendors/bootstrap/less/bootstrap.less','css/main.css',false));

2)

Yii::app()->less->compile($css);

Compiles less string or file to a css string. Returns compiled css string.

$css - less string or file

Examples:

Yii::app()->clientScript->registerCss('CSS_block_id',Yii::app()->less->compile(Yii::app()->basePath.'/vendors/bootstrap/less/bootstrap.less')); Yii::app()->clientScript->registerCss('CSS_block_id',Yii::app()->less->compile('.block { padding: 3 + 4px }'));

Something went wrong with that request. Please try again.