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.
90
91
92
93
|
# File 'lib/less/engine/nodes/property.rb', line 90
def initialize ary, parent = nil
self.parent = parent
super ary
end
|
Instance Attribute Details
Returns the value of attribute parent.
88
89
90
|
# File 'lib/less/engine/nodes/property.rb', line 88
def parent
@parent
end
|
Instance Method Details
97
|
# File 'lib/less/engine/nodes/property.rb', line 97
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/less/engine/nodes/property.rb', line 129
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
95
|
# File 'lib/less/engine/nodes/property.rb', line 95
def expressions; select {|i| i.kind_of? Expression } end
|
105
106
107
|
# File 'lib/less/engine/nodes/property.rb', line 105
def inspect
'[' + map {|i| i.inspect }.join(', ') + ']'
end
|
98
|
# File 'lib/less/engine/nodes/property.rb', line 98
def literals; select {|i| i.kind_of? Literal } end
|
#operators ⇒ Object
96
|
# File 'lib/less/engine/nodes/property.rb', line 96
def operators; select {|i| i.is_a? Operator } end
|
#terminal? ⇒ Boolean
109
110
111
|
# File 'lib/less/engine/nodes/property.rb', line 109
def terminal?
expressions.empty?
end
|
113
114
115
116
117
|
# File 'lib/less/engine/nodes/property.rb', line 113
def to_css
map do |i|
i.respond_to?(:to_css) ? i.to_css : i.to_s
end * ' '
end
|
119
120
121
122
123
|
# File 'lib/less/engine/nodes/property.rb', line 119
def to_ruby
map do |i|
i.respond_to?(:to_ruby) ? i.to_ruby : i.to_s
end
end
|