Guest User

Untitled

a guest
Jan 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. # Custom Sass function
  2.  
  3. module Sass::Script::Functions
  4. def format_color(color, format)
  5. assert_type color, :Color
  6. assert_type format, :String
  7. result = case format.value
  8. when 'hsla'
  9. "hsla(%d, %d%%, %d%%, %f)" % (color.hsl + [color.alpha])
  10. when 'hsl'
  11. "hsl(%d, %d%%, %d%%)" % color.hsl
  12. when 'rgba'
  13. "rgba(%d, %d, %d, %f)" % (color.rgb + [color.alpha])
  14. when 'rgb'
  15. "rgb(%d, %d, %d)" % color.rgb
  16. when 'hex' # really just rgb
  17. "#%s" % color.rgb.map { |c| c.to_s(16) }.join('')
  18. end
  19. Sass::Script::String.new(result)
  20. end
  21. declare :format_color, :args => [:string]
  22. end
Add Comment
Please, Sign In to add comment