1[![Build Status](https://travis-ci.org/MarcusSchwarz/lesserphp.svg)](https://travis-ci.org/MarcusSchwarz/lesserphp) 2 3# lesserphp v0.6.0 4### <http://github.com/MarcusSchwarz/lesserphp> 5 6`lesserphp` is a compiler for LESS written in PHP. It is based on lessphp bei leafo. 7The documentation is great, 8so check it out: <http://leafo.net/lessphp/docs/>. 9 10Here's a quick tutorial: 11 12### How to use in your PHP project 13 14The only file required is `lessc.inc.php`, so copy that to your include directory. 15 16The typical flow of **lesserphp** is to create a new instance of `lessc`, 17configure it how you like, then tell it to compile something using one built in 18compile methods. 19 20The `compile` method compiles a string of LESS code to CSS. 21 22```php 23<?php 24require "lessc.inc.php"; 25 26$less = new lessc; 27echo $less->compile(".block { padding: 3 + 4px }"); 28``` 29 30The `compileFile` method reads and compiles a file. It will either return the 31result or write it to the path specified by an optional second argument. 32 33```php 34<?php 35echo $less->compileFile("input.less"); 36``` 37 38The `checkedCompile` method is like `compileFile`, but it only compiles if the output 39file doesn't exist or it's older than the input file: 40 41```php 42<?php 43$less->checkedCompile("input.less", "output.css"); 44``` 45 46If there any problem compiling your code, an exception is thrown with a helpful message: 47 48```php 49<?php 50try { 51 $less->compile("invalid LESS } {"); 52} catch (\Exception $e) { 53 echo "fatal error: " . $e->getMessage(); 54} 55``` 56 57The `lessc` object can be configured through an assortment of instance methods. 58Some possible configuration options include [changing the output format][1], 59[setting variables from PHP][2], and [controlling the preservation of 60comments][3], writing [custom functions][4] and much more. It's all described 61in [the documentation][0]. 62 63 64 [0]: http://leafo.net/lessphp/docs/ 65 [1]: http://leafo.net/lessphp/docs/#output_formatting 66 [2]: http://leafo.net/lessphp/docs/#setting_variables_from_php 67 [3]: http://leafo.net/lessphp/docs/#preserving_comments 68 [4]: http://leafo.net/lessphp/docs/#custom_functions 69 70 71### How to use from the command line 72 73An additional script has been included to use the compiler from the command 74line. In the simplest invocation, you specify an input file and the compiled 75css is written to standard out: 76 77 $ plessc input.less > output.css 78 79Using the -r flag, you can specify LESS code directly as an argument or, if 80the argument is left off, from standard in: 81 82 $ plessc -r "my less code here" 83 84Finally, by using the -w flag you can watch a specified input file and have it 85compile as needed to the output file: 86 87 $ plessc -w input-file output-file 88 89Errors from watch mode are written to standard out. 90 91The -f flag sets the [output formatter][1]. For example, to compress the 92output run this: 93 94 $ plessc -f=compressed myfile.less 95 96For more help, run `plessc --help` 97 98