Class: Less2Sass::Less::Tree::ExpressionNode

Inherits:
Node
  • Object
show all
Defined in:
lib/less2sass/less/tree/expression_node.rb

Overview

Represents the expression in the Less AST.

Sass does not have an Expression node. It is usually represented as the ‘expr` member of the Sass::Tree::VariableNode, that represents a variable definition.

The Sass equivalent is either Sass::Script::Value::Base wrapped in Sass::Script::Tree::Literal or Sass::Tree::Node.

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #has_children, #has_parent, #line, #parent, #ref_vars

Instance Method Summary collapse

Methods inherited from Node

#<<, #==, #contains_variables?, #creates_context?, #each, #get_referenced_variable_names, #initialize, #transform

Constructor Details

This class inherits a constructor from Less2Sass::Less::Tree::Node

Instance Attribute Details

#valueObject

Returns the value of attribute value.



13
14
15
# File 'lib/less2sass/less/tree/expression_node.rb', line 13

def value
  @value
end

Instance Method Details

#to_sass::Sass::Script::Tree::Literal, ...

Returns:

  • (::Sass::Script::Tree::Literal, ::Sass::Script::Tree::ListLiteral, ::Sass::Tree::Node)

See Also:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/less2sass/less/tree/expression_node.rb', line 17

def to_sass
  if @value.is_a?(Array)
    # TODO: document solution of: method to_sass is invoked on "to right":String, deal with it
    if is_multiword_keyword?
      multiword_keyword_argument
    elsif should_be_literal?
      @value.inject([]) { |value, elem| value << elem.to_s }.join(' ')
    else
      elements = @value.inject([]) do |value, elem|
        node = elem.to_sass
        node = node(::Sass::Script::Tree::Literal.new(node), line) if node.is_a?(::Sass::Script::Value::Base)
        value << node
      end
      node(::Sass::Script::Tree::ListLiteral.new(elements, :space), line)
    end
  else
    value = @value.to_sass
    return value unless value.is_a?(::Sass::Script::Value::Base)
    node(::Sass::Script::Tree::Literal.new(value), line)
  end
end