PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/lessphp/Tree.php

https://bitbucket.org/moodle/moodle
PHP | 90 lines | 48 code | 22 blank | 20 comment | 4 complexity | 799f9d39be65cbda499da580e752d31e MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0
  1. <?php
  2. /**
  3. * Tree
  4. *
  5. * @package Less
  6. * @subpackage tree
  7. */
  8. class Less_Tree{
  9. public $cache_string;
  10. public function toCSS(){
  11. $output = new Less_Output();
  12. $this->genCSS($output);
  13. return $output->toString();
  14. }
  15. /**
  16. * Generate CSS by adding it to the output object
  17. *
  18. * @param Less_Output $output The output
  19. * @return void
  20. */
  21. public function genCSS($output){}
  22. /**
  23. * @param Less_Tree_Ruleset[] $rules
  24. */
  25. public static function outputRuleset( $output, $rules ){
  26. $ruleCnt = count($rules);
  27. Less_Environment::$tabLevel++;
  28. // Compressed
  29. if( Less_Parser::$options['compress'] ){
  30. $output->add('{');
  31. for( $i = 0; $i < $ruleCnt; $i++ ){
  32. $rules[$i]->genCSS( $output );
  33. }
  34. $output->add( '}' );
  35. Less_Environment::$tabLevel--;
  36. return;
  37. }
  38. // Non-compressed
  39. $tabSetStr = "\n".str_repeat( Less_Parser::$options['indentation'] , Less_Environment::$tabLevel-1 );
  40. $tabRuleStr = $tabSetStr.Less_Parser::$options['indentation'];
  41. $output->add( " {" );
  42. for($i = 0; $i < $ruleCnt; $i++ ){
  43. $output->add( $tabRuleStr );
  44. $rules[$i]->genCSS( $output );
  45. }
  46. Less_Environment::$tabLevel--;
  47. $output->add( $tabSetStr.'}' );
  48. }
  49. public function accept($visitor){}
  50. public static function ReferencedArray($rules){
  51. foreach($rules as $rule){
  52. if( method_exists($rule, 'markReferenced') ){
  53. $rule->markReferenced();
  54. }
  55. }
  56. }
  57. /**
  58. * Requires php 5.3+
  59. */
  60. public static function __set_state($args){
  61. $class = get_called_class();
  62. $obj = new $class(null,null,null,null);
  63. foreach($args as $key => $val){
  64. $obj->$key = $val;
  65. }
  66. return $obj;
  67. }
  68. }