Plugins
Resources
Official documentation is now available, along with a Vim syntax file.
About
lessphp is a compiler for LESS written in php.
The entire compiler comes in a single includable class, but an additional command line interface to the compiler is included. See the quick start for basic usage.
For a gentle introduction to LESS, take a look at LESS classic guide, and to explore some of the more advanced features available in the php version, have look at the lessphp official documentation.
Note: This software is far from mature and is being updated on a regular basis. For the best experience check back here frequently for new versions, or subscribe to the update feed.
Missing Features
If you see something here that isn't listed, or you have found a bug feel free to leave a comment or post on the github issues tracker. The following are planned for future releases.
- hsl colors
- some cs3 selectors and properties (nested block css selectors)
- recursively merging sub-blocks of the same name
Download
repo: http://github.com/leafo/lessphp/tree/master
stable: lessphp-0.1.6.tar.gz
Demo
Use the demo to test the compiler running on this server using your own code, or click through the example buttons to see more of LESS.
More Examples: variables, mixins, nested rules, accessors, namespaces, mixin functions
|
LESS goes here |
CSS comes here |
Quick Start
There are a few ways to interface with the compiler. The easiest is to have it
compile a LESS file when the page is requested. The static function
less::ccompile, checked compile, will compile the input LESS file only when it
is newer than the output file.
require 'lessc.inc.php'; try { lessc::ccompile('input.less', 'out.css'); } catch (exception $ex) { exit('lessc fatal error:<br />'.$ex->getMessage()); }
Note that all failures with lessc are reported through exceptions.
If you need more control you can make your own instance of lessc.
require 'lessc.inc.php'; $less = new lessc('path/to/style.less'); file_put_contents('path/to/style.css', $less->parse());
In addition to loading from file, you can also parse from a string like so:
require 'lessc.inc.php'; $less = new lessc(); $style = '<style type="text/css">'. $less->parse('.block { padding: 3 + 4px }'). '</style>';
Changelog
version 0.1.6 - August 21 2009- rewrote command line tool, plessc, with more logical argument parsing and proper exit codes
- separate blocks of the same name will now merge instead of overwriting each over
- fixed a bug with any type of mixin not searching outside the scope
- updated this webpage
- happy 1 month anniversary ;)
version 0.1.5 - August 6 2009- wrote documentation, see http://leafo.net/lessphp/docs/
- added support for variables inside of strings
- mixins append their data into the block instead of overwriting
- fixed a bug where rgb was being ignored since 0.1.4
version 0.1.4 - August 4 2009- blocks that start with @ are treated as abstract blocks and are not printed out
- all blocks/mixins can now take argument lists (with default args) and be treated as functions
- fixed bug with nested blocks inside of a mixin printing the name of the mixin
- added the ability to specify import directory for @import
- the correct import directory is figured out automatically when you compile from file path
- fixed bug with @import and comments in imported file
version 0.1.3 - July 28 2009- setting variables to themselves in equations works how you expect
- parentheses are supported in arithmetic
- all variables and arithmetic do lazy evaluation, variables are set to the equation and not the value
- code no longer throws php notices
version 0.1.2-1 - July 23 2009 bugfix- issue with comments and whitespace on head of document fixed
version 0.1.2 - July 23 2009- Performance enhancements (50% faster compile for average case)
- Accepts more native css properties and values (still some trouble with more advanced css3 stuff)
- Better string support in general
- Comments will no longer be interpreted from within strings
version 0.1.1 - July 22 2009- New @import parsing, supports media
- Repeated properties are all written instead of overwriting each other
- Support for additional css properties and values that were left out
- New comment parsing prevents comments inside of strings from being removed
- Added a static compile on demand function to lessc
- Updated command line utility significantly
- Fixed color rendering bug for small rgb values
version 0.1.0 - July 21 2009 Initial releaseComments
If you have a github account, you can post bug reports on the github issues tracker.
August 21 2009 - leaf corcoran
@a: 2;
@x: @a * @a;
@y: @x + 1;
@z: @x * 2 + @y;
@nice-blue: #5B83AD;
@light-blue: @nice-blue + #111;
@b: @a * 10;
@c: #888;
@fonts: "Trebuchet MS", Verdana, sans-serif;
.variables {
width: @z + 1cm; // 14cm
height: @b + @x + 0px; // 24px
color: @c;
background: @light-blue;
font-family: @fonts;
}
.bordered {
border-top: dotted 1px black;
border-bottom: solid 2px black;
}
#menu a {
color: #111;
.bordered;
}
.post a {
color: red;
.bordered;
}
#header {
color: black;
.navigation {
font-size: 12px;
}
.logo {
width: 300px;
:hover { text-decoration: none }
}
}
#defaults {
@width: 960px;
@color: black;
}
.article { color: #294366; }
.comment {
width: #defaults[@width];
color: .article['color'];
}
#bundle {
.button {
display: block;
border: 1px solid black;
background-color: grey;
:hover { background-color: white }
}
}
#header a {
color: orange;
#bundle > .button; // mixin the button class
}
@outer: 10px;
@class(@var:22px; @car: 400px + @outer) {
margin: @var;
height: @car;
}
@group {
@f(@color) {
color: @color;
}
.cool {
border-bottom: 1px solid green;
}
}
.class(@width:200px) {
padding: @width;
}
body {
.class(2.0em);
@group > @f(red);
@class(10px; 10px + 2);
@group > .cool;
}