Class: Less::Node::Property
- Inherits:
-
String
- Object
- String
- Less::Node::Property
- Includes:
- Entity
- Defined in:
- lib/less/engine/nodes/property.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Attributes included from Entity
Instance Method Summary collapse
- #<<(token) ⇒ Object
- #==(other) ⇒ Object
- #copy ⇒ Object
- #empty? ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #evaluate(env = nil) ⇒ Object
-
#initialize(key, value = nil, parent = nil) ⇒ Property
constructor
A new instance of Property.
- #inspect ⇒ Object
- #nearest(node) ⇒ Object
- #parent=(obj) ⇒ Object
- #to_css(env = nil) ⇒ Object
- #to_s ⇒ Object
Methods included from Entity
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
#value ⇒ Object
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 |
#copy ⇒ Object
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
42 |
# File 'lib/less/engine/nodes/property.rb', line 42 def empty?; !@value || @value.empty? end |
#eql?(other) ⇒ 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 |
#inspect ⇒ Object
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_s ⇒ Object
56 57 58 |
# File 'lib/less/engine/nodes/property.rb', line 56 def to_s super end |