Module: Less::Functions

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

Instance Method Summary collapse

Instance Method Details

#hsl(*args) ⇒ Object



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

def hsl *args
  hsla args, 1.0
end

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



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

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



3
4
5
# File 'lib/less/engine/nodes/function.rb', line 3

def rgb *rgb
  rgba rgb, 1.0
end

#rgba(*rgba) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/less/engine/nodes/function.rb', line 11

def rgba *rgba
  r, g, b, a = rgba.flatten
  hex = [r, g, b].inject("") do |str, c|
    c = c.to_i.to_s(16)
    c = '0' + c if c.length < 2
    str + c
  end
  Node::Color.new hex, a
end