[ Index ]

PHP Cross Reference of DokuWiki




/vendor/splitbrain/lesserphp/src/ -> Lessc.php (summary)

http://leafo.net/lessphp LESS CSS compiler, adapted from http://lesscss.org

File Size: 1746 lines (53 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Lessc:: (60 methods):

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

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.
__construct()   X-Ref
Initialize the LESS Parser

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.

return: int|string number of bytes written to file, or CSS if no output file
param: string $fname LESS file
param: string|null $outFname optional output file

setPreserveComments(bool $preserve)   X-Ref
Should comments be preserved in the output?

Default is false

param: bool $preserve

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, ...]

unsetVariable(string $name)   X-Ref
Remove a currently set variable

param: string $name

setImportDir($dirs)   X-Ref
Set the directories to search for imports

Overwrites any previously set directories

param: string|string[] $dirs

addImportDir(string $dir)   X-Ref
Add an additional directory to search for imports

enableImports(bool $enable)   X-Ref
Enable or disable import statements

There is usually no need to disable imports

return: void
param: bool $enable

setFormatter(?FormatterClassic $formatter = null)   X-Ref
Set the formatter to use for output

return: void
param: FormatterClassic|null $formatter Null for the default LessJs formatter

registerLibraryFunctions()   X-Ref
Register all the default functions

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

return: bool
param: string $name file path

compressList($items, $delim)   X-Ref

tryImport($importPath, $parentBlock, $out)   X-Ref

compileImportedProps($props, $block, $out, $sourceParser, $importDir)   X-Ref

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()

compileCSSBlock($block)   X-Ref

compileMedia($media)   X-Ref

mediaParent($scope)   X-Ref
No description

compileNestedBlock($block, $selectors)   X-Ref

compileRoot($root)   X-Ref

compileProps($block, $out)   X-Ref

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.

sortProps($props, $split = false)   X-Ref
No description

compileMediaQuery($queries)   X-Ref

multiplyMedia($env, $childQueries = null)   X-Ref
No description

expandParentSelectors(&$tag, $replace)   X-Ref
No description

findClosestSelectors()   X-Ref
No description

multiplySelectors($selectors)   X-Ref
No description

compileSelectors($selectors)   X-Ref
reduces selector expressions

eq($left, $right)   X-Ref
No description

patternMatch($block, $orderedArgs, $keywordArgs)   X-Ref

return: bool

patternMatchAll($blocks, $orderedArgs, $keywordArgs, $skip = [])   X-Ref

findBlocks($searchIn, $path, $orderedArgs, $keywordArgs, $seen = [])   X-Ref
attempt to find blocks matched by path and args

zipSetArgs($args, $orderedValues, $keywordValues)   X-Ref
sets all argument names in $args to either the default value
or the one passed in through $values

compileProp($prop, $block, $out)   X-Ref
compile a prop and update $lines or $blocks appropriately

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

array(type, contents [, additional_contents]*)

The input is expected to be reduced. This function will not work on
things like expressions and variables.

unwrap(array $arg)   X-Ref
Utility func to unquote a string

funcToColor($func)   X-Ref
Convert the rgb, rgba, hsl color literals of function type
as returned by the parser into values of color type.

reduce($value, $forExpression = false)   X-Ref

coerceString($value)   X-Ref
No description

flattenList($value)   X-Ref
No description

evaluate($exp)   X-Ref
evaluate an expression

stringConcatenate($left, $right)   X-Ref
No description

op_number_color($op, $lft, $rgt)   X-Ref

op_color_number($op, $lft, $rgt)   X-Ref

op_color_color($op, $left, $right)   X-Ref

op_number_number($op, $left, $right)   X-Ref
operator on two numbers

makeOutputBlock($type, $selectors = null)   X-Ref
No description

pushEnv($block = null)   X-Ref
No description

popEnv()   X-Ref
No description

set($name, $value)   X-Ref
No description

get($name)   X-Ref
get the highest occurrence entry for a name

injectVariables($args)   X-Ref
inject array of unparsed strings into environment as variables

makeParser(?string $name)   X-Ref
Create a new parser instance

param: string|null $name A name to identify the parser in error messages

addParsedFile($file)   X-Ref
Add the given file to the list of parsed files

param: $file