Attribute.php 979 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Attribute
  4. *
  5. * @package Less
  6. * @subpackage tree
  7. */
  8. class Less_Tree_Attribute extends Less_Tree {
  9. public $key;
  10. public $op;
  11. public $value;
  12. public $type = 'Attribute';
  13. public function __construct( $key, $op, $value ) {
  14. $this->key = $key;
  15. $this->op = $op;
  16. $this->value = $value;
  17. }
  18. public function compile( $env ) {
  19. $key_obj = is_object( $this->key );
  20. $val_obj = is_object( $this->value );
  21. if ( !$key_obj && !$val_obj ) {
  22. return $this;
  23. }
  24. return new Less_Tree_Attribute(
  25. $key_obj ? $this->key->compile( $env ) : $this->key,
  26. $this->op,
  27. $val_obj ? $this->value->compile( $env ) : $this->value );
  28. }
  29. /**
  30. * @see Less_Tree::genCSS
  31. */
  32. public function genCSS( $output ) {
  33. $output->add( $this->toCSS() );
  34. }
  35. public function toCSS() {
  36. $value = $this->key;
  37. if ( $this->op ) {
  38. $value .= $this->op;
  39. $value .= ( is_object( $this->value ) ? $this->value->toCSS() : $this->value );
  40. }
  41. return '[' . $value . ']';
  42. }
  43. }