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



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

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



46
47
48
# File 'lib/less/engine/nodes/property.rb', line 46

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

#copyObject



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

def copy
  clone.tap {|c| c.value = value.copy }
end

#empty?Boolean

Returns:

  • (Boolean)


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

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/less/engine/nodes/property.rb', line 50

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

#evaluate(env = nil) ⇒ Object



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

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



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

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

#nearest(node) ⇒ Object



58
59
60
# File 'lib/less/engine/nodes/property.rb', line 58

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



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

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



54
55
56
# File 'lib/less/engine/nodes/property.rb', line 54

def to_s
  super
end