Class: Less2Sass::Less::Tree::ValueNode
- Defined in:
- lib/less2sass/less/tree/value_node.rb
Overview
Represents the value of any Less AST node.
It has no individual representation in Sass, so it returns its value node’s Sass representation, when #to_sass gets called.
Sass equivalents:
- {::Sass::Script::Tree::Literal} if part of property declaration
- {::Sass::Script::Tree::ListLiteral} if part of variable definition
Instance Attribute Summary collapse
-
#value ⇒ Node+
The ValueNode is not the final value of a variable or a property.
Attributes inherited from Node
#children, #has_children, #has_parent, #line, #parent, #ref_vars
Instance Method Summary collapse
-
#to_sass ⇒ ::Sass::Script::Tree::Literal, ::Sass::Script::Tree::ListLiteral
This node’s value is either a single expression, or an array of those.
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
#value ⇒ Node+
The ValueNode is not the final value of a variable or a property.
23 24 25 |
# File 'lib/less2sass/less/tree/value_node.rb', line 23 def value @value end |
Instance Method Details
#to_sass ⇒ ::Sass::Script::Tree::Literal, ::Sass::Script::Tree::ListLiteral
This node’s value is either a single expression, or an array of those. The array needs to be further processed.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/less2sass/less/tree/value_node.rb', line 31 def to_sass if @value.is_a?(Array) # TODO: don't forget about interpolation. What if one of the expressions is a variable? if @parent.is_variable_definition? || contains_variables? elements = @value.inject([]) { |elements, elem| elements << elem.to_sass } node(::Sass::Script::Tree::ListLiteral.new(elements, :comma), line) else value = @value.inject([]) do |value, elem| substring = elem.to_sass # TODO: describe solution for '"Source Code Pro", Monaco, monospace' substring = substring.value.value if substring.is_a?(::Sass::Script::Tree::Literal) value << substring end.join(', ') node(::Sass::Script::Tree::Literal.new(::Sass::Script::Value::String.new(value)), line) end else @value.to_sass end end |