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