PHP Class Beans_Lessc, Beans

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.
Mostra file Open project: Getbeans/Beans Class Usage Examples

Public Properties

Property Type Description
$VERSION
$defaultValue
$importDir
$importDisabled
$mPrefix prefix of abstract properties
$parentSelector prefix of abstract blocks
$vPrefix

Protected Properties

Property Type Description
$FALSE
$TRUE
$allParsedFiles
$cssColors
$libFunctions
$nextImportId
$numberPrecision
$preserveComments
$registeredVars
$sourceLoc
$sourceParser so we know how to create error messages

Public Methods

Method Description
__construct ( $fname = null ) Initialize any static state, can initialize parser for a file $opts isn't used yet
addImportDir ( $dir )
allParsedFiles ( )
cachedCompile ( mixed $in, boolean $force = false ) : array Execute lessphp on a .less file or a lessphp cache structure
ccompile ( $in, $out, $less = null ) returns true when it compiles, false otherwise
cexecute ( $in, $force = false, $less = null )
checkedCompile ( $in, $out ) compile only if changed input has changed or output doesn't exist
compile ( $string, $name = null )
compileFile ( $fname, $outFname = null )
compressList ( $items, $delim )
lib_blue ( $color )
lib_green ( $color )
lib_red ( $color )
parse ( $str = null, $initialVariables = null ) This is deprecated
preg_quote ( $what )
registerFunction ( $name, $func )
setFormatter ( $name )
setImportDir ( $dirs )
setPreserveComments ( $preserve )
setVariables ( $variables )
unregisterFunction ( $name )
unsetVariable ( $name )

Protected Methods

Method Description
addParsedFile ( $file )
assertArgs ( $value, $expectedArgs, $name = "" )
assertColor ( $value, $error = "expected color value" )
assertNumber ( $value, $error = "expecting number" )
clamp ( $v, $max = 1, $min )
coerceColor ( $value ) coerce a value for use in color operation
coerceString ( $value ) make something string like into a string
colorArgs ( $args ) Helper function to get arguments for color manipulation functions.
compileBlock ( $block ) Recursively compiles a block.
compileCSSBlock ( $block )
compileImportedProps ( $props, $block, $out, $sourceParser, $importDir )
compileMedia ( $media )
compileMediaQuery ( $queries )
compileNestedBlock ( $block, $selectors )
compileProp ( $prop, $block, $out ) compile a prop and update $lines or $blocks appropriately
compileProps ( $block, $out )
compileRoot ( $root )
compileSelectors ( $selectors ) reduces selector expressions
compileValue ( $value ) Compiles a primitive value into a CSS property value.
eq ( $left, $right )
evaluate ( $exp ) evaluate an expression
expandParentSelectors ( &$tag, $replace )
fileExists ( $name )
findBlocks ( $searchIn, $path, $orderedArgs, $keywordArgs, $seen = [] ) attempt to find blocks matched by path and args
findClosestSelectors ( )
findImport ( $url ) attempts to find the path of an import url, returns null for css files
fixColor ( $c ) make sure a color's components don't go out of bounds
flattenList ( $value ) turn list of length 1 into value type
funcToColor ( $func ) Convert the rgb, rgba, hsl color literals of function type as returned by the parser into values of color type.
get ( $name, $default = null ) get the highest occurrence entry for a name
injectVariables ( $args ) inject array of unparsed strings into environment as variables
lib__sprintf ( $args )
lib_acos ( $num )
lib_alpha ( $value ) defaults to 1 for non-colors or colors without an alpha
lib_argb ( $color )
lib_asin ( $num )
lib_atan ( $num )
lib_ceil ( $arg )
lib_contrast ( $args )
lib_cos ( $num )
lib_darken ( $args )
lib_desaturate ( $args )
lib_e ( ) use func_get_arg to prevent Theme Checker triggering unrelated translation warning.
lib_extract ( $value )
lib_fade ( $args ) set the alpha of the color
lib_fadein ( $args )
lib_fadeout ( $args )
lib_floor ( $arg )
lib_hue ( $color )
lib_iscolor ( $value )
lib_isem ( $value )
lib_iskeyword ( $value )
lib_isnumber ( $value )
lib_ispercentage ( $value )
lib_ispixel ( $value )
lib_isrem ( $value )
lib_isstring ( $value )
lib_lighten ( $args )
lib_lightness ( $color )
lib_mix ( $args ) http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#mix-instance_method
lib_mod ( $args )
lib_percentage ( $arg )
lib_pi ( )
lib_pow ( $args )
lib_rgbahex ( $color )
lib_round ( $arg )
lib_saturate ( $args )
lib_saturation ( $color )
lib_sin ( $num )
lib_spin ( $args )
lib_sqrt ( $num )
lib_tan ( $num )
lib_unit ( $arg )
lib_unquote ( $arg ) use func_get_arg to prevent Theme Checker triggering unrelated translation warning.
makeOutputBlock ( $type, $selectors = null ) * environment functions
makeParser ( $name )
mediaParent ( $scope )
multiplyMedia ( $env, $childQueries = null )
multiplySelectors ( $selectors ) multiply $selectors against the nearest selectors in env
newFormatter ( )
op_color_color ( $op, $left, $right )
op_color_number ( $op, $lft, $rgt )
op_number_color ( $op, $lft, $rgt )
op_number_number ( $op, $left, $right ) operator on two numbers
patternMatch ( $block, $orderedArgs, $keywordArgs )
patternMatchAll ( $blocks, $orderedArgs, $keywordArgs, $skip = [] )
popEnv ( ) pop something off the stack
pushEnv ( $block = null ) the state of execution
reduce ( $value, $forExpression = false )
set ( $name, $value ) set something in the current env
sortProps ( $props, $split = false )
stringConcatenate ( $left, $right )
throwError ( $msg = null ) Uses the current value of $this->count to show line and line number
toBool ( $a )
toHSL ( $color )
toRGB ( $color ) Converts a hsl array into a color value in rgb.
toRGB_helper ( $comp, $temp1, $temp2 )
tryImport ( $importPath, $parentBlock, $out )
zipSetArgs ( $args, $orderedValues, $keywordValues ) or the one passed in through $values

Method Details

__construct() public method

Initialize any static state, can initialize parser for a file $opts isn't used yet
public __construct ( $fname = null )

addImportDir() public method

public addImportDir ( $dir )

addParsedFile() protected method

protected addParsedFile ( $file )

allParsedFiles() public method

public allParsedFiles ( )

assertArgs() protected method

protected assertArgs ( $value, $expectedArgs, $name = "" )

assertColor() protected method

protected assertColor ( $value, $error = "expected color value" )

assertNumber() protected method

protected assertNumber ( $value, $error = "expecting number" )

cachedCompile() public method

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.
public cachedCompile ( mixed $in, boolean $force = false ) : array
$in mixed Input
$force boolean Force rebuild?
return array lessphp cache structure

ccompile() public static method

returns true when it compiles, false otherwise
public static ccompile ( $in, $out, $less = null )

cexecute() public static method

public static cexecute ( $in, $force = false, $less = null )

checkedCompile() public method

compile only if changed input has changed or output doesn't exist
public checkedCompile ( $in, $out )

clamp() protected method

protected clamp ( $v, $max = 1, $min )

coerceColor() protected method

coerce a value for use in color operation
protected coerceColor ( $value )

coerceString() protected method

make something string like into a string
protected coerceString ( $value )

colorArgs() protected method

takes a list that contains a color like thing and a percentage
protected colorArgs ( $args )

compile() public method

public compile ( $string, $name = null )

compileBlock() protected method

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()
protected compileBlock ( $block )

compileCSSBlock() protected method

protected compileCSSBlock ( $block )

compileFile() public method

public compileFile ( $fname, $outFname = null )

compileImportedProps() protected method

protected compileImportedProps ( $props, $block, $out, $sourceParser, $importDir )

compileMedia() protected method

protected compileMedia ( $media )

compileMediaQuery() protected method

protected compileMediaQuery ( $queries )

compileNestedBlock() protected method

protected compileNestedBlock ( $block, $selectors )

compileProp() protected method

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

compileProps() protected method

protected compileProps ( $block, $out )

compileRoot() protected method

protected compileRoot ( $root )

compileSelectors() protected method

reduces selector expressions
protected compileSelectors ( $selectors )

compileValue() protected method

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.
protected compileValue ( $value )

compressList() public static method

public static compressList ( $items, $delim )

eq() protected method

protected eq ( $left, $right )

evaluate() protected method

evaluate an expression
protected evaluate ( $exp )

expandParentSelectors() protected method

protected expandParentSelectors ( &$tag, $replace )

fileExists() protected method

protected fileExists ( $name )

findBlocks() protected method

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

findClosestSelectors() protected method

protected findClosestSelectors ( )

findImport() protected method

attempts to find the path of an import url, returns null for css files
protected findImport ( $url )

fixColor() protected method

make sure a color's components don't go out of bounds
protected fixColor ( $c )

flattenList() protected method

turn list of length 1 into value type
protected flattenList ( $value )

funcToColor() protected method

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

get() protected method

get the highest occurrence entry for a name
protected get ( $name, $default = null )

injectVariables() protected method

inject array of unparsed strings into environment as variables
protected injectVariables ( $args )

lib__sprintf() protected method

protected lib__sprintf ( $args )

lib_acos() protected method

protected lib_acos ( $num )

lib_alpha() protected method

defaults to 1 for non-colors or colors without an alpha
protected lib_alpha ( $value )

lib_argb() protected method

protected lib_argb ( $color )

lib_asin() protected method

protected lib_asin ( $num )

lib_atan() protected method

protected lib_atan ( $num )

lib_blue() public method

public lib_blue ( $color )

lib_ceil() protected method

protected lib_ceil ( $arg )

lib_contrast() protected method

protected lib_contrast ( $args )

lib_cos() protected method

protected lib_cos ( $num )

lib_darken() protected method

protected lib_darken ( $args )

lib_desaturate() protected method

protected lib_desaturate ( $args )

lib_e() protected method

use func_get_arg to prevent Theme Checker triggering unrelated translation warning.
protected lib_e ( )

lib_extract() protected method

protected lib_extract ( $value )

lib_fade() protected method

set the alpha of the color
protected lib_fade ( $args )

lib_fadein() protected method

protected lib_fadein ( $args )

lib_fadeout() protected method

protected lib_fadeout ( $args )

lib_floor() protected method

protected lib_floor ( $arg )

lib_green() public method

public lib_green ( $color )

lib_hue() protected method

protected lib_hue ( $color )

lib_iscolor() protected method

protected lib_iscolor ( $value )

lib_isem() protected method

protected lib_isem ( $value )

lib_iskeyword() protected method

protected lib_iskeyword ( $value )

lib_isnumber() protected method

protected lib_isnumber ( $value )

lib_ispercentage() protected method

protected lib_ispercentage ( $value )

lib_ispixel() protected method

protected lib_ispixel ( $value )

lib_isrem() protected method

protected lib_isrem ( $value )

lib_isstring() protected method

protected lib_isstring ( $value )

lib_lighten() protected method

protected lib_lighten ( $args )

lib_lightness() protected method

protected lib_lightness ( $color )

lib_mix() protected method

http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#mix-instance_method
protected lib_mix ( $args )

lib_mod() protected method

protected lib_mod ( $args )

lib_percentage() protected method

protected lib_percentage ( $arg )

lib_pi() protected method

protected lib_pi ( )

lib_pow() protected method

protected lib_pow ( $args )

lib_red() public method

public lib_red ( $color )

lib_rgbahex() protected method

protected lib_rgbahex ( $color )

lib_round() protected method

protected lib_round ( $arg )

lib_saturate() protected method

protected lib_saturate ( $args )

lib_saturation() protected method

protected lib_saturation ( $color )

lib_sin() protected method

protected lib_sin ( $num )

lib_spin() protected method

protected lib_spin ( $args )

lib_sqrt() protected method

protected lib_sqrt ( $num )

lib_tan() protected method

protected lib_tan ( $num )

lib_unit() protected method

protected lib_unit ( $arg )

lib_unquote() protected method

use func_get_arg to prevent Theme Checker triggering unrelated translation warning.
protected lib_unquote ( $arg )

makeOutputBlock() protected method

* environment functions
protected makeOutputBlock ( $type, $selectors = null )

makeParser() protected method

protected makeParser ( $name )

mediaParent() protected method

protected mediaParent ( $scope )

multiplyMedia() protected method

protected multiplyMedia ( $env, $childQueries = null )

multiplySelectors() protected method

multiply $selectors against the nearest selectors in env
protected multiplySelectors ( $selectors )

newFormatter() protected method

protected newFormatter ( )

op_color_color() protected method

protected op_color_color ( $op, $left, $right )

op_color_number() protected method

protected op_color_number ( $op, $lft, $rgt )

op_number_color() protected method

protected op_number_color ( $op, $lft, $rgt )

op_number_number() protected method

operator on two numbers
protected op_number_number ( $op, $left, $right )

parse() public method

This is deprecated
public parse ( $str = null, $initialVariables = null )

patternMatch() protected method

protected patternMatch ( $block, $orderedArgs, $keywordArgs )

patternMatchAll() protected method

protected patternMatchAll ( $blocks, $orderedArgs, $keywordArgs, $skip = [] )

popEnv() protected method

pop something off the stack
protected popEnv ( )

preg_quote() public static method

public static preg_quote ( $what )

pushEnv() protected method

the state of execution
protected pushEnv ( $block = null )

reduce() protected method

protected reduce ( $value, $forExpression = false )

registerFunction() public method

public registerFunction ( $name, $func )

set() protected method

set something in the current env
protected set ( $name, $value )

setFormatter() public method

public setFormatter ( $name )

setImportDir() public method

public setImportDir ( $dirs )

setPreserveComments() public method

public setPreserveComments ( $preserve )

setVariables() public method

public setVariables ( $variables )

sortProps() protected method

protected sortProps ( $props, $split = false )

stringConcatenate() protected method

protected stringConcatenate ( $left, $right )

throwError() protected method

Uses the current value of $this->count to show line and line number
protected throwError ( $msg = null )

toBool() protected method

protected toBool ( $a )

toHSL() protected method

protected toHSL ( $color )

toRGB() protected method

Expects H to be in range of 0 to 360, S and L in 0 to 100
protected toRGB ( $color )

toRGB_helper() protected method

protected toRGB_helper ( $comp, $temp1, $temp2 )

tryImport() protected method

protected tryImport ( $importPath, $parentBlock, $out )

unregisterFunction() public method

public unregisterFunction ( $name )

unsetVariable() public method

public unsetVariable ( $name )

zipSetArgs() protected method

or the one passed in through $values
protected zipSetArgs ( $args, $orderedValues, $keywordValues )

Property Details

$FALSE protected_oe static_oe property

protected static $FALSE

$TRUE protected_oe static_oe property

protected static $TRUE

$VERSION public_oe static_oe property

public static $VERSION

$allParsedFiles protected_oe property

protected $allParsedFiles

$cssColors protected_oe static_oe property

protected static $cssColors

$defaultValue public_oe static_oe property

public static $defaultValue

$importDir public_oe property

public $importDir

$importDisabled public_oe property

public $importDisabled

$libFunctions protected_oe property

protected $libFunctions

$mPrefix public_oe property

prefix of abstract properties
public $mPrefix

$nextImportId protected_oe static_oe property

protected static $nextImportId

$numberPrecision protected_oe property

protected $numberPrecision

$parentSelector public_oe property

prefix of abstract blocks
public $parentSelector

$preserveComments protected_oe property

protected $preserveComments

$registeredVars protected_oe property

protected $registeredVars

$sourceLoc protected_oe property

protected $sourceLoc

$sourceParser protected_oe property

so we know how to create error messages
protected $sourceParser

$vPrefix public_oe property

public $vPrefix