Class: Less::Node::Function
- Inherits:
-
String
- Object
- String
- Less::Node::Function
- Defined in:
- lib/less/engine/nodes/function.rb
Overview
A CSS function, like rgb() or url()
it calls functions from the Functions module
Instance Attribute Summary
Attributes included from Entity
Instance Method Summary collapse
-
#evaluate(context = nil) ⇒ Object
Call the function.
-
#initialize(name, args) ⇒ Function
constructor
A new instance of Function.
- #nearest(node) ⇒ Object
- #to_css(env = nil) ⇒ Object
Methods included from Functions
available, #hsl, #hsla, #rgb, #rgba
Methods included from Entity
Constructor Details
#initialize(name, args) ⇒ Function
Returns a new instance of Function.
55 56 57 58 59 60 61 62 63 |
# File 'lib/less/engine/nodes/function.rb', line 55 def initialize name, args @args = if args.is_a? Array args.map {|e| e.is_a?(Expression) ? e : Expression.new(e, self)} else [args] end super name end |
Instance Method Details
#evaluate(context = nil) ⇒ Object
Call the function
If the function isn’t found, we just print it out, this is the case for url(), for example,
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/less/engine/nodes/function.rb', line 79 def evaluate context = nil if Functions.available.include? self.to_sym send to_sym, *@args else args = @args.map { |e| e.parent = self.parent e = e.evaluate(context) if e.respond_to?(:evaluate) e.to_css } * ', ' Node::Anonymous.new("#{to_sym}(#{args})") end end |
#nearest(node) ⇒ Object
69 70 71 |
# File 'lib/less/engine/nodes/function.rb', line 69 def nearest node parent.nearest node end |
#to_css(env = nil) ⇒ Object
65 66 67 |
# File 'lib/less/engine/nodes/function.rb', line 65 def to_css env = nil self.evaluate(env).to_css end |