Class: Less::Node::Property

Inherits:
String 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

Methods inherited from String

#blank?, #column_of, #indent, #line_of, #tabto, #treetop_camelize

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
# 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 }
  elsif value.nil?
    []
  else
    value
  end
  
  @value = Expression.new(value, self)
  @eval = false # Store the first evaluation in here
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



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

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



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#eval?Boolean

Returns:

  • (Boolean)


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

def eval?;  @eval end

#evaluateObject

TODO: @eval and @value should be merged



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

def evaluate    
  @eval ||= value.evaluate
end

#inspectObject



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

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

#nearest(node) ⇒ Object



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

def nearest node
  parent.nearest node
end

#to_cssObject



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

def to_css
  "#{self}: #{evaluate.to_css};"
end

#to_sObject



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

def to_s
  super
end