Tree.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /**
  24. * @param Less_Tree_Ruleset[] $rules
  25. */
  26. public static function outputRuleset( $output, $rules ) {
  27. $ruleCnt = count( $rules );
  28. Less_Environment::$tabLevel++;
  29. // Compressed
  30. if ( Less_Parser::$options['compress'] ) {
  31. $output->add( '{' );
  32. for ( $i = 0; $i < $ruleCnt; $i++ ) {
  33. $rules[$i]->genCSS( $output );
  34. }
  35. $output->add( '}' );
  36. Less_Environment::$tabLevel--;
  37. return;
  38. }
  39. // Non-compressed
  40. $tabSetStr = "\n".str_repeat( Less_Parser::$options['indentation'], Less_Environment::$tabLevel - 1 );
  41. $tabRuleStr = $tabSetStr.Less_Parser::$options['indentation'];
  42. $output->add( " {" );
  43. for ( $i = 0; $i < $ruleCnt; $i++ ) {
  44. $output->add( $tabRuleStr );
  45. $rules[$i]->genCSS( $output );
  46. }
  47. Less_Environment::$tabLevel--;
  48. $output->add( $tabSetStr.'}' );
  49. }
  50. public function accept( $visitor ) {
  51. }
  52. public static function ReferencedArray( $rules ) {
  53. foreach ( $rules as $rule ) {
  54. if ( method_exists( $rule, 'markReferenced' ) ) {
  55. $rule->markReferenced();
  56. }
  57. }
  58. }
  59. /**
  60. * Requires php 5.3+
  61. */
  62. public static function __set_state( $args ) {
  63. $class = get_called_class();
  64. $obj = new $class( null, null, null, null );
  65. foreach ( $args as $key => $val ) {
  66. $obj->$key = $val;
  67. }
  68. return $obj;
  69. }
  70. }