mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Add #red, #green, and #blue accessors for Script::Color.
This commit is contained in:
parent
51514c83d0
commit
6098d2345f
1 changed files with 31 additions and 2 deletions
|
@ -27,13 +27,31 @@ module Sass::Script
|
|||
# A hash from [red, green, blue] value arrays to color names.
|
||||
HTML4_COLORS_REVERSE = map_hash(HTML4_COLORS) {|k, v| [v, k]}
|
||||
|
||||
# The red component of the color.
|
||||
#
|
||||
# @return [Fixnum]
|
||||
attr_reader :red
|
||||
|
||||
# The green component of the color.
|
||||
#
|
||||
# @return [Fixnum]
|
||||
attr_reader :green
|
||||
|
||||
# The blue component of the color.
|
||||
#
|
||||
# @return [Fixnum]
|
||||
attr_reader :blue
|
||||
|
||||
# @param rgb [Array<Fixnum>] A three-element array of the red, green, and blue values (respectively)
|
||||
# of the color
|
||||
# @raise [Sass::SyntaxError] if any color value isn't between 0 and 255
|
||||
def initialize(rgb)
|
||||
rgb = rgb.map {|c| c.to_i}
|
||||
raise Sass::SyntaxError.new("Color values must be between 0 and 255") if rgb.any? {|c| c < 0 || c > 255}
|
||||
super(rgb)
|
||||
@red = rgb[0]
|
||||
@green = rgb[1]
|
||||
@blue = rgb[2]
|
||||
super(nil)
|
||||
end
|
||||
|
||||
# @deprecated This will be removed in version 2.6.
|
||||
|
@ -52,7 +70,18 @@ END
|
|||
# @return [Array<Fixnum>] A three-element array of the red, green, and blue
|
||||
# values (respectively) of the color
|
||||
def rgb
|
||||
@value
|
||||
[red, green, blue]
|
||||
end
|
||||
|
||||
# The SassScript `==` operation.
|
||||
# **Note that this returns a {Sass::Script::Bool} object,
|
||||
# not a Ruby boolean**.
|
||||
#
|
||||
# @param other [Literal] The right-hand side of the operator
|
||||
# @return [Bool] True if this literal is the same as the other,
|
||||
# false otherwise
|
||||
def eq(other)
|
||||
Sass::Script::Bool.new(other.is_a?(Color) && rgb == other.rgb)
|
||||
end
|
||||
|
||||
# The SassScript `+` operation.
|
||||
|
|
Loading…
Add table
Reference in a new issue