Module: Less::Functions

Included in:
Node::Function
Defined in:
lib/less/engine/nodes/function.rb

Overview

Functions useable from within the style-sheet go here

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.availableObject



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

def self.available
  self.instance_methods.map(&:to_sym)
end

Instance Method Details

#hsl(*args) ⇒ Object



10
11
12
# File 'lib/less/engine/nodes/function.rb', line 10

def hsl *args
  hsla *[args, 1.0].flatten
end

#hsla(h, s, l, a = 1.0) ⇒ Object

HSLA to RGBA



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/less/engine/nodes/function.rb', line 24

def hsla h, s, l, a = 1.0
  m2 = ( l <= 0.5 ) ? l * ( s + 1 ) : l + s - l * s
  m1 = l * 2 - m2;

  hue = lambda do |h|
    h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h)
    if    h * 6 < 1 then m1 + (m2 - m1) * h * 6
    elsif h * 2 < 1 then m2 
    elsif h * 3 < 2 then m1 + (m2 - m1) * (2/3 - h) * 6 
    else m1
    end
  end

  rgba hue[ h + 1/3 ], hue[ h ], hue[ h - 1/3 ], a
end

#rgb(*rgb) ⇒ Object



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

def rgb *rgb
  rgba rgb, 1.0
end

#rgba(*rgba) ⇒ Object

RGBA to Node::Color



17
18
19
# File 'lib/less/engine/nodes/function.rb', line 17

def rgba *rgba
  Node::Color.new *rgba.flatten
end