Changeset 943838
- Timestamp:
- 07/06/2014 06:13:45 AM (12 years ago)
- Location:
- less-compiler/trunk
- Files:
-
- 1 deleted
- 9 edited
-
cache (deleted)
-
css/less-compiler.css (modified) (1 diff)
-
libs/less-parser/Cache.php (modified) (6 diffs)
-
libs/less-parser/Less.php (modified) (142 diffs)
-
libs/less-parser/Version.php (modified) (1 diff)
-
libs/wm-settings/wm-settings.css (modified) (2 diffs)
-
libs/wm-settings/wm-settings.js (modified) (1 diff)
-
libs/wm-settings/wm-settings.php (modified) (9 diffs)
-
plugin.php (modified) (6 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
less-compiler/trunk/css/less-compiler.css
r912308 r943838 8 8 line-height: 1.4; 9 9 } 10 .toplevel_page_less .form-table th { 11 display: none; 12 } 13 .toplevel_page_less .form-table td { 14 padding-left: 0; 15 } -
less-compiler/trunk/libs/less-parser/Cache.php
r912308 r943838 22 22 * @param array $less_files Array of .less files to compile 23 23 * @param array $parser_options Array of compiler options 24 * @param boolean $use_cache Set to false to regenerate the css file24 * @param array $modify_vars Array of variables 25 25 * @return string Name of the css file 26 26 */ 27 public static function Get( $less_files, $parser_options = array(), $ use_cache = true){27 public static function Get( $less_files, $parser_options = array(), $modify_vars = array() ){ 28 28 29 29 … … 38 38 39 39 self::CheckCacheDir(); 40 $less_files = (array)$less_files; 41 42 43 //create a file for variables 44 if( !empty($modify_vars) ){ 45 $lessvars = Less_Parser::serializeVars($modify_vars); 46 $vars_file = Less_Cache::$cache_dir.'lessphpvars_' . sha1($lessvars) . '.less'; 47 48 if( !file_exists($vars_file) ){ 49 file_put_contents($vars_file, $lessvars); 50 } 51 52 $less_files += array($vars_file => '/'); 53 } 54 40 55 41 56 // generate name for compiled css file 42 $less_files = (array)$less_files;43 57 $hash = md5(json_encode($less_files)); 44 58 $list_file = Less_Cache::$cache_dir.'lessphp_'.$hash.'.list'; 45 59 46 60 47 if( $use_cache === true ){ 48 49 // check cached content 50 if( file_exists($list_file) ){ 51 61 // check cached content 62 if( !isset($parser_options['use_cache']) || $parser_options['use_cache'] === true ){ 63 if( file_exists($list_file) ){ 52 64 53 65 $list = explode("\n",file_get_contents($list_file)); 66 67 //pop the cached name that should match $compiled_name 68 $cached_name = array_pop($list); 69 if( !preg_match('/^lessphp_[a-f0-9]+\.css$/',$cached_name) ){ 70 $list[] = $cached_name; 71 $cached_name = false; 72 } 54 73 $compiled_name = self::CompiledName($list); 55 $compiled_file = Less_Cache::$cache_dir.$compiled_name; 56 if( file_exists($compiled_file) ){ 57 @touch($list_file); 58 @touch($compiled_file); 59 return $compiled_name; 60 } 61 } 62 74 75 // if $cached_name != $compiled_name, we know we need to recompile 76 if( !$cached_name || $cached_name === $compiled_name ){ 77 78 $output_file = self::OutputFile($compiled_name, $parser_options ); 79 80 if( $output_file && file_exists($output_file) ){ 81 @touch($list_file); 82 @touch($output_file); 83 return basename($output_file); // for backwards compatibility, we just return the name of the file 84 } 85 } 86 } 63 87 } 64 88 … … 68 92 } 69 93 94 $compiled_name = self::CompiledName( $less_files ); 95 $output_file = self::OutputFile($compiled_name, $parser_options ); 96 70 97 71 98 //save the file list 72 $cache = implode("\n",$less_files); 99 $list = $less_files; 100 $list[] = $compiled_name; 101 $cache = implode("\n",$list); 73 102 file_put_contents( $list_file, $cache ); 74 103 75 104 76 105 //save the css 77 $compiled_name = self::CompiledName( $less_files ); 78 file_put_contents( Less_Cache::$cache_dir.$compiled_name, $compiled ); 106 file_put_contents( $output_file, $compiled ); 79 107 80 108 … … 82 110 self::CleanCache(); 83 111 84 return $compiled_name;112 return basename($output_file); 85 113 } 86 114 … … 90 118 * @param array $less_files Array of .less files to compile 91 119 * @param array $parser_options Array of compiler options 120 * @param array $modify_vars Array of variables 92 121 * @return string Name of the css file 93 122 */ 94 public static function Regen( $less_files, $parser_options = array() ){ 95 return self::Get( $less_files, $parser_options, false ); 123 public static function Regen( $less_files, $parser_options = array(), $modify_vars = array() ){ 124 $parser_options['use_cache'] = false; 125 return self::Get( $less_files, $parser_options, $modify_vars ); 96 126 } 97 127 … … 127 157 128 158 return $compiled; 159 } 160 161 162 private static function OutputFile( $compiled_name, $parser_options ){ 163 164 //custom output file 165 if( !empty($parser_options['output']) ){ 166 167 //relative to cache directory? 168 if( preg_match('#[\\\\/]#',$parser_options['output']) ){ 169 return $parser_options['output']; 170 } 171 172 return Less_Cache::$cache_dir.$parser_options['output']; 173 } 174 175 return Less_Cache::$cache_dir.$compiled_name; 129 176 } 130 177 -
less-compiler/trunk/libs/less-parser/Less.php
r912308 r943838 27 27 'import_callback' => null, 28 28 'cache_dir' => null, 29 'cache_method' => 'php', //false, 'serialize', 'php', 'var_export'; 29 'cache_method' => 'php', // false, 'serialize', 'php', 'var_export', 'callback'; 30 'cache_callback_get' => null, 31 'cache_callback_set' => null, 30 32 31 33 'sourceMap' => false, // whether to output a source map … … 140 142 } 141 143 142 144 /** 145 * Registers a new custom function 146 * 147 * @param string $name function name 148 * @param callable $callback callback 149 */ 150 public function registerFunction($name, $callback) { 151 $this->env->functions[$name] = $callback; 152 } 153 154 /** 155 * Removed an already registered function 156 * 157 * @param string $name function name 158 */ 159 public function unregisterFunction($name) { 160 if( isset($this->env->functions[$name]) ) 161 unset($this->env->functions[$name]); 162 } 143 163 144 164 … … 328 348 public function ModifyVars( $vars ){ 329 349 330 $this->input = $this->serializeVars( $vars );350 $this->input = Less_Parser::serializeVars( $vars ); 331 351 $this->_parse(); 332 352 … … 447 467 448 468 $cache_file = $this->CacheFile( $file_path ); 449 if( $cache_file && file_exists($cache_file) ){ 450 switch(Less_Parser::$options['cache_method']){ 451 452 // Using serialize 453 // Faster but uses more memory 454 case 'serialize': 455 $cache = unserialize(file_get_contents($cache_file)); 469 if( $cache_file ){ 470 if( Less_Parser::$options['cache_method'] == 'callback' ){ 471 if( is_callable(Less_Parser::$options['cache_callback_get']) ){ 472 $cache = call_user_func_array( 473 Less_Parser::$options['cache_callback_get'], 474 array($this, $file_path, $cache_file) 475 ); 476 456 477 if( $cache ){ 457 touch($cache_file);458 478 $this->UnsetInput(); 459 479 return $cache; 460 480 } 461 break; 462 463 464 // Using generated php code 465 case 'var_export': 466 case 'php': 467 $this->UnsetInput(); 468 return include($cache_file); 481 } 482 483 }elseif( file_exists($cache_file) ){ 484 switch(Less_Parser::$options['cache_method']){ 485 486 // Using serialize 487 // Faster but uses more memory 488 case 'serialize': 489 $cache = unserialize(file_get_contents($cache_file)); 490 if( $cache ){ 491 touch($cache_file); 492 $this->UnsetInput(); 493 return $cache; 494 } 495 break; 496 497 498 // Using generated php code 499 case 'var_export': 500 case 'php': 501 $this->UnsetInput(); 502 return include($cache_file); 503 } 469 504 } 470 505 } … … 481 516 //save the cache 482 517 if( $cache_file ){ 483 484 //msg('write cache file'); 485 switch(Less_Parser::$options['cache_method']){ 486 case 'serialize': 487 file_put_contents( $cache_file, serialize($rules) ); 488 break; 489 case 'php': 490 file_put_contents( $cache_file, '<?php return '.self::ArgString($rules).'; ?>' ); 491 break; 492 case 'var_export': 493 //Requires __set_state() 494 file_put_contents( $cache_file, '<?php return '.var_export($rules,true).'; ?>' ); 495 break; 496 } 497 498 Less_Cache::CleanCache(); 518 if( Less_Parser::$options['cache_method'] == 'callback' ){ 519 if( is_callable(Less_Parser::$options['cache_callback_set']) ){ 520 call_user_func_array( 521 Less_Parser::$options['cache_callback_set'], 522 array($this, $file_path, $cache_file, $rules) 523 ); 524 } 525 526 }else{ 527 //msg('write cache file'); 528 switch(Less_Parser::$options['cache_method']){ 529 case 'serialize': 530 file_put_contents( $cache_file, serialize($rules) ); 531 break; 532 case 'php': 533 file_put_contents( $cache_file, '<?php return '.self::ArgString($rules).'; ?>' ); 534 break; 535 case 'var_export': 536 //Requires __set_state() 537 file_put_contents( $cache_file, '<?php return '.var_export($rules,true).'; ?>' ); 538 break; 539 } 540 541 Less_Cache::CleanCache(); 542 } 499 543 } 500 544 … … 540 584 public function CacheFile( $file_path ){ 541 585 542 if( $file_path && Less_Parser::$options['cache_method'] && Less_Cache::$cache_dir){586 if( $file_path && $this->CacheEnabled() ){ 543 587 544 588 $env = get_object_vars($this->env); … … 637 681 private function MatchFuncs($toks){ 638 682 639 foreach($toks as $tok){ 640 $match = $this->$tok(); 641 if( $match ){ 642 return $match; 683 if( $this->pos < $this->input_len ){ 684 foreach($toks as $tok){ 685 $match = $this->$tok(); 686 if( $match ){ 687 return $match; 688 } 643 689 } 644 690 } … … 865 911 $this->MatchChar('~'); 866 912 } 867 $str = $this->MatchReg('/\\G"((?:[^"\\\\\r\n]|\\\\.)*)"|\'((?:[^\'\\\\\r\n]|\\\\.)*)\'/'); 913 914 // Fix for #124: match escaped newlines 915 //$str = $this->MatchReg('/\\G"((?:[^"\\\\\r\n]|\\\\.)*)"|\'((?:[^\'\\\\\r\n]|\\\\.)*)\'/'); 916 $str = $this->MatchReg('/\\G"((?:[^"\\\\\r\n]|\\\\.|\\\\\r\n|\\\\[\n\r\f])*)"|\'((?:[^\'\\\\\r\n]|\\\\.|\\\\\r\n|\\\\[\n\r\f])*)\'/'); 917 868 918 if( $str ){ 869 919 $result = $str[0][0] == '"' ? $str[1] : $str[2]; … … 1563 1613 // 1564 1614 private function parseCombinator(){ 1565 $c = $this->input[$this->pos]; 1566 if ($c === '>' || $c === '+' || $c === '~' || $c === '|' || $c === '^' ){ 1567 1568 $this->pos++; 1569 if( $this->input[$this->pos] === '^' ){ 1570 $c = '^^'; 1615 if( $this->pos < $this->input_len ){ 1616 $c = $this->input[$this->pos]; 1617 if ($c === '>' || $c === '+' || $c === '~' || $c === '|' || $c === '^' ){ 1618 1571 1619 $this->pos++; 1572 } 1573 1574 $this->skipWhitespace(0); 1575 1576 return $c; 1577 } 1578 1579 if( $this->pos > 0 && $this->isWhitespace(-1) ){ 1580 return ' '; 1620 if( $this->input[$this->pos] === '^' ){ 1621 $c = '^^'; 1622 $this->pos++; 1623 } 1624 1625 $this->skipWhitespace(0); 1626 1627 return $c; 1628 } 1629 1630 if( $this->pos > 0 && $this->isWhitespace(-1) ){ 1631 return ' '; 1632 } 1581 1633 } 1582 1634 } … … 1619 1671 //error("Extend can only be used at the end of selector"); 1620 1672 //} 1621 $c = $this->input[ $this->pos ]; 1673 if( $this->pos < $this->input_len ){ 1674 $c = $this->input[ $this->pos ]; 1675 } 1622 1676 $elements[] = $e; 1623 1677 $e = null; … … 2379 2433 } 2380 2434 2381 public function serializeVars( $vars ){2435 public static function serializeVars( $vars ){ 2382 2436 $s = ''; 2383 2437 … … 2427 2481 public function NewObj0($class){ 2428 2482 $obj = new $class(); 2429 if( Less_Cache::$cache_dir){2483 if( $this->CacheEnabled() ){ 2430 2484 $obj->cache_string = ' new '.$class.'()'; 2431 2485 } … … 2435 2489 public function NewObj1($class, $arg){ 2436 2490 $obj = new $class( $arg ); 2437 if( Less_Cache::$cache_dir){2491 if( $this->CacheEnabled() ){ 2438 2492 $obj->cache_string = ' new '.$class.'('.Less_Parser::ArgString($arg).')'; 2439 2493 } … … 2443 2497 public function NewObj2($class, $args){ 2444 2498 $obj = new $class( $args[0], $args[1] ); 2445 if( Less_Cache::$cache_dir){2499 if( $this->CacheEnabled() ){ 2446 2500 $this->ObjCache( $obj, $class, $args); 2447 2501 } … … 2451 2505 public function NewObj3($class, $args){ 2452 2506 $obj = new $class( $args[0], $args[1], $args[2] ); 2453 if( Less_Cache::$cache_dir){2507 if( $this->CacheEnabled() ){ 2454 2508 $this->ObjCache( $obj, $class, $args); 2455 2509 } … … 2459 2513 public function NewObj4($class, $args){ 2460 2514 $obj = new $class( $args[0], $args[1], $args[2], $args[3] ); 2461 if( Less_Cache::$cache_dir){2515 if( $this->CacheEnabled() ){ 2462 2516 $this->ObjCache( $obj, $class, $args); 2463 2517 } … … 2467 2521 public function NewObj5($class, $args){ 2468 2522 $obj = new $class( $args[0], $args[1], $args[2], $args[3], $args[4] ); 2469 if( Less_Cache::$cache_dir){2523 if( $this->CacheEnabled() ){ 2470 2524 $this->ObjCache( $obj, $class, $args); 2471 2525 } … … 2475 2529 public function NewObj6($class, $args){ 2476 2530 $obj = new $class( $args[0], $args[1], $args[2], $args[3], $args[4], $args[5] ); 2477 if( Less_Cache::$cache_dir){2531 if( $this->CacheEnabled() ){ 2478 2532 $this->ObjCache( $obj, $class, $args); 2479 2533 } … … 2483 2537 public function NewObj7($class, $args){ 2484 2538 $obj = new $class( $args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6] ); 2485 if( Less_Cache::$cache_dir){2539 if( $this->CacheEnabled() ){ 2486 2540 $this->ObjCache( $obj, $class, $args); 2487 2541 } … … 2530 2584 public static function WinPath($path){ 2531 2585 return str_replace('\\', '/', $path); 2586 } 2587 2588 public function CacheEnabled(){ 2589 return (Less_Parser::$options['cache_method'] && (Less_Cache::$cache_dir || (Less_Parser::$options['cache_method'] == 'callback'))); 2532 2590 } 2533 2591 … … 2754 2812 public static $mixin_stack = 0; 2755 2813 2814 /** 2815 * @var array 2816 */ 2817 public $functions = array(); 2818 2756 2819 2757 2820 public function Init(){ … … 2821 2884 * 2822 2885 */ 2823 static function normalizePath($path){2886 public static function normalizePath($path){ 2824 2887 2825 2888 $segments = explode('/',$path); … … 2889 2952 * @param string $op 2890 2953 */ 2891 static public function operate( $op, $a, $b ){2954 public static function operate( $op, $a, $b ){ 2892 2955 switch ($op) { 2893 2956 case '+': return $a + $b; … … 2898 2961 } 2899 2962 2900 static public function clamp($val, $max = 1){2963 public static function clamp($val, $max = 1){ 2901 2964 return min( max($val, 0), $max); 2902 2965 } 2903 2966 2904 static function fround( $value ){2967 public static function fround( $value ){ 2905 2968 2906 2969 if( $value === 0 ){ … … 2915 2978 } 2916 2979 2917 static public function number($n){2980 public static function number($n){ 2918 2981 2919 2982 if ($n instanceof Less_Tree_Dimension) { … … 2926 2989 } 2927 2990 2928 static public function scaled($n, $size = 255 ){2991 public static function scaled($n, $size = 255 ){ 2929 2992 if( $n instanceof Less_Tree_Dimension && $n->unit->is('%') ){ 2930 2993 return (float)$n->value * $size / 100; … … 2970 3033 * @param double $h 2971 3034 */ 2972 function hsla_hue($h, $m1, $m2){3035 public function hsla_hue($h, $m1, $m2){ 2973 3036 $h = $h < 0 ? $h + 1 : ($h > 1 ? $h - 1 : $h); 2974 3037 if ($h * 6 < 1) return $m1 + ($m2 - $m1) * $h * 6; … … 3388 3451 * @param boolean $isMin 3389 3452 */ 3390 function _minmax( $isMin, $args ){3453 private function _minmax( $isMin, $args ){ 3391 3454 3392 3455 $arg_count = count($args); … … 3583 3646 } 3584 3647 3585 function length($values){3648 public function length($values){ 3586 3649 $n = (property_exists($values,'value') && is_array($values->value)) ? count($values->value) : 1; 3587 3650 return new Less_Tree_Dimension($n); 3588 3651 } 3589 3652 3590 function datauri($mimetypeNode, $filePathNode = null ) {3653 public function datauri($mimetypeNode, $filePathNode = null ) { 3591 3654 3592 3655 $filePath = ( $filePathNode ? $filePathNode->value : null ); … … 3664 3727 3665 3728 //svg-gradient 3666 function svggradient( $direction ){3729 public function svggradient( $direction ){ 3667 3730 3668 3731 $throw_message = 'svg-gradient expects direction, start_color [start_position], [color position,]..., end_color [end_position]'; … … 3863 3926 3864 3927 // non-w3c functions: 3865 function colorBlendAverage($cb, $cs ){3928 public function colorBlendAverage($cb, $cs ){ 3866 3929 return ($cb + $cs) / 2; 3867 3930 } … … 3871 3934 } 3872 3935 3873 function colorBlendNegation($cb, $cs){3936 public function colorBlendNegation($cb, $cs){ 3874 3937 return 1 - abs($cb + $cs - 1); 3875 3938 } … … 3896 3959 '.jpg' => 'image/jpeg', 3897 3960 '.jpeg'=> 'image/jpeg', 3898 '.png' => 'image/png' 3961 '.png' => 'image/png', 3962 '.ttf' => 'application/x-font-ttf', 3963 '.otf' => 'application/x-font-otf', 3964 '.eot' => 'application/vnd.ms-fontobject', 3965 '.woff' => 'application/x-font-woff', 3966 '.svg' => 'image/svg+xml', 3899 3967 ); 3900 3968 3901 static function lookup( $filepath ){3969 public static function lookup( $filepath ){ 3902 3970 $parts = explode('.',$filepath); 3903 3971 $ext = '.'.strtolower(array_pop($parts)); … … 3909 3977 } 3910 3978 3911 static function charsets_lookup( $type = null ){3979 public static function charsets_lookup( $type = null ){ 3912 3980 // assumes all text types are UTF-8 3913 3981 return $type && preg_match('/^text\//',$type) ? 'UTF-8' : ''; 3914 3982 } 3915 } 3983 } 3984 3916 3985 3917 3986 /** … … 4060 4129 class Less_Visitor{ 4061 4130 4062 var$methods = array();4063 var$_visitFnCache = array();4064 4065 function __construct(){4131 protected $methods = array(); 4132 protected $_visitFnCache = array(); 4133 4134 public function __construct(){ 4066 4135 $this->_visitFnCache = get_class_methods(get_class($this)); 4067 4136 $this->_visitFnCache = array_flip($this->_visitFnCache); 4068 4137 } 4069 4138 4070 function visitObj( $node ){4139 public function visitObj( $node ){ 4071 4140 4072 4141 $funcName = 'visit'.$node->type; … … 4092 4161 } 4093 4162 4094 function visitArray( $nodes ){4163 public function visitArray( $nodes ){ 4095 4164 4096 4165 array_map( array($this,'visitObj'), $nodes); … … 4109 4178 class Less_VisitorReplacing extends Less_Visitor{ 4110 4179 4111 function visitObj( $node ){4180 public function visitObj( $node ){ 4112 4181 4113 4182 $funcName = 'visit'.$node->type; … … 4135 4204 } 4136 4205 4137 function visitArray( $nodes ){4206 public function visitArray( $nodes ){ 4138 4207 4139 4208 $newNodes = array(); … … 4151 4220 } 4152 4221 4153 function flatten( $arr, &$out ){4222 public function flatten( $arr, &$out ){ 4154 4223 4155 4224 foreach($arr as $item){ … … 4323 4392 } 4324 4393 4325 function compare($x){4394 public function compare($x){ 4326 4395 if( !is_object($x) ){ 4327 4396 return -1; … … 4364 4433 public $type = 'Assignment'; 4365 4434 4366 function __construct($key, $val) {4435 public function __construct($key, $val) { 4367 4436 $this->key = $key; 4368 4437 $this->value = $val; 4369 4438 } 4370 4439 4371 function accept( $visitor ){4440 public function accept( $visitor ){ 4372 4441 $this->value = $visitor->visitObj( $this->value ); 4373 4442 } … … 4404 4473 public $type = 'Attribute'; 4405 4474 4406 function __construct($key, $op, $value){4475 public function __construct($key, $op, $value){ 4407 4476 $this->key = $key; 4408 4477 $this->op = $op; … … 4410 4479 } 4411 4480 4412 function compile($env){4481 public function compile($env){ 4413 4482 4414 4483 $key_obj = is_object($this->key); … … 4428 4497 * @see Less_Tree::genCSS 4429 4498 */ 4430 function genCSS( $output ){4499 public function genCSS( $output ){ 4431 4500 $output->add( $this->toCSS() ); 4432 4501 } 4433 4502 4434 function toCSS(){4503 public function toCSS(){ 4435 4504 $value = $this->key; 4436 4505 … … 4454 4523 public $value; 4455 4524 4456 var$name;4457 var$args;4458 var$index;4459 var$currentFileInfo;4525 protected $name; 4526 protected $args; 4527 protected $index; 4528 protected $currentFileInfo; 4460 4529 public $type = 'Call'; 4461 4530 … … 4467 4536 } 4468 4537 4469 function accept( $visitor ){4538 public function accept( $visitor ){ 4470 4539 $this->args = $visitor->visitArray( $this->args ); 4471 4540 } … … 4523 4592 throw new Less_Exception_Compiler('error evaluating function `' . $this->name . '` '.$e->getMessage().' index: '. $this->index); 4524 4593 } 4594 } elseif( isset( $env->functions[$nameLC] ) && is_callable( $env->functions[$nameLC] ) ) { 4595 try { 4596 $result = call_user_func_array( $env->functions[$nameLC], $args ); 4597 } catch (Exception $e) { 4598 throw new Less_Exception_Compiler('error evaluating function `' . $this->name . '` '.$e->getMessage().' index: '. $this->index); 4599 } 4525 4600 } 4526 4601 } … … 4707 4782 4708 4783 //Adapted from http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript 4709 function toHSV() {4784 public function toHSV() { 4710 4785 $r = $this->rgb[0] / 255; 4711 4786 $g = $this->rgb[1] / 255; … … 4755 4830 } 4756 4831 4757 function toHex( $v ){4832 public function toHex( $v ){ 4758 4833 4759 4834 $ret = '#'; … … 4923 4998 static $value_; 4924 4999 4925 static function compile(){5000 public static function compile(){ 4926 5001 if( self::$error_ ){ 4927 throw Exception(self::$error_);5002 throw new Exception(self::$error_); 4928 5003 } 4929 5004 if( self::$value_ !== null ){ … … 4932 5007 } 4933 5008 4934 static function value( $v ){5009 public static function value( $v ){ 4935 5010 self::$value_ = $v; 4936 5011 } 4937 5012 4938 static function error( $e ){5013 public static function error( $e ){ 4939 5014 self::$error_ = $e; 4940 5015 } 4941 5016 4942 static function reset(){5017 public static function reset(){ 4943 5018 self::$value_ = self::$error_ = null; 4944 5019 } … … 4957 5032 public $type = 'DetachedRuleset'; 4958 5033 4959 function __construct( $ruleset, $frames = null ){5034 public function __construct( $ruleset, $frames = null ){ 4960 5035 $this->ruleset = $ruleset; 4961 5036 $this->frames = $frames; 4962 5037 } 4963 5038 4964 function accept($visitor) {5039 public function accept($visitor) { 4965 5040 $this->ruleset = $visitor->visitObj($this->ruleset); 4966 5041 } 4967 5042 4968 function compile($env){5043 public function compile($env){ 4969 5044 if( $this->frames ){ 4970 5045 $frames = $this->frames; … … 4975 5050 } 4976 5051 4977 function callEval($env) {5052 public function callEval($env) { 4978 5053 if( $this->frames ){ 4979 5054 return $this->ruleset->compile( $env->copyEvalEnv( array_merge($this->frames,$env->frames) ) ); … … 5009 5084 } 5010 5085 5011 function accept( $visitor ){5086 public function accept( $visitor ){ 5012 5087 $this->unit = $visitor->visitObj( $this->unit ); 5013 5088 } … … 5132 5207 } 5133 5208 5134 function unify() {5209 public function unify() { 5135 5210 return $this->convertTo(array('length'=> 'px', 'duration'=> 's', 'angle' => 'rad' )); 5136 5211 } 5137 5212 5138 function convertTo($conversions) {5213 public function convertTo($conversions) { 5139 5214 $value = $this->value; 5140 5215 $unit = clone $this->unit; … … 5217 5292 5218 5293 5219 function accept( $visitor ){5294 public function accept( $visitor ){ 5220 5295 if( $this->rules ){ 5221 5296 $this->rules = $visitor->visitObj( $this->rules ); … … 5230 5305 * @see Less_Tree::genCSS 5231 5306 */ 5232 function genCSS( $output ){5307 public function genCSS( $output ){ 5233 5308 $value = $this->value; 5234 5309 $rules = $this->rules; … … 5315 5390 } 5316 5391 5317 function accept( $visitor ){5392 public function accept( $visitor ){ 5318 5393 if( $this->value_is_object ){ //object or string 5319 5394 $this->value = $visitor->visitObj( $this->value ); … … 5379 5454 } 5380 5455 5381 function accept( $visitor ){5456 public function accept( $visitor ){ 5382 5457 $this->value = $visitor->visitArray( $this->value ); 5383 5458 } … … 5432 5507 * @see Less_Tree::genCSS 5433 5508 */ 5434 function genCSS( $output ){5509 public function genCSS( $output ){ 5435 5510 $val_len = count($this->value); 5436 5511 for( $i = 0; $i < $val_len; $i++ ){ … … 5442 5517 } 5443 5518 5444 function throwAwayComments() {5519 public function throwAwayComments() { 5445 5520 5446 5521 if( is_array($this->value) ){ … … 5483 5558 * @param integer $index 5484 5559 */ 5485 function __construct($selector, $option, $index){5560 public function __construct($selector, $option, $index){ 5486 5561 static $i = 0; 5487 5562 $this->selector = $selector; … … 5504 5579 } 5505 5580 5506 function accept( $visitor ){5581 public function accept( $visitor ){ 5507 5582 $this->selector = $visitor->visitObj( $this->selector ); 5508 5583 } 5509 5584 5510 function compile( $env ){5585 public function compile( $env ){ 5511 5586 Less_Parser::$has_extends = true; 5512 5587 $this->selector = $this->selector->compile($env); … … 5515 5590 } 5516 5591 5517 function findSelfSelectors( $selectors ){5592 public function findSelfSelectors( $selectors ){ 5518 5593 $selfElements = array(); 5519 5594 … … 5561 5636 public $type = 'Import'; 5562 5637 5563 function __construct($path, $features, $options, $index, $currentFileInfo = null ){5638 public function __construct($path, $features, $options, $index, $currentFileInfo = null ){ 5564 5639 $this->options = $options; 5565 5640 $this->index = $index; … … 5592 5667 // 5593 5668 5594 function accept($visitor){5669 public function accept($visitor){ 5595 5670 5596 5671 if( $this->features ){ … … 5607 5682 * @see Less_Tree::genCSS 5608 5683 */ 5609 function genCSS( $output ){5684 public function genCSS( $output ){ 5610 5685 if( $this->css ){ 5611 5686 … … 5621 5696 } 5622 5697 5623 function toCSS(){5698 public function toCSS(){ 5624 5699 $features = $this->features ? ' ' . $this->features->toCSS() : ''; 5625 5700 … … 5634 5709 * @return string 5635 5710 */ 5636 function getPath(){5711 public function getPath(){ 5637 5712 if ($this->path instanceof Less_Tree_Quoted) { 5638 5713 $path = $this->path->value; 5639 return( isset($this->css) || preg_match('/(\.[a-z]*$)|([\?;].*)$/',$path)) ? $path : $path . '.less';5714 $path = ( isset($this->css) || preg_match('/(\.[a-z]*$)|([\?;].*)$/',$path)) ? $path : $path . '.less'; 5640 5715 } else if ($this->path instanceof Less_Tree_URL) { 5641 return $this->path->value->value; 5642 } 5643 return null; 5644 } 5645 5646 function compileForImport( $env ){ 5716 $path = $this->path->value->value; 5717 }else{ 5718 return null; 5719 } 5720 5721 //remove query string and fragment 5722 return preg_replace('/[\?#][^\?]*$/','',$path); 5723 } 5724 5725 public function compileForImport( $env ){ 5647 5726 return new Less_Tree_Import( $this->path->compile($env), $this->features, $this->options, $this->index, $this->currentFileInfo); 5648 5727 } 5649 5728 5650 function compilePath($env) {5729 public function compilePath($env) { 5651 5730 $path = $this->path->compile($env); 5652 5731 $rootpath = ''; … … 5672 5751 } 5673 5752 5674 function compile( $env ){5753 public function compile( $env ){ 5675 5754 5676 5755 $evald = $this->compileForImport($env); … … 5729 5808 * @param Less_Tree_Import $evald 5730 5809 */ 5731 function PathAndUri(){5810 public function PathAndUri(){ 5732 5811 5733 5812 $evald_path = $this->getPath(); … … 5780 5859 * @return Less_Tree_Media|array 5781 5860 */ 5782 function ParseImport( $full_path, $uri, $env ){5861 public function ParseImport( $full_path, $uri, $env ){ 5783 5862 5784 5863 $import_env = clone $env; … … 5927 6006 } 5928 6007 5929 function accept( $visitor ){6008 public function accept( $visitor ){ 5930 6009 $this->features = $visitor->visitObj($this->features); 5931 6010 $this->rules = $visitor->visitArray($this->rules); … … 5935 6014 * @see Less_Tree::genCSS 5936 6015 */ 5937 function genCSS( $output ){6016 public function genCSS( $output ){ 5938 6017 5939 6018 $output->add( '@media ', $this->currentFileInfo, $this->index ); … … 6068 6147 } 6069 6148 6070 function bubbleSelectors($selectors) {6149 public function bubbleSelectors($selectors) { 6071 6150 6072 6151 if( !$selectors) return; … … 6103 6182 } 6104 6183 6105 function genCSS( $output ){6184 public function genCSS( $output ){ 6106 6185 6107 6186 $output->add( … … 6130 6209 public $type = 'Negative'; 6131 6210 6132 function __construct($node){6211 public function __construct($node){ 6133 6212 $this->value = $node; 6134 6213 } … … 6141 6220 * @see Less_Tree::genCSS 6142 6221 */ 6143 function genCSS( $output ){6222 public function genCSS( $output ){ 6144 6223 $output->add( '-' ); 6145 6224 $this->value->genCSS( $output ); 6146 6225 } 6147 6226 6148 function compile($env) {6227 public function compile($env) { 6149 6228 if( Less_Environment::isMathOn() ){ 6150 6229 $ret = new Less_Tree_Operation('*', array( new Less_Tree_Dimension(-1), $this->value ) ); … … 6177 6256 } 6178 6257 6179 function accept($visitor) {6258 public function accept($visitor) { 6180 6259 $this->operands = $visitor->visitArray($this->operands); 6181 6260 } … … 6210 6289 * @see Less_Tree::genCSS 6211 6290 */ 6212 function genCSS( $output ){6291 public function genCSS( $output ){ 6213 6292 $this->operands[0]->genCSS( $output ); 6214 6293 if( $this->isSpaced ){ … … 6240 6319 } 6241 6320 6242 function accept($visitor){6321 public function accept($visitor){ 6243 6322 $this->value = $visitor->visitObj($this->value); 6244 6323 } … … 6247 6326 * @see Less_Tree::genCSS 6248 6327 */ 6249 function genCSS( $output ){6328 public function genCSS( $output ){ 6250 6329 $output->add( '(' ); 6251 6330 $this->value->genCSS( $output ); … … 6323 6402 } 6324 6403 6325 function compare($x) {6404 public function compare($x) { 6326 6405 6327 6406 if( !Less_Parser::is_method($x, 'toCSS') ){ … … 6373 6452 } 6374 6453 6375 function accept($visitor) {6454 public function accept($visitor) { 6376 6455 $this->value = $visitor->visitObj( $this->value ); 6377 6456 } … … 6380 6459 * @see Less_Tree::genCSS 6381 6460 */ 6382 function genCSS( $output ){6461 public function genCSS( $output ){ 6383 6462 6384 6463 $output->add( $this->name . Less_Environment::$_outputMap[': '], $this->currentFileInfo, $this->index); … … 6441 6520 6442 6521 6443 function CompileName( $env, $name ){6522 public function CompileName( $env, $name ){ 6444 6523 $output = new Less_Output(); 6445 6524 foreach($name as $n){ … … 6449 6528 } 6450 6529 6451 function makeImportant(){6530 public function makeImportant(){ 6452 6531 return new Less_Tree_Rule($this->name, $this->value, '!important', $this->merge, $this->index, $this->currentFileInfo, $this->inline); 6453 6532 } … … 6480 6559 public $allExtends; 6481 6560 6482 var$ruleset_id;6483 var$originalRuleset;6484 6485 var$first_oelements;6561 public $ruleset_id; 6562 public $originalRuleset; 6563 6564 public $first_oelements; 6486 6565 6487 6566 public function SetRulesetIndex(){ … … 6506 6585 } 6507 6586 6508 function accept( $visitor ){6587 public function accept( $visitor ){ 6509 6588 if( $this->paths ){ 6510 6589 $paths_len = count($this->paths); … … 7110 7189 public $type = "RulesetCall"; 7111 7190 7112 function __construct($variable){7191 public function __construct($variable){ 7113 7192 $this->variable = $variable; 7114 7193 } 7115 7194 7116 function accept($visitor) {}7117 7118 function compile( $env ){7195 public function accept($visitor) {} 7196 7197 public function compile( $env ){ 7119 7198 $variable = new Less_Tree_Variable($this->variable); 7120 7199 $detachedRuleset = $variable->compile($env); … … 7170 7249 } 7171 7250 7172 function accept($visitor) {7251 public function accept($visitor) { 7173 7252 $this->elements = $visitor->visitArray($this->elements); 7174 7253 $this->extendList = $visitor->visitArray($this->extendList); … … 7182 7261 } 7183 7262 7184 function createDerived( $elements, $extendList = null, $evaldCondition = null ){7263 public function createDerived( $elements, $extendList = null, $evaldCondition = null ){ 7185 7264 $newSelector = new Less_Tree_Selector( $elements, ($extendList ? $extendList : $this->extendList), null, $this->index, $this->currentFileInfo, $this->isReferenced); 7186 7265 $newSelector->evaldCondition = $evaldCondition ? $evaldCondition : $this->evaldCondition; … … 7267 7346 * @see Less_Tree::genCSS 7268 7347 */ 7269 function genCSS( $output, $firstSelector = true ){7348 public function genCSS( $output, $firstSelector = true ){ 7270 7349 7271 7350 if( !$firstSelector && $this->elements[0]->combinator === "" ){ … … 7278 7357 } 7279 7358 7280 function markReferenced(){7359 public function markReferenced(){ 7281 7360 $this->isReferenced = true; 7282 7361 } 7283 7362 7284 function getIsReferenced(){7363 public function getIsReferenced(){ 7285 7364 return !isset($this->currentFileInfo['reference']) || !$this->currentFileInfo['reference'] || $this->isReferenced; 7286 7365 } 7287 7366 7288 function getIsOutput(){7367 public function getIsOutput(){ 7289 7368 return $this->evaldCondition; 7290 7369 } … … 7335 7414 public $type = 'Unit'; 7336 7415 7337 function __construct($numerator = array(), $denominator = array(), $backupUnit = null ){7416 public function __construct($numerator = array(), $denominator = array(), $backupUnit = null ){ 7338 7417 $this->numerator = $numerator; 7339 7418 $this->denominator = $denominator; … … 7341 7420 } 7342 7421 7343 function __clone(){7422 public function __clone(){ 7344 7423 } 7345 7424 … … 7347 7426 * @see Less_Tree::genCSS 7348 7427 */ 7349 function genCSS( $output ){7428 public function genCSS( $output ){ 7350 7429 7351 7430 if( $this->numerator ){ … … 7359 7438 } 7360 7439 7361 function toString(){7440 public function toString(){ 7362 7441 $returnStr = implode('*',$this->numerator); 7363 7442 foreach($this->denominator as $d){ … … 7367 7446 } 7368 7447 7369 function __toString(){7448 public function __toString(){ 7370 7449 return $this->toString(); 7371 7450 } … … 7375 7454 * @param Less_Tree_Unit $other 7376 7455 */ 7377 function compare($other) {7456 public function compare($other) { 7378 7457 return $this->is( $other->toString() ) ? 0 : -1; 7379 7458 } 7380 7459 7381 function is($unitString){7460 public function is($unitString){ 7382 7461 return $this->toString() === $unitString; 7383 7462 } 7384 7463 7385 function isLength(){7464 public function isLength(){ 7386 7465 $css = $this->toCSS(); 7387 7466 return !!preg_match('/px|em|%|in|cm|mm|pc|pt|ex/',$css); 7388 7467 } 7389 7468 7390 function isAngle() {7469 public function isAngle() { 7391 7470 return isset( Less_Tree_UnitConversions::$angle[$this->toCSS()] ); 7392 7471 } 7393 7472 7394 function isEmpty(){7473 public function isEmpty(){ 7395 7474 return !$this->numerator && !$this->denominator; 7396 7475 } 7397 7476 7398 function isSingular() {7477 public function isSingular() { 7399 7478 return count($this->numerator) <= 1 && !$this->denominator; 7400 7479 } 7401 7480 7402 7481 7403 function usedUnits(){7482 public function usedUnits(){ 7404 7483 $result = array(); 7405 7484 … … 7423 7502 } 7424 7503 7425 function cancel(){7504 public function cancel(){ 7426 7505 $counter = array(); 7427 7506 $backup = null; … … 7523 7602 } 7524 7603 7525 function accept( $visitor ){7604 public function accept( $visitor ){ 7526 7605 $this->value = $visitor->visitObj($this->value); 7527 7606 } … … 7530 7609 * @see Less_Tree::genCSS 7531 7610 */ 7532 function genCSS( $output ){7611 public function genCSS( $output ){ 7533 7612 $output->add( 'url(' ); 7534 7613 $this->value->genCSS( $output ); … … 7594 7673 } 7595 7674 7596 function accept($visitor) {7675 public function accept($visitor) { 7597 7676 $this->value = $visitor->visitArray($this->value); 7598 7677 } … … 7653 7732 7654 7733 if( $this->name[1] === '@' ){ 7655 $v = new Less_Tree_Variable(substr($this->name, 1), $this->index + 1 );7734 $v = new Less_Tree_Variable(substr($this->name, 1), $this->index + 1, $this->currentFileInfo); 7656 7735 $name = '@' . $v->compile($env)->value; 7657 7736 }else{ … … 7667 7746 foreach($env->frames as $frame){ 7668 7747 if( $v = $frame->variable($name) ){ 7748 $r = $v->value->compile($env); 7669 7749 $this->evaluating = false; 7670 return $ v->value->compile($env);7671 } 7672 } 7673 7674 throw new Less_Exception_Compiler("variable " . $name . " is undefined ", null, $this->index );7750 return $r; 7751 } 7752 } 7753 7754 throw new Less_Exception_Compiler("variable " . $name . " is undefined in file ".$this->currentFileInfo["filename"], null, $this->index ); 7675 7755 } 7676 7756 … … 7785 7865 $defaultResult = $defTrue; 7786 7866 if( ($count[$defTrue] + $count[$defFalse]) > 1 ){ 7787 throw Exception( 'Ambiguous use of `default()` found when matching for `'. $this->format($args) + '`' );7867 throw new Exception( 'Ambiguous use of `default()` found when matching for `'. $this->format($args) + '`' ); 7788 7868 } 7789 7869 } … … 7823 7903 7824 7904 }else{ 7825 throw new Less_Exception_Compiler(trim($this->selector->toCSS()) . " is undefined ", null, $this->index);7905 throw new Less_Exception_Compiler(trim($this->selector->toCSS()) . " is undefined in ".$this->currentFileInfo['filename'], null, $this->index); 7826 7906 } 7827 7907 … … 8126 8206 public $foundExtends; 8127 8207 8128 function __construct(){8208 public function __construct(){ 8129 8209 $this->contexts = array(); 8130 8210 $this->allExtendsStack = array(array()); … … 8135 8215 * @param Less_Tree_Ruleset $root 8136 8216 */ 8137 function run($root){8217 public function run($root){ 8138 8218 $root = $this->visitObj($root); 8139 8219 $root->allExtends =& $this->allExtendsStack[0]; … … 8141 8221 } 8142 8222 8143 function visitRule($ruleNode, &$visitDeeper ){8223 public function visitRule($ruleNode, &$visitDeeper ){ 8144 8224 $visitDeeper = false; 8145 8225 } 8146 8226 8147 function visitMixinDefinition( $mixinDefinitionNode, &$visitDeeper ){8227 public function visitMixinDefinition( $mixinDefinitionNode, &$visitDeeper ){ 8148 8228 $visitDeeper = false; 8149 8229 } 8150 8230 8151 function visitRuleset($rulesetNode){8231 public function visitRuleset($rulesetNode){ 8152 8232 8153 8233 if( $rulesetNode->root ){ … … 8185 8265 } 8186 8266 8187 function allExtendsStackPush($rulesetNode, $selectorPath, $extend, &$j){8267 public function allExtendsStackPush($rulesetNode, $selectorPath, $extend, &$j){ 8188 8268 $this->foundExtends = true; 8189 8269 $extend = clone $extend; … … 8200 8280 8201 8281 8202 function visitRulesetOut( $rulesetNode ){8282 public function visitRulesetOut( $rulesetNode ){ 8203 8283 if( !is_object($rulesetNode) || !$rulesetNode->root ){ 8204 8284 array_pop($this->contexts); … … 8206 8286 } 8207 8287 8208 function visitMedia( $mediaNode ){8288 public function visitMedia( $mediaNode ){ 8209 8289 $mediaNode->allExtends = array(); 8210 8290 $this->allExtendsStack[] =& $mediaNode->allExtends; 8211 8291 } 8212 8292 8213 function visitMediaOut(){8293 public function visitMediaOut(){ 8214 8294 array_pop($this->allExtendsStack); 8215 8295 } 8216 8296 8217 function visitDirective( $directiveNode ){8297 public function visitDirective( $directiveNode ){ 8218 8298 $directiveNode->allExtends = array(); 8219 8299 $this->allExtendsStack[] =& $directiveNode->allExtends; 8220 8300 } 8221 8301 8222 function visitDirectiveOut(){8302 public function visitDirectiveOut(){ 8223 8303 array_pop($this->allExtendsStack); 8224 8304 } … … 8380 8460 * @param Less_Tree_Ruleset $root 8381 8461 */ 8382 function run( $root ){8462 public function run( $root ){ 8383 8463 return $this->visitObj($root); 8384 8464 } 8385 8465 8386 function visitRule( $ruleNode, &$visitDeeper ){8466 public function visitRule( $ruleNode, &$visitDeeper ){ 8387 8467 $visitDeeper = false; 8388 8468 } 8389 8469 8390 function visitMixinDefinition( $mixinDefinitionNode, &$visitDeeper ){8470 public function visitMixinDefinition( $mixinDefinitionNode, &$visitDeeper ){ 8391 8471 $visitDeeper = false; 8392 8472 } 8393 8473 8394 function visitRuleset( $rulesetNode ){8474 public function visitRuleset( $rulesetNode ){ 8395 8475 8396 8476 $paths = array(); … … 8421 8501 } 8422 8502 8423 function visitRulesetOut(){8503 public function visitRulesetOut(){ 8424 8504 array_pop($this->contexts); 8425 8505 } 8426 8506 8427 function visitMedia($mediaNode) {8507 public function visitMedia($mediaNode) { 8428 8508 $context = end($this->contexts); //$context = $this->contexts[ count($this->contexts) - 1]; 8429 8509 … … 8915 8995 private $charset; 8916 8996 8917 function __construct(){8997 public function __construct(){ 8918 8998 parent::__construct(); 8919 8999 } … … 8922 9002 * @param Less_Tree_Ruleset $root 8923 9003 */ 8924 function run( $root ){9004 public function run( $root ){ 8925 9005 return $this->visitObj($root); 8926 9006 } 8927 9007 8928 function visitRule( $ruleNode ){9008 public function visitRule( $ruleNode ){ 8929 9009 if( $ruleNode->variable ){ 8930 9010 return array(); … … 8933 9013 } 8934 9014 8935 function visitMixinDefinition($mixinNode){9015 public function visitMixinDefinition($mixinNode){ 8936 9016 // mixin definitions do not get eval'd - this means they keep state 8937 9017 // so we have to clear that state here so it isn't used if toCSS is called twice … … 8940 9020 } 8941 9021 8942 function visitExtend(){9022 public function visitExtend(){ 8943 9023 return array(); 8944 9024 } 8945 9025 8946 function visitComment( $commentNode ){9026 public function visitComment( $commentNode ){ 8947 9027 if( $commentNode->isSilent() ){ 8948 9028 return array(); … … 8951 9031 } 8952 9032 8953 function visitMedia( $mediaNode, &$visitDeeper ){9033 public function visitMedia( $mediaNode, &$visitDeeper ){ 8954 9034 $mediaNode->accept($this); 8955 9035 $visitDeeper = false; … … 8961 9041 } 8962 9042 8963 function visitDirective( $directiveNode ){9043 public function visitDirective( $directiveNode ){ 8964 9044 if( isset($directiveNode->currentFileInfo['reference']) && (!property_exists($directiveNode,'isReferenced') || !$directiveNode->isReferenced) ){ 8965 9045 return array(); … … 8985 9065 } 8986 9066 8987 function checkPropertiesInRoot( $rulesetNode ){9067 public function checkPropertiesInRoot( $rulesetNode ){ 8988 9068 8989 9069 if( !$rulesetNode->firstRoot ){ … … 9000 9080 9001 9081 9002 function visitRuleset( $rulesetNode, &$visitDeeper ){9082 public function visitRuleset( $rulesetNode, &$visitDeeper ){ 9003 9083 9004 9084 $visitDeeper = false; … … 9097 9177 } 9098 9178 9099 function _removeDuplicateRules( &$rules ){9179 protected function _removeDuplicateRules( &$rules ){ 9100 9180 // remove duplicates 9101 9181 $ruleCache = array(); … … 9124 9204 } 9125 9205 9126 function _mergeRules( &$rules ){9206 protected function _mergeRules( &$rules ){ 9127 9207 $groups = array(); 9128 9208 … … 9176 9256 } 9177 9257 9178 static function toExpression($values){9258 public static function toExpression($values){ 9179 9259 $mapped = array(); 9180 9260 foreach($values as $p){ … … 9184 9264 } 9185 9265 9186 static function toValue($values){9266 public static function toValue($values){ 9187 9267 //return new Less_Tree_Value($values); ?? 9188 9268 … … 9363 9443 * 9364 9444 */ 9365 function Chunks(){9445 protected function Chunks(){ 9366 9446 $level = 0; 9367 9447 $parenLevel = 0; … … 9490 9570 } 9491 9571 9492 function CharCode($pos){9572 public function CharCode($pos){ 9493 9573 return ord($this->input[$pos]); 9494 9574 } 9495 9575 9496 9576 9497 function fail( $msg, $index = null ){9577 public function fail( $msg, $index = null ){ 9498 9578 9499 9579 if( !$index ){ … … 9623 9703 count($sourceLines), // original_line 9624 9704 strlen($sourceColumns), // original_column 9625 $fileInfo ['currentUri']9705 $fileInfo 9626 9706 ); 9627 9707 }else{ … … 9632 9712 count($sourceLines) + $i, // original_line 9633 9713 $i === 0 ? strlen($sourceColumns) : 0, // original_column 9634 $fileInfo ['currentUri']9714 $fileInfo 9635 9715 ); 9636 9716 } … … 9875 9955 9876 9956 // base path for filename normalization 9877 'sourceMapBasepath' => '' 9957 'sourceMapRootpath' => '', 9958 9959 // base path for filename normalization 9960 'sourceMapBasepath' => '' 9878 9961 ); 9879 9962 … … 9912 9995 */ 9913 9996 protected $sources = array(); 9997 protected $source_keys = array(); 9914 9998 9915 9999 /** … … 9928 10012 9929 10013 // fix windows paths 9930 if( isset($this->options['sourceMapBasepath']) ){ 9931 $this->options['sourceMapBasepath'] = str_replace('\\', '/', $this->options['sourceMapBasepath']); 10014 if( !empty($this->options['sourceMapRootpath']) ){ 10015 $this->options['sourceMapRootpath'] = str_replace('\\', '/', $this->options['sourceMapRootpath']); 10016 $this->options['sourceMapRootpath'] = rtrim($this->options['sourceMapRootpath'],'/').'/'; 9932 10017 } 9933 10018 } … … 9999 10084 */ 10000 10085 protected function normalizeFilename($filename){ 10086 10001 10087 $filename = str_replace('\\', '/', $filename); 10088 $rootpath = $this->getOption('sourceMapRootpath'); 10002 10089 $basePath = $this->getOption('sourceMapBasepath'); 10003 10090 10004 if( $basePath && ($pos = strpos($filename, $basePath)) !== false ){ 10005 $filename = substr($filename, $pos + strlen($basePath)); 10006 if(strpos($filename, '\\') === 0 || strpos($filename, '/') === 0){ 10007 $filename = substr($filename, 1); 10008 } 10009 } 10010 return sprintf('%s%s', $this->getOption('sourceMapRootpath'), $filename); 10091 // "Trim" the 'sourceMapBasepath' from the output filename. 10092 if (strpos($filename, $basePath) === 0) { 10093 $filename = substr($filename, strlen($basePath)); 10094 } 10095 10096 // Remove extra leading path separators. 10097 if(strpos($filename, '\\') === 0 || strpos($filename, '/') === 0){ 10098 $filename = substr($filename, 1); 10099 } 10100 10101 return $rootpath . $filename; 10011 10102 } 10012 10103 … … 10020 10111 * @param string $sourceFile The original source file 10021 10112 */ 10022 public function addMapping($generatedLine, $generatedColumn, $originalLine, $originalColumn, $sourceFile){ 10113 public function addMapping($generatedLine, $generatedColumn, $originalLine, $originalColumn, $fileInfo ){ 10114 10023 10115 $this->mappings[] = array( 10024 10116 'generated_line' => $generatedLine, … … 10026 10118 'original_line' => $originalLine, 10027 10119 'original_column' => $originalColumn, 10028 'source_file' => $ sourceFile10120 'source_file' => $fileInfo['currentUri'] 10029 10121 ); 10030 10122 10031 10032 $norm_file = $this->normalizeFilename($sourceFile); 10033 10034 $this->sources[$norm_file] = $sourceFile; 10123 $this->sources[$fileInfo['currentUri']] = $fileInfo['filename']; 10035 10124 } 10036 10125 … … 10066 10155 10067 10156 // A list of original sources used by the 'mappings' entry. 10068 $sourceMap['sources'] = array_keys($this->sources); 10069 10157 $sourceMap['sources'] = array(); 10158 foreach($this->sources as $source_uri => $source_filename){ 10159 $sourceMap['sources'][] = $this->normalizeFilename($source_filename); 10160 } 10070 10161 10071 10162 … … 10118 10209 } 10119 10210 10211 $this->source_keys = array_flip(array_keys($this->sources)); 10212 10213 10120 10214 // group mappings by generated line number. 10121 10215 $groupedMap = $groupedMapEncoded = array(); … … 10141 10235 // find the index 10142 10236 if( $m['source_file'] ){ 10143 $index = $this->findFileIndex($ this->normalizeFilename($m['source_file']));10237 $index = $this->findFileIndex($m['source_file']); 10144 10238 if( $index !== false ){ 10145 10239 $mapEncoded .= $this->encoder->encode($index - $lastOriginalIndex); … … 10171 10265 */ 10172 10266 protected function findFileIndex($filename){ 10173 return array_search($filename, array_keys($this->sources));10267 return $this->source_keys[$filename]; 10174 10268 } 10175 10269 -
less-compiler/trunk/libs/less-parser/Version.php
r912308 r943838 9 9 class Less_Version{ 10 10 11 const version = '1.7.0. 1'; // The current build number of less.php11 const version = '1.7.0.2'; // The current build number of less.php 12 12 const less_version = '1.7'; // The less.js version that this build should be compatible with 13 13 const cache_version = '170'; // The parser cache version -
less-compiler/trunk/libs/wm-settings/wm-settings.css
r912308 r943838 2 2 form.wrap p.submit { 3 3 padding-top: 20px; 4 border-top: 1px solid #d fdfdf;4 border-top: 1px solid #ddd; 5 5 } 6 6 form.wrap td .settings-error { … … 11 11 margin: 0.5em 0; 12 12 } 13 form.wrap .wm-settings-tabs-header h3 { 14 float: left; 15 padding: 10px 15px; 16 font-weight: 300; 17 background-color: #fff; 18 border: 1px solid #ddd; 19 border-right: none; 20 border-bottom: none; 21 cursor: pointer; 22 } 23 form.wrap .wm-settings-tabs-header h3:hover { 24 background-color: #f9f9f9; 25 } 26 form.wrap .wm-settings-tabs-header h3.wm-settings-tab-active { 27 background-color: #f1f1f1; 28 } 29 form.wrap .wm-settings-tabs-header h3:last-child { 30 border-right: 1px solid #ddd; 31 } 32 .wm-settings-tabs-header, 33 .wm-settings-tabs-content { 34 clear: both; 35 } -
less-compiler/trunk/libs/wm-settings/wm-settings.js
r912308 r943838 1 1 jQuery(document).ready(function ($) { 2 2 'use strict'; 3 var tabs = $('.wm-settings-tab', 'form'), 4 tabsHeader, 5 tabsContent, 6 active = 'wm-settings-tab-active', 7 current = $('#wm-settings-current-tab'); 8 if (tabs.length) { 9 tabsHeader = $('<div>').addClass('wm-settings-tabs-header').insertBefore('form .submit:first'); 10 tabsContent = $('<div>').addClass('wm-settings-tabs-content').insertAfter(tabsHeader); 11 tabs.each(function(i, el) { 12 var title = $(el).prev('h3').appendTo(tabsHeader), 13 nextAll = $(el).nextAll(), 14 tab = $('<div>').appendTo(tabsContent).hide(); 15 nextAll.each(function() { 16 var tag = $(this).prop('tagName'); 17 if (tag === 'H3' || tag === 'INPUT') { 18 return false; 19 } 20 $(this).appendTo(tab); 21 }); 22 title.click(function(e) { 23 e.preventDefault(); 24 if (!title.hasClass(active)) { 25 current.val(i); 26 $('.' + active, tabsContent).fadeOut('fast', function() { 27 $('.' + active, 'form').removeClass(active); 28 title.addClass(active); 29 tab.fadeIn('fast').addClass(active); 30 }); 31 } 32 }); 33 }); 34 tabsHeader.children().eq(current.val()).addClass(active); 35 tabsContent.children().eq(current.val()).show().addClass(active); 36 } 3 37 $('.wm-settings-media', 'form').each(function () { 4 38 var frame, -
less-compiler/trunk/libs/wm-settings/wm-settings.php
r912308 r943838 1 1 <?php 2 2 /* 3 http://webmaestro.fr/wordpress-settings-api-options-pages/ 3 Plugin Name: WebMaestro Settings 4 Plugin URI: http://webmaestro.fr/wordpress-settings-api-options-pages/ 5 Author: Etienne Baudry 6 Author URI: http://webmaestro.fr 7 Description: Simplified options system for WordPress. Generates a default page for settings. 8 Version: 1.2.4 9 License: GNU General Public License 10 License URI: license.txt 11 Text Domain: wm-settings 12 GitHub Plugin URI: https://github.com/WebMaestroFr/wm-settings 13 GitHub Branch: master 4 14 */ 5 15 … … 28 38 $this->args = array_merge( array( 29 39 'submit' => __( 'Save Settings', 'wm-settings' ), 30 'reset' => __( 'Reset Settings', 'wm-settings' ) 40 'reset' => __( 'Reset Settings', 'wm-settings' ), 41 'tabs' => true 31 42 ), $args ); 32 43 add_action( 'admin_menu', array( $this, 'admin_menu' ) ); … … 63 74 } 64 75 } 76 // This is really ugly, there must be a better way to deal with that active tab 77 $current_tag = "wm_settings_{$this->page}_current_tab"; 78 if ( isset( $_POST[$current_tag] ) ) { 79 update_option( $current_tag, (int) $_POST[$current_tag] ); 80 } 65 81 } 66 82 … … 146 162 { ?> 147 163 <form action="options.php" method="POST" enctype="multipart/form-data" class="wrap"> 164 <input type="hidden" name="wm_settings_<?php echo $this->page; ?>_current_tab" value="<?php echo get_option( "wm_settings_{$this->page}_current_tab" ); ?>" id="wm-settings-current-tab"> 148 165 <h2><?php echo $this->title; ?></h2> 149 166 <?php 150 167 // Avoid showing admin notice twice 151 // TODO : Target the pages where it happens152 168 if ( ! in_array( $this->menu['parent'], array( 'options-general.php' ) ) ) { 153 169 settings_errors(); … … 168 184 { 169 185 extract( $args ); 186 echo "<input name='{$id}[{$this->page}_setting]' type='hidden' value='{$id}'"; 187 if ( $this->args['tabs'] && ! empty( $this->settings[$id]['title'] ) ) { 188 echo " class='wm-settings-tab'"; 189 } 190 echo " />"; 170 191 if ( $text = $this->settings[$id]['description'] ) { 171 192 echo wpautop( $text ); 172 193 } 173 echo "<input name='{$id}[{$this->page}_setting]' type='hidden' value='{$id}' />";174 194 } 175 195 … … 187 207 { 188 208 case 'checkbox': 189 $check = checked( 1, $value, false );209 $check = checked( 1, $value, false ); 190 210 echo "<label><input {$attrs} id='{$id}' type='checkbox' value='1' {$check} />"; 191 211 if ( $description ) { echo " {$description}"; } … … 216 236 case 'media': 217 237 echo "<fieldset class='wm-settings-media' id='{$id}'><input {$attrs} type='hidden' value='{$value}' />"; 238 echo "<p><a class='button button-large wm-select-media' title='{$label}'>" . sprintf( __( 'Select %s', 'wm-settings' ), $label ) . "</a> "; 239 echo "<a class='button button-small wm-remove-media' title='{$label}'>" . sprintf( __( 'Remove %s', 'wm-settings' ), $label ) . "</a></p>"; 218 240 if ( $value ) { 219 echo wp_get_attachment_image( $value, 'medium' ); 220 } 221 echo "<p><a class='button button-large wm-select-media' title='{$label}'>" . sprintf( __( 'Select %s', 'wm-settings' ), $label ) . "</a> "; 222 echo "<a class='button button-small wm-remove-media' title='{$label}'>" . sprintf( __( 'Remove %s', 'wm-settings' ), $label ) . "</a></p>{$desc}</fieldset>"; 241 echo wpautop( wp_get_attachment_image( $value, 'medium' ) ); 242 } 243 echo "{$desc}</fieldset>"; 223 244 break; 224 245 … … 232 253 foreach ( $options as $n => $label ) { 233 254 $a = preg_replace( "/name\=\'(.+)\'/", "name='$1[{$n}]'", $attrs ); 234 $check = checked( 1, $value[$n], false );255 $check = checked( 1, $value[$n], false ); 235 256 $options[$n] = "<label><input {$a} type='checkbox' value='1' {$check} /> {$label}</label>"; 236 257 } … … 352 373 } 353 374 375 function wm_settings_plugin_priority() 376 { 377 $wm_settings = plugin_basename( __FILE__ ); 378 $active_plugins = get_option( 'active_plugins' ); 379 if ( $order = array_search( $wm_settings, $active_plugins ) ) { 380 array_splice( $active_plugins, $order, 1 ); 381 array_unshift( $active_plugins, $wm_settings ); 382 update_option( 'active_plugins', $active_plugins ); 383 } 384 } 385 add_action( 'activated_plugin', 'wm_settings_plugin_priority' ); 386 354 387 } 355 388 -
less-compiler/trunk/plugin.php
r919717 r943838 6 6 Author URI: http://webmaestro.fr 7 7 Description: Less Compiler for Wordpress 8 Version: 1. 2.28 Version: 1.3 9 9 License: GNU General Public License 10 10 License URI: license.txt … … 61 61 add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) ); 62 62 // add_editor_style( get_stylesheet_directory_uri() . self::$output ); 63 add_filter( 'style_loader_src', array( __CLASS__, 'style_loader_src' ) ); 63 64 } 64 65 … … 71 72 ), array( 72 73 'less' => array( 73 'description' => '<p>' . sprintf( __( 'The resulting CSS will be compiled into <strong>%s</strong>. You can use the PHP function <code>less_output( $css_file );</code> to output an other file instead (relative to <strong>%s</strong>).', 'wm-less' ), self::$output, get_stylesheet_directory() ) . '</p><p>' . __( 'Import any LESS files to compile prior to this stylesheet with <code>less_import( $files_array );</code>.', 'wm-less' ) . '</p>', 74 'description' => '<p>' . 75 sprintf( __( 'The resulting CSS will be compiled into <strong>%s</strong>.', 'wm-less' ), ltrim( self::$output, '/' ) ) . 76 ' ' . sprintf( __( 'You can use the PHP function <code>less_output( $css_file );</code> to output an other file instead (relative to <strong>%s</strong>).', 'wm-less' ), get_stylesheet_directory() ) . 77 ' ' . __( 'Do not set your theme\'s <strong>style.css</strong> as output !', 'wm-less' ) . 78 '</p><p>' . 79 __( 'Import any LESS files to compile prior to this stylesheet with <code>less_import( $files_array );</code>.', 'wm-less' ) . 80 '</p><p>' . 81 __( 'Alternatively, you can enqueue any LESS sheet the same way you would for your CSS : <code>wp_enqueue_style( $handle, $src, $deps, $ver, $media );</code>.', 'wm-less' ) . 82 '</p>', 74 83 'fields' => array( 75 84 'compiler' => array( … … 128 137 { 129 138 require_once( plugin_dir_path( __FILE__ ) . 'libs/less-parser/Less.php' ); 139 $parser = new Less_Parser( array( 140 'compress' => true, 141 'cache_dir' => self::get_cache_dir() 142 ) ); 143 $parser->SetImportDirs( array( 144 get_stylesheet_directory() => '', 145 get_template_directory() => '' 146 ) ); 130 147 try { 131 $cache_dir = plugin_dir_path( __FILE__ ) . 'cache';132 if ( ! is_writable( $cache_dir ) ) {133 add_action( 'admin_notices', array( __CLASS__, 'cache_permissions_notice' ) );134 }135 $parser = new Less_Parser( array(136 'compress' => true,137 'cache_dir' => is_writable( $cache_dir ) ? $cache_dir : null138 ) );139 $parser->SetImportDirs( array(140 get_stylesheet_directory() => '',141 get_template_directory() => ''142 ) );143 148 foreach ( self::$imports as $file ) { 144 149 $parser->parse( "@import '{$file}';" ); … … 152 157 } 153 158 } 159 private static function get_cache_dir() 160 { 161 $cache_dir = ABSPATH . 'wp-content/cache'; 162 if ( ! is_dir( $cache_dir ) ) { 163 mkdir( $cache_dir ); 164 } 165 if ( ! is_writable( $cache_dir ) ) { 166 add_action( 'admin_notices', array( __CLASS__, 'cache_permissions_notice' ) ); 167 return null; 168 } 169 return $cache_dir; 170 } 154 171 155 172 public static function admin_enqueue_scripts( $hook_suffix ) 156 173 { 157 174 if ( 'toplevel_page_less' == $hook_suffix ) { 158 wp_enqueue_script( 'codemirror', plugin_dir_url( __FILE__ ) . ' /js/codemirror.js' );159 wp_enqueue_script( 'codemirror-less', plugin_dir_url( __FILE__ ) . ' /js/codemirror-less.js', array( 'codemirror' ) );160 wp_enqueue_script( 'less-compiler', plugin_dir_url( __FILE__ ) . ' /js/less-compiler.js', array( 'codemirror-less' ) );161 wp_enqueue_style( 'codemirror', plugin_dir_url( __FILE__ ) . ' /css/codemirror.css' );162 wp_enqueue_style( 'less-compiler', plugin_dir_url( __FILE__ ) . ' /css/less-compiler.css' );175 wp_enqueue_script( 'codemirror', plugin_dir_url( __FILE__ ) . 'js/codemirror.js' ); 176 wp_enqueue_script( 'codemirror-less', plugin_dir_url( __FILE__ ) . 'js/codemirror-less.js', array( 'codemirror' ) ); 177 wp_enqueue_script( 'less-compiler', plugin_dir_url( __FILE__ ) . 'js/less-compiler.js', array( 'codemirror-less' ) ); 178 wp_enqueue_style( 'codemirror', plugin_dir_url( __FILE__ ) . 'css/codemirror.css' ); 179 wp_enqueue_style( 'less-compiler', plugin_dir_url( __FILE__ ) . 'css/less-compiler.css' ); 163 180 } 164 181 } … … 170 187 } 171 188 } 189 190 public static function style_loader_src( $src ) 191 { 192 $input = strtok( $src, '?' ); 193 if ( preg_match( '/\.less$/', $input ) ) { 194 require_once( plugin_dir_path( __FILE__ ) . 'libs/less-parser/Less.php' ); 195 $input = str_replace( trailingslashit( site_url() ), ABSPATH, $input ); 196 if ( $cache_dir = self::get_cache_dir() ) { 197 return trailingslashit( str_replace( ABSPATH, trailingslashit( site_url() ), $cache_dir ) ) . Less_Cache::Get( array( 198 $input => dirname( $input ) 199 ), array( 200 'cache_dir' => $cache_dir 201 ) ); 202 } 203 return null; 204 } 205 return $src; 206 } 172 207 } 173 208 add_action( 'init', array( 'WM_Less', 'init' ) ); -
less-compiler/trunk/readme.txt
r912476 r943838 5 5 Requires at least: 3.9 6 6 Tested up to: 3.9.1 7 Stable tag: 1. 27 Stable tag: 1.3 8 8 License: GPLv2 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 39 39 Import any LESS files to compile prior to the dashboard stylesheet. 40 40 41 - ```wp_enqueue_style( 'my-less-handle', 'http://example.com/css/mystyle.less', $deps, $ver, $media );``` 42 43 Alternatively you can register and enqueue your LESS sheets the same way you would do for your CSS. 44 45 41 46 You will most likely use these in your theme's `functions.php`. 42 47 43 The plugin uses [ **leafo**'s LESS compiler written in PHP](https://github.com/leafo/lessphp).48 The plugin uses [the Less.php Compiler](http://lessphp.gpeasy.com/). 44 49 45 50 == Installation == … … 62 67 == Changelog == 63 68 64 = 1.2 = 65 * Minor fixes (typo, dependences) 69 = 1.3 = 70 * "wp_enqueue_style" support 71 * Moved cache directory to wp-content/cache 66 72 67 = 1.0 = 68 * First stable release 69 70 == Upgrade Notice == 73 = 1.2.2 = 74 * Menu icon and cache warning 71 75 72 76 = 1.2 = 73 77 * Minor fixes (typo, dependences) 74 78 75 = 1.0 = 76 First stable release 79 == Upgrade Notice == 80 81 = 1.3 = 82 * "wp_enqueue_style" support 83 * Moved cache directory to wp-content/cache 84 85 = 1.2 = 86 * Minor fixes (typo, dependences)
Note: See TracChangeset
for help on using the changeset viewer.