Class: Lessc - X-Ref
The LESS compiler and parser.
Converting LESS to CSS is a three stage process. The incoming file is parsed
by `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, 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 dumped as strings. This
handles math equations, variable dereferences, and the like.
The `compile` function of `Lessc` is the entry point.
In summary:
The `Lessc` class creates an instance 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 `Parser` class is only concerned with parsing its input.
The `Formatter` takes a CSS tree, and dumps it to a formatted string,
handling things like indentation.
compile(string $string, ?string $name = null)
X-Ref
|
Compile the given LESS string into CSS
param: string $string LESS code
param: string|null $name optional filename to show in errors
|
compileFile(string $fname, ?string $outFname = null)
X-Ref
|
Parse the given File and return the compiled CSS.
If an output file is specified, the compiled CSS will be written to that file.
param: string $fname LESS file
param: string|null $outFname optional output file
return: int|string number of bytes written to file, or CSS if no output file
|
registerFunction(string $name, callable $func)
X-Ref
|
Register a custom function to be available in LESS
param: string $name name of function
param: callable $func callback
|
unregisterFunction(string $name)
X-Ref
|
Remove a function from being available in LESS
param: string $name The name of the function to unregister
|
setVariables($variables)
X-Ref
|
Add additional variables to the parser
Given variables are merged with any already set variables
param: array $variables [name => value, ...]
|
getVariables()
X-Ref
|
Get the currently set variables
return: array [name => value, ...]
|
setImportDir($dirs)
X-Ref
|
Set the directories to search for imports
Overwrites any previously set directories
param: string|string[] $dirs
|
enableImports(bool $enable)
X-Ref
|
Enable or disable import statements
There is usually no need to disable imports
param: bool $enable
return: void
|
setFormatter(?FormatterClassic $formatter = null)
X-Ref
|
Set the formatter to use for output
param: FormatterClassic|null $formatter Null for the default LessJs formatter
return: void
|
findImport(string $url)
X-Ref
|
attempts to find the path of an import url, returns null for css files
|
fileExists(string $name)
X-Ref
|
Check if a given file exists and is actually a file
param: string $name file path
return: bool
|
compileBlock($block)
X-Ref
|
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: compileProp()
|
deduplicate($lines)
X-Ref
|
Deduplicate lines in a block. Comments are not deduplicated. If a
duplicate rule is detected, the comments immediately preceding each
occurrence are consolidated.
|
compileValue($value)
X-Ref
|
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.
|
funcToColor($func)
X-Ref
|
Convert the rgb, rgba, hsl color literals of function type
as returned by the parser into values of color type.
|
makeParser(?string $name)
X-Ref
|
Create a new parser instance
param: string|null $name A name to identify the parser in error messages
|