Element.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Element
  4. *
  5. * @package Less
  6. * @subpackage tree
  7. */
  8. class Less_Tree_Element extends Less_Tree{
  9. public $combinator = '';
  10. public $value = '';
  11. public $index;
  12. public $currentFileInfo;
  13. public $type = 'Element';
  14. public $value_is_object = false;
  15. public function __construct($combinator, $value, $index = null, $currentFileInfo = null ){
  16. $this->value = $value;
  17. $this->value_is_object = is_object($value);
  18. if( $combinator ){
  19. $this->combinator = $combinator;
  20. }
  21. $this->index = $index;
  22. $this->currentFileInfo = $currentFileInfo;
  23. }
  24. public function accept( $visitor ){
  25. if( $this->value_is_object ){ //object or string
  26. $this->value = $visitor->visitObj( $this->value );
  27. }
  28. }
  29. public function compile($env){
  30. if( Less_Environment::$mixin_stack ){
  31. return new Less_Tree_Element($this->combinator, ($this->value_is_object ? $this->value->compile($env) : $this->value), $this->index, $this->currentFileInfo );
  32. }
  33. if( $this->value_is_object ){
  34. $this->value = $this->value->compile($env);
  35. }
  36. return $this;
  37. }
  38. /**
  39. * @see Less_Tree::genCSS
  40. */
  41. public function genCSS( $output ){
  42. $output->add( $this->toCSS(), $this->currentFileInfo, $this->index );
  43. }
  44. public function toCSS(){
  45. if( $this->value_is_object ){
  46. $value = $this->value->toCSS();
  47. }else{
  48. $value = $this->value;
  49. }
  50. if( $value === '' && $this->combinator && $this->combinator === '&' ){
  51. return '';
  52. }
  53. return Less_Environment::$_outputMap[$this->combinator] . $value;
  54. }
  55. }