Class: Less::Node::Property

Inherits:
String
  • Object
show all
Includes:
Entity
Defined in:
lib/less/engine/nodes/property.rb

Direct Known Subclasses

Variable

Instance Attribute Summary collapse

Attributes included from Entity

#parent

Instance Method Summary collapse

Methods included from Entity

#path, #root

Constructor Details

#initialize(key, value = nil, parent = nil) ⇒ Property

Returns a new instance of Property.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/less/engine/nodes/property.rb', line 8

def initialize key, value = nil, parent = nil
  super key, parent
  value = if value.is_a? Array
    value.each {|v| v.parent = self if v.respond_to? :parent }.
          map  {|v| v.is_a?(Expression) ? v : Expression.new(v, self) }
  elsif value.nil?
    []
  else
    value
  end
  @value = value.is_a?(Expression) ? value : Expression.new(value, self)
  @value.parent = self
  @value.delimiter = ','
#        puts "new property #{to_s}: #{value} => #{@value}, contains: #{@value[0].class}"
#        puts
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/less/engine/nodes/property.rb', line 6

def value
  @value
end

Instance Method Details

#<<(token) ⇒ Object



36
37
38
39
40
# File 'lib/less/engine/nodes/property.rb', line 36

def << token
  token = Node::Anonymous.new(*token) unless token.is_a? Entity or token.respond_to? :to_ruby
  token.parent = self if token.respond_to? :parent
  @value << token
end

#==(other) ⇒ Object



48
49
50
# File 'lib/less/engine/nodes/property.rb', line 48

def == other
  self.to_s == other.to_s
end

#copyObject



30
31
32
33
34
# File 'lib/less/engine/nodes/property.rb', line 30

def copy
  ret = clone
  ret.value = value.copy
  ret
end

#empty?Boolean

Returns:

  • (Boolean)


42
# File 'lib/less/engine/nodes/property.rb', line 42

def empty?; !@value || @value.empty? end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/less/engine/nodes/property.rb', line 52

def eql? other
  self == other and value.eql? other.value
end

#evaluate(env = nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/less/engine/nodes/property.rb', line 64

def evaluate env = nil
#        puts "evaluating property `#{to_s}`: #{value.inspect}"
  if value.is_a?(Expression) #Value
#          puts "value is a Value"
    value.map {|e| e.evaluate(env) } #6
  else
#          puts "value is a #{value.class}"
    [value.evaluate(env)]
  end


end

#inspectObject



44
45
46
# File 'lib/less/engine/nodes/property.rb', line 44

def inspect
  self + (empty?? "" : ": `#{value.map {|i| i.to_s } * ' | '}`")
end

#nearest(node) ⇒ Object



60
61
62
# File 'lib/less/engine/nodes/property.rb', line 60

def nearest node
  parent.nearest node
end

#parent=(obj) ⇒ Object



25
26
27
28
# File 'lib/less/engine/nodes/property.rb', line 25

def parent= obj
  @parent = obj
  value.parent = self
end

#to_css(env = nil) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/less/engine/nodes/property.rb', line 77

def to_css env = nil
#        puts "property.to_css `#{to_s}` env:#{env ? env.variables : "nil"}"
  val = evaluate(env)
  "#{self}: #{if val.respond_to? :to_css
      val.to_css
    else
#            p val
#            puts "#{val.class} #{val.first.class}"
      val.map {|i| i.to_css }.join(", ")
    end};"
end

#to_sObject



56
57
58
# File 'lib/less/engine/nodes/property.rb', line 56

def to_s
  super
end