Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leafo/lessphp
LESS compiler written in PHP
https://github.com/leafo/lessphp
Last synced: 11 days ago
JSON representation
LESS compiler written in PHP
- Host: GitHub
- URL: https://github.com/leafo/lessphp
- Owner: leafo
- License: other
- Created: 2009-07-21T04:00:36.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2024-05-16T00:46:15.000Z (6 months ago)
- Last Synced: 2024-10-14T12:04:47.440Z (26 days ago)
- Language: PHP
- Homepage: http://leafo.net/lessphp
- Size: 820 KB
- Stars: 2,197
- Watchers: 103
- Forks: 528
- Open Issues: 219
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/leafo/lessphp.svg?branch=master)](https://travis-ci.org/leafo/lessphp)
# lessphp v0.5.0
###`lessphp` is a compiler for LESS written in PHP. The documentation is great,
so check it out: .Here's a quick tutorial:
### How to use in your PHP project
The only file required is `lessc.inc.php`, so copy that to your include directory.
The typical flow of **lessphp** is to create a new instance of `lessc`,
configure it how you like, then tell it to compile something using one built in
compile methods.The `compile` method compiles a string of LESS code to CSS.
```php
compile(".block { padding: 3 + 4px }");
```The `compileFile` method reads and compiles a file. It will either return the
result or write it to the path specified by an optional second argument.```php
compileFile("input.less");
```The `checkedCompile` method is like `compileFile`, but it only compiles if the output
file doesn't exist or it's older than the input file:```php
checkedCompile("input.less", "output.css");
```If there any problem compiling your code, an exception is thrown with a helpful message:
```php
compile("invalid LESS } {");
} catch (exception $e) {
echo "fatal error: " . $e->getMessage();
}
```The `lessc` object can be configured through an assortment of instance methods.
Some possible configuration options include [changing the output format][1],
[setting variables from PHP][2], and [controlling the preservation of
comments][3], writing [custom functions][4] and much more. It's all described
in [the documentation][0].[0]: http://leafo.net/lessphp/docs/
[1]: http://leafo.net/lessphp/docs/#output_formatting
[2]: http://leafo.net/lessphp/docs/#setting_variables_from_php
[3]: http://leafo.net/lessphp/docs/#preserving_comments
[4]: http://leafo.net/lessphp/docs/#custom_functions### How to use from the command line
An additional script has been included to use the compiler from the command
line. In the simplest invocation, you specify an input file and the compiled
css is written to standard out:$ plessc input.less > output.css
Using the -r flag, you can specify LESS code directly as an argument or, if
the argument is left off, from standard in:$ plessc -r "my less code here"
Finally, by using the -w flag you can watch a specified input file and have it
compile as needed to the output file:$ plessc -w input-file output-file
Errors from watch mode are written to standard out.
The -f flag sets the [output formatter][1]. For example, to compress the
output run this:$ plessc -f=compressed myfile.less
For more help, run `plessc --help`