$VERSION
$VERSION
The less compiler and parser.
Converting LESS to CSS is a three stage process. The incoming file is parsed
by lessc_parser
into a syntax tree, then it is compiled into another tree
representing the CSS structure by lessc
. The CSS tree is fed into a
formatter, like lessc_formatter
which then outputs CSS as a string.
During the first compile, all values are reduced, which means that their types are brought to the lowest form before being dump as strings. This handles math equations, variable dereferences, and the like.
The parse
function of lessc
is the entry point.
In summary:
The lessc
class creates an intstance of the parser, feeds it LESS code,
then transforms the resulting tree to a CSS tree. This class also holds the
evaluation context, such as all available mixins and variables at any given
time.
The lessc_parser
class is only concerned with parsing its input.
The lessc_formatter
takes a CSS tree, and dumps it to a formatted string,
handling things like indentation.
cachedCompile(mixed $in, bool $force) : array
Execute lessphp on a .less file or a lessphp cache structure
The lessphp cache structure contains information about a specific less file having been parsed. It can be used as a hint for future calls to determine whether or not a rebuild is required.
The cache structure contains two important keys that may be used externally:
compiled: The final compiled CSS updated: The time (in seconds) the CSS was last compiled
The cache structure is a plain-ol' PHP associative array and can be serialized and unserialized without a hitch.
mixed | $in | Input |
bool | $force | Force rebuild? |
lessphp cache structure
compileBlock( $block)
Recursively compiles a block.
A block is analogous to a CSS block in most cases. A single LESS document is encapsulated in a block when parsed, but it does not have parent tags so all of it's children appear on the root level when compiled.
Blocks are made up of props and children.
Props are property instructions, array tuples which describe an action to be taken, eg. write a property, set a variable, mixin a block.
The children of a block are just all the blocks that are defined within. This is used to look up mixins when performing a mixin.
Compiling the block involves pushing a fresh environment on the stack, and iterating through the props, compiling each one.
See lessc::compileProp()
$block |
compileValue( $value)
Compiles a primitive value into a CSS property value.
Values in lessphp are typed by being wrapped in arrays, their format is typically:
array(type, contents [, additional_contents]*)
The input is expected to be reduced. This function will not work on things like expressions and variables.
$value |