Class: Less::Node::Expression
- Defined in:
- lib/less/engine/nodes/property.rb
Instance Method Summary collapse
- #entities ⇒ Object
-
#evaluate ⇒ Object
Evaluates the expression and instantiates a new Literal with the result ex: [#111, +, #111] will evaluate to a Color node, with value #222.
- #inspect ⇒ Object
- #literals ⇒ Object
- #operators ⇒ Object
- #to_css ⇒ Object
Instance Method Details
#entities ⇒ Object
66 |
# File 'lib/less/engine/nodes/property.rb', line 66 def entities; select {|i| i.kind_of? Entity } end |
#evaluate ⇒ Object
Evaluates the expression and instantiates a new Literal with the result ex: [#111, +, #111] will evaluate to a Color node, with value #222
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/less/engine/nodes/property.rb', line 81 def evaluate log "evaluating #{self}" log "#{self.select{|i| i.is_a? Entity }}" if size > 2 && (entities.size == operators.size + 1) # Create a sub-expression with all the variables/properties evaluated evaluated = Expression.new map {|e| e.respond_to?(:evaluate) ? e.evaluate : e } unit = evaluated.literals.map do |node| node.unit end.compact.uniq.tap do |ary| raise MixedUnitsError, self * ' ' if ary.size > 1 end.join entity = evaluated.literals.find {|e| e.unit == unit } || evaluated.first ruby = map {|e| e.to_ruby if e.respond_to? :to_ruby } unless ruby.include? nil log "ruby(#{unit}): " + ruby.join(' ') + "\n" if entity log "\n# => #{eval(ruby.join)} <#{entity.class}>\n" entity.class.new(eval(ruby.join), *(unit if entity.class == Node::Number)) else log "\n# => not evaluated" first end else log "some elements dont respond to to_ruby: #{ruby}" self end elsif size == 1 log "not evaluating, size == 1" first else self end end |
#inspect ⇒ Object
69 70 71 |
# File 'lib/less/engine/nodes/property.rb', line 69 def inspect '[' + map {|i| i.inspect }.join(', ') + ']' end |
#literals ⇒ Object
67 |
# File 'lib/less/engine/nodes/property.rb', line 67 def literals; select {|i| i.kind_of? Literal } end |
#operators ⇒ Object
65 |
# File 'lib/less/engine/nodes/property.rb', line 65 def operators; select {|i| i.is_a? Operator } end |
#to_css ⇒ Object
73 74 75 |
# File 'lib/less/engine/nodes/property.rb', line 73 def to_css map {|i| i.to_css } * ' ' end |