marcusschwarz / lesserphp
lesserphp is a compiler for LESS written in PHP based on leafo's lessphp.
Installs: 6 862 630
Dependents: 5
Suggesters: 0
Security: 0
Stars: 26
Watchers: 10
Forks: 528
Open Issues: 7
Requires
- php: ^7.2|^7.3|^7.4|^8.0
Requires (Dev)
- phpunit/phpunit: ^8.0|^9.0
This package is auto-updated.
Last update: 2024-11-11 03:47:54 UTC
README
lesserphp dev-master
http://github.com/MarcusSchwarz/lesserphp
Please note: Please bear in mind, the master branch is not up-to-date with the release branch, which is 0.6-dev. Bug fixes should go to branch 0.6-dev (php7.2 and greater) or 0.5-dev (php5.6 to php7.4). Thank you!
lesserphp
is a compiler for LESS written in PHP. It is based on lessphp bei leafo.
The documentation is great,
so check it out: https://www.maswaba.de/lesserphpdocs/.
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 lesserphp 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 require "lessc.inc.php"; $less = new lessc; echo $less->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 echo $less->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 $less->checkedCompile("input.less", "output.css");
If there any problem compiling your code, an exception is thrown with a helpful message:
<?php try { $less->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,
setting variables from PHP, and controlling the preservation of
comments, writing custom functions and much more. It's all described
in the documentation.
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. For example, to compress the output run this:
$ plessc -f=compressed myfile.less
For more help, run plessc --help