Sha256: b8db07ab65a89fa469f38e318eaad39d369caa49e6dc3f6cd30a4f2de565184f
Contents?: true
Size: 1.46 KB
Versions: 16
Compression:
Stored size: 1.46 KB
Contents
module Less # # Functions useable from within the style-sheet go here # module Functions def rgb *rgb rgba rgb, 1.0 end def hsl *args hsla args, 1.0 end # # RGBA to Node::Color # def rgba *rgba Node::Color.new *rgba end # # HSLA to RGBA # 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 end module Node # # A CSS function, like rgb() or url() # # it calls functions from the Functions module # class Function < ::String include Functions include Entity def initialize name, *args @args = args.flatten super name end def to_css self.evaluate.to_css end # # Call the function # def evaluate send self.to_sym, *@args end # # If the function isn't found, we just print it out, # this is the case for url(), for example, # def method_missing meth, *args Node::Anonymous.new("#{meth}(#{args.map(&:to_css) * ', '})") end end end end
Version data entries
16 entries across 16 versions & 2 rubygems