Class: Less::Node::Expression
- Inherits:
-
Array
show all
- Defined in:
- lib/less/engine/nodes/property.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Array
#dissolve, #mean, #one?, #sum
Constructor Details
#initialize(ary, parent = nil) ⇒ Expression
Returns a new instance of Expression.
98
99
100
101
|
# File 'lib/less/engine/nodes/property.rb', line 98
def initialize ary, parent = nil
self.parent = parent
super ary
end
|
Instance Attribute Details
Returns the value of attribute parent.
96
97
98
|
# File 'lib/less/engine/nodes/property.rb', line 96
def parent
@parent
end
|
Instance Method Details
105
|
# File 'lib/less/engine/nodes/property.rb', line 105
def entities; select {|i| i.kind_of? Entity } end
|
Evaluates the expression and instantiates a new Literal with the result ex: [#111, +, #111] will evaluate to a Color node, with value #222
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/less/engine/nodes/property.rb', line 137
def evaluate
if size > 2 or !terminal?
replace map {|e| e.respond_to?(:evaluate) ? e.evaluate : e }
unit = literals.map do |node|
node.unit
end.compact.uniq.tap do |ary|
raise MixedUnitsError, self * ' ' if ary.size > 1
end.join
entity = literals.find {|e| e.unit == unit } || entities.first
result = operators.empty?? self : eval(to_ruby.join)
case result
when Entity then result
when Expression then result.one?? result.first : self.class.new(result)
else entity.class.new(result, *(unit if entity.class == Node::Number))
end
elsif size == 1
first
else
self
end
end
|
#expressions ⇒ Object
103
|
# File 'lib/less/engine/nodes/property.rb', line 103
def expressions; select {|i| i.kind_of? Expression } end
|
113
114
115
|
# File 'lib/less/engine/nodes/property.rb', line 113
def inspect
'[' + map {|i| i.inspect }.join(', ') + ']'
end
|
106
|
# File 'lib/less/engine/nodes/property.rb', line 106
def literals; select {|i| i.kind_of? Literal } end
|
#operators ⇒ Object
104
|
# File 'lib/less/engine/nodes/property.rb', line 104
def operators; select {|i| i.is_a? Operator } end
|
#terminal? ⇒ Boolean
117
118
119
|
# File 'lib/less/engine/nodes/property.rb', line 117
def terminal?
expressions.empty?
end
|
121
122
123
124
125
|
# File 'lib/less/engine/nodes/property.rb', line 121
def to_css
map do |i|
i.respond_to?(:to_css) ? i.to_css : i.to_s
end * ' '
end
|
127
128
129
130
131
|
# File 'lib/less/engine/nodes/property.rb', line 127
def to_ruby
map do |i|
i.respond_to?(:to_ruby) ? i.to_ruby : i.to_s
end
end
|