haml-edge 2.3.82 → 2.3.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/EDGE_GEM_VERSION +1 -1
- data/VERSION +1 -1
- data/lib/sass/script/color.rb +45 -11
- data/lib/sass/script/funcall.rb +3 -2
- data/lib/sass/script/functions.rb +144 -9
- data/test/sass/functions_test.rb +100 -0
- data/test/sass/script_test.rb +38 -0
- metadata +2 -2
data/EDGE_GEM_VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.3.
|
|
1
|
+
2.3.83
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.3.
|
|
1
|
+
2.3.83
|
data/lib/sass/script/color.rb
CHANGED
|
@@ -27,6 +27,30 @@ module Sass::Script
|
|
|
27
27
|
# A hash from [red, green, blue] value arrays to color names.
|
|
28
28
|
HTML4_COLORS_REVERSE = map_hash(HTML4_COLORS) {|k, v| [v, k]}
|
|
29
29
|
|
|
30
|
+
# Constructs an RGB or RGBA color object.
|
|
31
|
+
# The RGB values must be between 0 and 255,
|
|
32
|
+
# and the alpha value is generally expected to be between 0 and 1.
|
|
33
|
+
# However, the alpha value can be greater than 1
|
|
34
|
+
# in order to allow it to be used for color multiplication.
|
|
35
|
+
#
|
|
36
|
+
# @param rgba [Array<Numeric>] A three-element array of the red, green, blue,
|
|
37
|
+
# and optionally alpha values (respectively) of the color
|
|
38
|
+
# @raise [Sass::SyntaxError] if any color value isn't between 0 and 255,
|
|
39
|
+
# or the alpha value is negative
|
|
40
|
+
def initialize(rgba)
|
|
41
|
+
@red, @green, @blue = rgba[0...3].map {|c| c.to_i}
|
|
42
|
+
@alpha = rgba[3] ? rgba[3].to_f : 1
|
|
43
|
+
super(nil)
|
|
44
|
+
|
|
45
|
+
unless rgb.all? {|c| (0..255).include?(c)}
|
|
46
|
+
raise Sass::SyntaxError.new("Color values must be between 0 and 255")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
unless (0..1).include?(alpha)
|
|
50
|
+
raise Sass::SyntaxError.new("Color opacity value must between 0 and 1")
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
30
54
|
# The red component of the color.
|
|
31
55
|
#
|
|
32
56
|
# @return [Fixnum]
|
|
@@ -42,16 +66,18 @@ module Sass::Script
|
|
|
42
66
|
# @return [Fixnum]
|
|
43
67
|
attr_reader :blue
|
|
44
68
|
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
#
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
69
|
+
# The alpha channel (opacity) of the color.
|
|
70
|
+
# This is 1 unless otherwise defined.
|
|
71
|
+
#
|
|
72
|
+
# @return [Fixnum]
|
|
73
|
+
attr_accessor :alpha
|
|
74
|
+
|
|
75
|
+
# Returns whether this color object is translucent;
|
|
76
|
+
# that is, whether the alpha channel is non-1.
|
|
77
|
+
#
|
|
78
|
+
# @return [Boolean]
|
|
79
|
+
def alpha?
|
|
80
|
+
alpha < 1
|
|
55
81
|
end
|
|
56
82
|
|
|
57
83
|
# @deprecated This will be removed in version 2.6.
|
|
@@ -81,7 +107,8 @@ END
|
|
|
81
107
|
# @return [Bool] True if this literal is the same as the other,
|
|
82
108
|
# false otherwise
|
|
83
109
|
def eq(other)
|
|
84
|
-
Sass::Script::Bool.new(
|
|
110
|
+
Sass::Script::Bool.new(
|
|
111
|
+
other.is_a?(Color) && rgb == other.rgb && alpha == other.alpha)
|
|
85
112
|
end
|
|
86
113
|
|
|
87
114
|
# The SassScript `+` operation.
|
|
@@ -205,6 +232,7 @@ END
|
|
|
205
232
|
#
|
|
206
233
|
# @return [String] The string representation
|
|
207
234
|
def to_s
|
|
235
|
+
return "rgba(#{rgb.join(', ')}, #{alpha % 1 == 0.0 ? alpha.to_i : alpha})" if alpha?
|
|
208
236
|
return HTML4_COLORS_REVERSE[rgb] if HTML4_COLORS_REVERSE[rgb]
|
|
209
237
|
red, green, blue = rgb.map { |num| num.to_s(16).rjust(2, '0') }
|
|
210
238
|
"##{red}#{green}#{blue}"
|
|
@@ -224,6 +252,12 @@ END
|
|
|
224
252
|
res = rgb[i].send(operation, other_num ? other.value : other.rgb[i])
|
|
225
253
|
result[i] = [ [res, 255].min, 0 ].max
|
|
226
254
|
end
|
|
255
|
+
|
|
256
|
+
if !other_num && other.alpha != alpha
|
|
257
|
+
raise Sass::SyntaxError.new("Alpha channels must be equal: #{self} #{operation} #{other}")
|
|
258
|
+
end
|
|
259
|
+
result[3] = alpha
|
|
260
|
+
|
|
227
261
|
Color.new(result)
|
|
228
262
|
end
|
|
229
263
|
end
|
data/lib/sass/script/funcall.rb
CHANGED
|
@@ -36,11 +36,12 @@ module Sass
|
|
|
36
36
|
# @raise [Sass::SyntaxError] if the function call raises an ArgumentError
|
|
37
37
|
def perform(environment)
|
|
38
38
|
args = self.args.map {|a| a.perform(environment)}
|
|
39
|
-
|
|
39
|
+
ruby_name = name.gsub('-', '_')
|
|
40
|
+
unless Haml::Util.has?(:public_instance_method, Functions, ruby_name) && ruby_name !~ /^__/
|
|
40
41
|
return Script::String.new("#{name}(#{args.map {|a| a.perform(environment)}.join(', ')})")
|
|
41
42
|
end
|
|
42
43
|
|
|
43
|
-
return Functions::EvaluationContext.new(environment.options).send(
|
|
44
|
+
return Functions::EvaluationContext.new(environment.options).send(ruby_name, *args)
|
|
44
45
|
rescue ArgumentError => e
|
|
45
46
|
raise e unless e.backtrace.any? {|t| t =~ /:in `(block in )?(#{name}|perform)'$/}
|
|
46
47
|
raise Sass::SyntaxError.new("#{e.message} for `#{name}'")
|
|
@@ -11,6 +11,33 @@ module Sass::Script
|
|
|
11
11
|
# \{#hsl}
|
|
12
12
|
# : Converts an `hsl(hue, saturation, lightness)` triplet into a color.
|
|
13
13
|
#
|
|
14
|
+
# \{#hsla}
|
|
15
|
+
# : Converts an `hsla(hue, saturation, lightness, alpha)` quadruplet into a color.
|
|
16
|
+
#
|
|
17
|
+
# \{#rgb}
|
|
18
|
+
# : Converts an `rgb(red, green, blue)` triplet into a color.
|
|
19
|
+
#
|
|
20
|
+
# \{#rgba}
|
|
21
|
+
# : Converts an `rgb(red, green, blue, alpha)` triplet into a color.
|
|
22
|
+
#
|
|
23
|
+
# \{#red}
|
|
24
|
+
# : Gets the red component of a color.
|
|
25
|
+
#
|
|
26
|
+
# \{#green}
|
|
27
|
+
# : Gets the green component of a color.
|
|
28
|
+
#
|
|
29
|
+
# \{#blue}
|
|
30
|
+
# : Gets the blue component of a color.
|
|
31
|
+
#
|
|
32
|
+
# \{#alpha} / \{#opacity}
|
|
33
|
+
# : Gets the alpha component (opacity) of a color.
|
|
34
|
+
#
|
|
35
|
+
# \{#opacify} / \{#fade_in #fade-in}
|
|
36
|
+
# : Makes a color more opaque.
|
|
37
|
+
#
|
|
38
|
+
# \{#transparentize} / \{#fade_out #fade-out}
|
|
39
|
+
# : Makes a color more transparent.
|
|
40
|
+
#
|
|
14
41
|
# \{#percentage}
|
|
15
42
|
# : Converts a unitless number to a percentage.
|
|
16
43
|
#
|
|
@@ -105,19 +132,40 @@ module Sass::Script
|
|
|
105
132
|
# @param blue
|
|
106
133
|
# A number between 0 and 255 inclusive
|
|
107
134
|
def rgb(red, green, blue)
|
|
135
|
+
rgba(red, green, blue, Number.new(1))
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Creates a {Color} object from red, green, and blue values,
|
|
139
|
+
# as well as an alpha channel indicating opacity.
|
|
140
|
+
#
|
|
141
|
+
# @param red
|
|
142
|
+
# A number between 0 and 255 inclusive
|
|
143
|
+
# @param green
|
|
144
|
+
# A number between 0 and 255 inclusive
|
|
145
|
+
# @param blue
|
|
146
|
+
# A number between 0 and 255 inclusive
|
|
147
|
+
# @param alpha
|
|
148
|
+
# A number between 0 and 1
|
|
149
|
+
def rgba(red, green, blue, alpha)
|
|
108
150
|
assert_type red, :Number
|
|
109
151
|
assert_type green, :Number
|
|
110
152
|
assert_type blue, :Number
|
|
153
|
+
assert_type alpha, :Number
|
|
111
154
|
|
|
112
155
|
[red.value, green.value, blue.value].each do |v|
|
|
113
|
-
next
|
|
156
|
+
next if (0..255).include?(v)
|
|
114
157
|
raise ArgumentError.new("Color value #{v} must be between 0 and 255 inclusive")
|
|
115
158
|
end
|
|
116
|
-
|
|
159
|
+
|
|
160
|
+
unless (0..1).include?(alpha.value)
|
|
161
|
+
raise ArgumentError.new("Alpha channel #{alpha.value} must be between 0 and 1 inclusive")
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
Color.new([red.value, green.value, blue.value, alpha.value])
|
|
117
165
|
end
|
|
118
166
|
|
|
119
|
-
# Creates a {Color} object from hue, saturation, and lightness
|
|
120
|
-
#
|
|
167
|
+
# Creates a {Color} object from hue, saturation, and lightness.
|
|
168
|
+
# Uses the algorithm from the [CSS3 spec](http://www.w3.org/TR/css3-color/#hsl-color).
|
|
121
169
|
#
|
|
122
170
|
# @param hue [Number] The hue of the color.
|
|
123
171
|
# Should be between 0 and 360 degrees, inclusive
|
|
@@ -128,16 +176,39 @@ module Sass::Script
|
|
|
128
176
|
# @return [Color] The resulting color
|
|
129
177
|
# @raise [ArgumentError] if `saturation` or `lightness` are out of bounds
|
|
130
178
|
def hsl(hue, saturation, lightness)
|
|
179
|
+
hsla(hue, saturation, lightness, Number.new(1))
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# Creates a {Color} object from hue, saturation, and lightness,
|
|
183
|
+
# as well as an alpha channel indicating opacity.
|
|
184
|
+
# Uses the algorithm from the [CSS3 spec](http://www.w3.org/TR/css3-color/#hsl-color).
|
|
185
|
+
#
|
|
186
|
+
# @param hue [Number] The hue of the color.
|
|
187
|
+
# Should be between 0 and 360 degrees, inclusive
|
|
188
|
+
# @param saturation [Number] The saturation of the color.
|
|
189
|
+
# Must be between `0%` and `100%`, inclusive
|
|
190
|
+
# @param lightness [Number] The lightness of the color.
|
|
191
|
+
# Must be between `0%` and `100%`, inclusive
|
|
192
|
+
# @param alpha [Number] The opacity of the color.
|
|
193
|
+
# Must be between 0 and 1, inclusive
|
|
194
|
+
# @return [Color] The resulting color
|
|
195
|
+
# @raise [ArgumentError] if `saturation`, `lightness`, or `alpha` are out of bounds
|
|
196
|
+
def hsla(hue, saturation, lightness, alpha)
|
|
131
197
|
assert_type hue, :Number
|
|
132
198
|
assert_type saturation, :Number
|
|
133
199
|
assert_type lightness, :Number
|
|
200
|
+
assert_type alpha, :Number
|
|
201
|
+
|
|
202
|
+
unless (0..1).include?(alpha.value)
|
|
203
|
+
raise ArgumentError.new("Alpha channel #{alpha.value} must be between 0 and 1")
|
|
204
|
+
end
|
|
134
205
|
|
|
135
206
|
original_s = saturation
|
|
136
207
|
original_l = lightness
|
|
137
208
|
# This algorithm is from http://www.w3.org/TR/css3-color#hsl-color
|
|
138
209
|
h, s, l = [hue, saturation, lightness].map { |a| a.value }
|
|
139
|
-
raise ArgumentError.new("Saturation #{s} must be between 0% and 100%")
|
|
140
|
-
raise ArgumentError.new("Lightness #{l} must be between 0% and 100%")
|
|
210
|
+
raise ArgumentError.new("Saturation #{s} must be between 0% and 100%") unless (0..100).include?(s)
|
|
211
|
+
raise ArgumentError.new("Lightness #{l} must be between 0% and 100%") unless (0..100).include?(l)
|
|
141
212
|
|
|
142
213
|
h = (h % 360) / 360.0
|
|
143
214
|
s /= 100.0
|
|
@@ -145,9 +216,11 @@ module Sass::Script
|
|
|
145
216
|
|
|
146
217
|
m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s
|
|
147
218
|
m1 = l * 2 - m2
|
|
148
|
-
Color.new(
|
|
149
|
-
|
|
150
|
-
|
|
219
|
+
Color.new(
|
|
220
|
+
[hue_to_rgb(m1, m2, h + 1.0/3),
|
|
221
|
+
hue_to_rgb(m1, m2, h),
|
|
222
|
+
hue_to_rgb(m1, m2, h - 1.0/3)].map { |c| (c * 0xff).round } +
|
|
223
|
+
[alpha.value])
|
|
151
224
|
end
|
|
152
225
|
|
|
153
226
|
# Returns the red component of a color.
|
|
@@ -180,6 +253,68 @@ module Sass::Script
|
|
|
180
253
|
Sass::Script::Number.new(color.blue)
|
|
181
254
|
end
|
|
182
255
|
|
|
256
|
+
# Returns the alpha component (opacity) of a color.
|
|
257
|
+
# This is 1 unless otherwise specified.
|
|
258
|
+
#
|
|
259
|
+
# @param color [Color]
|
|
260
|
+
# @return [Number]
|
|
261
|
+
# @raise [ArgumentError] If `color` isn't a color
|
|
262
|
+
def alpha(color)
|
|
263
|
+
assert_type color, :Color
|
|
264
|
+
Sass::Script::Number.new(color.alpha)
|
|
265
|
+
end
|
|
266
|
+
alias_method :opacity, :alpha
|
|
267
|
+
|
|
268
|
+
# Makes a color more opaque.
|
|
269
|
+
# Takes a color and an amount between `0%` and `100%`
|
|
270
|
+
# and returns a color that's that much closer to opaque.
|
|
271
|
+
#
|
|
272
|
+
# For example, `50%` will make the color twice as opaque:
|
|
273
|
+
#
|
|
274
|
+
# opacify(rgba(0, 0, 0, 0.5), 50%) => rgba(0, 0, 0, 0.75)
|
|
275
|
+
# opacify(rgba(0, 0, 0, 0.8), 50%) => rgba(0, 0, 0, 0.9)
|
|
276
|
+
# opacify(rgba(0, 0, 0, 0.2), 50%) => rgba(0, 0, 0, 0.8)
|
|
277
|
+
#
|
|
278
|
+
# Specifically, `opacify(color, n%)` will make the color
|
|
279
|
+
# `n%` closer to fully opaque.
|
|
280
|
+
def opacify(color, amount)
|
|
281
|
+
assert_type color, :Color
|
|
282
|
+
assert_type amount, :Number
|
|
283
|
+
unless (0..100).include?(amount.value)
|
|
284
|
+
raise ArgumentError.new("Amount #{amount} must be between 0% and 100%")
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
color = color.dup
|
|
288
|
+
color.alpha += (1 - color.alpha) * (amount.value / 100.0)
|
|
289
|
+
color
|
|
290
|
+
end
|
|
291
|
+
alias_method :fade_in, :opacify
|
|
292
|
+
|
|
293
|
+
# Makes a color more transparent.
|
|
294
|
+
# Takes a color and an amount between `0%` and `100%`
|
|
295
|
+
# and returns a color that's that much closer to transparent.
|
|
296
|
+
#
|
|
297
|
+
# For example, `50%` will make the color twice as transparent:
|
|
298
|
+
#
|
|
299
|
+
# opacify(rgba(0, 0, 0, 0.5), 50%) => rgba(0, 0, 0, 0.25)
|
|
300
|
+
# opacify(rgba(0, 0, 0, 0.8), 50%) => rgba(0, 0, 0, 0.4)
|
|
301
|
+
# opacify(rgba(0, 0, 0, 0.2), 50%) => rgba(0, 0, 0, 0.1)
|
|
302
|
+
#
|
|
303
|
+
# Specifically, `transparentize(color, n%)` will make the color
|
|
304
|
+
# `n%` closer to fully transparent.
|
|
305
|
+
def transparentize(color, amount)
|
|
306
|
+
assert_type color, :Color
|
|
307
|
+
assert_type amount, :Number
|
|
308
|
+
unless (0..100).include?(amount.value)
|
|
309
|
+
raise ArgumentError.new("Amount #{amount} must be between 0% and 100%")
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
color = color.dup
|
|
313
|
+
color.alpha *= 1 - (amount.value / 100.0)
|
|
314
|
+
color
|
|
315
|
+
end
|
|
316
|
+
alias_method :fade_out, :transparentize
|
|
317
|
+
|
|
183
318
|
# Converts a decimal number to a percentage.
|
|
184
319
|
# For example:
|
|
185
320
|
#
|
data/test/sass/functions_test.rb
CHANGED
|
@@ -27,6 +27,26 @@ class SassFunctionTest < Test::Unit::TestCase
|
|
|
27
27
|
assert_error_message("\"foo\" is not a number for `hsl'", "hsl(10, 10, \"foo\")");
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
def test_hsla
|
|
31
|
+
assert_equal "rgba(51, 204, 204, 0.4)", evaluate("hsla(180, 60%, 50%, 0.4)")
|
|
32
|
+
assert_equal "#33cccc", evaluate("hsla(180, 60%, 50%, 1)")
|
|
33
|
+
assert_equal "rgba(51, 204, 204, 0)", evaluate("hsla(180, 60%, 50%, 0)")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_hsla_checks_bounds
|
|
37
|
+
assert_error_message("Saturation -114 must be between 0% and 100% for `hsla'", "hsla(10, -114, 12, 1)");
|
|
38
|
+
assert_error_message("Lightness 256 must be between 0% and 100% for `hsla'", "hsla(10, 10, 256%, 0)");
|
|
39
|
+
assert_error_message("Alpha channel -0.1 must be between 0 and 1 for `hsla'", "hsla(10, 10, 10, -0.1)");
|
|
40
|
+
assert_error_message("Alpha channel 1.1 must be between 0 and 1 for `hsla'", "hsla(10, 10, 10, 1.1)");
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_hsla_checks_types
|
|
44
|
+
assert_error_message("\"foo\" is not a number for `hsla'", "hsla(\"foo\", 10, 12, 0.3)");
|
|
45
|
+
assert_error_message("\"foo\" is not a number for `hsla'", "hsla(10, \"foo\", 12, 0)");
|
|
46
|
+
assert_error_message("\"foo\" is not a number for `hsla'", "hsla(10, 10, \"foo\", 1)");
|
|
47
|
+
assert_error_message("\"foo\" is not a number for `hsla'", "hsla(10, 10, 10, \"foo\")");
|
|
48
|
+
end
|
|
49
|
+
|
|
30
50
|
def test_percentage
|
|
31
51
|
assert_equal("50%", evaluate("percentage(.5)"))
|
|
32
52
|
assert_equal("100%", evaluate("percentage(1)"))
|
|
@@ -95,6 +115,36 @@ class SassFunctionTest < Test::Unit::TestCase
|
|
|
95
115
|
assert_error_message("\"foo\" is not a number for `rgb'", "rgb(10, 10, \"foo\")");
|
|
96
116
|
end
|
|
97
117
|
|
|
118
|
+
def test_rgba
|
|
119
|
+
assert_equal("rgba(18, 52, 86, 0.5)", evaluate("rgba(18, 52, 86, 0.5)"))
|
|
120
|
+
assert_equal("#beaded", evaluate("rgba(190, 173, 237, 1)"))
|
|
121
|
+
assert_equal("rgba(0, 255, 127, 0)", evaluate("rgba(0, 255, 127, 0)"))
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def test_rgb_tests_bounds
|
|
125
|
+
assert_error_message("Color value 256 must be between 0 and 255 inclusive for `rgba'",
|
|
126
|
+
"rgba(256, 1, 1, 0.3)")
|
|
127
|
+
assert_error_message("Color value 256 must be between 0 and 255 inclusive for `rgba'",
|
|
128
|
+
"rgba(1, 256, 1, 0.3)")
|
|
129
|
+
assert_error_message("Color value 256 must be between 0 and 255 inclusive for `rgba'",
|
|
130
|
+
"rgba(1, 1, 256, 0.3)")
|
|
131
|
+
assert_error_message("Color value 256 must be between 0 and 255 inclusive for `rgba'",
|
|
132
|
+
"rgba(1, 256, 257, 0.3)")
|
|
133
|
+
assert_error_message("Color value -1 must be between 0 and 255 inclusive for `rgba'",
|
|
134
|
+
"rgba(-1, 1, 1, 0.3)")
|
|
135
|
+
assert_error_message("Alpha channel -0.2 must be between 0 and 1 inclusive for `rgba'",
|
|
136
|
+
"rgba(1, 1, 1, -0.2)")
|
|
137
|
+
assert_error_message("Alpha channel 1.2 must be between 0 and 1 inclusive for `rgba'",
|
|
138
|
+
"rgba(1, 1, 1, 1.2)")
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_rgba_tests_types
|
|
142
|
+
assert_error_message("\"foo\" is not a number for `rgba'", "rgba(\"foo\", 10, 12, 0.2)");
|
|
143
|
+
assert_error_message("\"foo\" is not a number for `rgba'", "rgba(10, \"foo\", 12, 0.1)");
|
|
144
|
+
assert_error_message("\"foo\" is not a number for `rgba'", "rgba(10, 10, \"foo\", 0)");
|
|
145
|
+
assert_error_message("\"foo\" is not a number for `rgba'", "rgba(10, 10, 10, \"foo\")");
|
|
146
|
+
end
|
|
147
|
+
|
|
98
148
|
def test_red
|
|
99
149
|
assert_equal("18", evaluate("red(#123456)"))
|
|
100
150
|
end
|
|
@@ -119,6 +169,56 @@ class SassFunctionTest < Test::Unit::TestCase
|
|
|
119
169
|
assert_error_message("12 is not a color for `blue'", "blue(12)")
|
|
120
170
|
end
|
|
121
171
|
|
|
172
|
+
def test_alpha
|
|
173
|
+
assert_equal("1", evaluate("alpha(#123456)"))
|
|
174
|
+
assert_equal("0.34", evaluate("alpha(rgba(0, 1, 2, 0.34))"))
|
|
175
|
+
assert_equal("0", evaluate("alpha(hsla(0, 1, 2, 0))"))
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def test_alpha_exception
|
|
179
|
+
assert_error_message("12 is not a color for `alpha'", "alpha(12)")
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def test_opacify
|
|
183
|
+
assert_equal("rgba(0, 0, 0, 0.75)", evaluate("opacify(rgba(0, 0, 0, 0.5), 50%)"))
|
|
184
|
+
assert_equal("rgba(0, 0, 0, 0.8)", evaluate("opacify(rgba(0, 0, 0, 0.2), 75)"))
|
|
185
|
+
assert_equal("rgba(0, 0, 0, 0.28)", evaluate("fade-in(rgba(0, 0, 0, 0.2), 10px)"))
|
|
186
|
+
assert_equal("black", evaluate("fade_in(rgba(0, 0, 0, 0.2), 100%)"))
|
|
187
|
+
assert_equal("rgba(0, 0, 0, 0.2)", evaluate("opacify(rgba(0, 0, 0, 0.2), 0%)"))
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def test_opacify_tests_bounds
|
|
191
|
+
assert_error_message("Amount -3012% must be between 0% and 100% for `opacify'",
|
|
192
|
+
"opacify(rgba(0, 0, 0, 0.2), -3012%)")
|
|
193
|
+
assert_error_message("Amount 101 must be between 0% and 100% for `opacify'",
|
|
194
|
+
"opacify(rgba(0, 0, 0, 0.2), 101)")
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def test_opacify_tests_types
|
|
198
|
+
assert_error_message("\"foo\" is not a color for `opacify'", "opacify(\"foo\", 10%)")
|
|
199
|
+
assert_error_message("\"foo\" is not a number for `opacify'", "opacify(#fff, \"foo\")")
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def test_transparentize
|
|
203
|
+
assert_equal("rgba(0, 0, 0, 0.25)", evaluate("transparentize(rgba(0, 0, 0, 0.5), 50%)"))
|
|
204
|
+
assert_equal("rgba(0, 0, 0, 0.05)", evaluate("transparentize(rgba(0, 0, 0, 0.2), 75)"))
|
|
205
|
+
assert_equal("rgba(0, 0, 0, 0.18)", evaluate("fade-out(rgba(0, 0, 0, 0.2), 10px)"))
|
|
206
|
+
assert_equal("rgba(0, 0, 0, 0)", evaluate("fade_out(rgba(0, 0, 0, 0.2), 100%)"))
|
|
207
|
+
assert_equal("rgba(0, 0, 0, 0.2)", evaluate("transparentize(rgba(0, 0, 0, 0.2), 0%)"))
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def test_transparentize_tests_bounds
|
|
211
|
+
assert_error_message("Amount -3012% must be between 0% and 100% for `transparentize'",
|
|
212
|
+
"transparentize(rgba(0, 0, 0, 0.2), -3012%)")
|
|
213
|
+
assert_error_message("Amount 101 must be between 0% and 100% for `transparentize'",
|
|
214
|
+
"transparentize(rgba(0, 0, 0, 0.2), 101)")
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def test_transparentize_tests_types
|
|
218
|
+
assert_error_message("\"foo\" is not a color for `transparentize'", "transparentize(\"foo\", 10%)")
|
|
219
|
+
assert_error_message("\"foo\" is not a number for `transparentize'", "transparentize(#fff, \"foo\")")
|
|
220
|
+
end
|
|
221
|
+
|
|
122
222
|
private
|
|
123
223
|
|
|
124
224
|
def evaluate(value)
|
data/test/sass/script_test.rb
CHANGED
|
@@ -10,6 +10,11 @@ class SassScriptTest < Test::Unit::TestCase
|
|
|
10
10
|
assert_raise(Sass::SyntaxError, "Color values must be between 0 and 255") {Color.new([256, 2, 3])}
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
def test_color_checks_rgba_input
|
|
14
|
+
assert_raise(Sass::SyntaxError, "Alpha channel must be between 0 and 1") {Color.new([1, 2, 3, 1.1])}
|
|
15
|
+
assert_raise(Sass::SyntaxError, "Alpha channel must be between 0 and 1") {Color.new([1, 2, 3, -0.1])}
|
|
16
|
+
end
|
|
17
|
+
|
|
13
18
|
def test_string_escapes
|
|
14
19
|
assert_equal '"', resolve("\"\\\"\"")
|
|
15
20
|
assert_equal "\\", resolve("\"\\\\\"")
|
|
@@ -22,6 +27,39 @@ class SassScriptTest < Test::Unit::TestCase
|
|
|
22
27
|
assert_equal "#fffffe", resolve("white - #000001")
|
|
23
28
|
end
|
|
24
29
|
|
|
30
|
+
def test_rgba_color_literals
|
|
31
|
+
assert_equal Sass::Script::Color.new([1, 2, 3, 0.75]), eval("rgba(1, 2, 3, 0.75)")
|
|
32
|
+
assert_equal "rgba(1, 2, 3, 0.75)", resolve("rgba(1, 2, 3, 0.75)")
|
|
33
|
+
|
|
34
|
+
assert_equal Sass::Script::Color.new([1, 2, 3, 0]), eval("rgba(1, 2, 3, 0)")
|
|
35
|
+
assert_equal "rgba(1, 2, 3, 0)", resolve("rgba(1, 2, 3, 0)")
|
|
36
|
+
|
|
37
|
+
assert_equal Sass::Script::Color.new([1, 2, 3]), eval("rgba(1, 2, 3, 1)")
|
|
38
|
+
assert_equal Sass::Script::Color.new([1, 2, 3, 1]), eval("rgba(1, 2, 3, 1)")
|
|
39
|
+
assert_equal "#010203", resolve("rgba(1, 2, 3, 1)")
|
|
40
|
+
assert_equal "white", resolve("rgba(255, 255, 255, 1)")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_rgba_color_math
|
|
44
|
+
assert_equal "rgba(50, 50, 100, 0.35)", resolve("rgba(1, 1, 2, 0.35) * rgba(50, 50, 50, 0.35)")
|
|
45
|
+
assert_equal "rgba(52, 52, 52, 0.25)", resolve("rgba(2, 2, 2, 0.25) + rgba(50, 50, 50, 0.25)")
|
|
46
|
+
|
|
47
|
+
assert_raise(Sass::SyntaxError, "Alpha channels must be equal: rgba(1, 2, 3, 0.15) + rgba(50, 50, 50, 0.75)") do
|
|
48
|
+
resolve("rgba(1, 2, 3, 0.15) + rgba(50, 50, 50, 0.75)")
|
|
49
|
+
end
|
|
50
|
+
assert_raise(Sass::SyntaxError, "Alpha channels must be equal: #123456 * rgba(50, 50, 50, 0.75)") do
|
|
51
|
+
resolve("#123456 * rgba(50, 50, 50, 0.75)")
|
|
52
|
+
end
|
|
53
|
+
assert_raise(Sass::SyntaxError, "Alpha channels must be equal: #123456 / #123456") do
|
|
54
|
+
resolve("rgba(50, 50, 50, 0.75) / #123456")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_rgba_number_math
|
|
59
|
+
assert_equal "rgba(49, 49, 49, 0.75)", resolve("rgba(50, 50, 50, 0.75) - 1")
|
|
60
|
+
assert_equal "rgba(100, 100, 100, 0.75)", resolve("rgba(50, 50, 50, 0.75) * 2")
|
|
61
|
+
end
|
|
62
|
+
|
|
25
63
|
def test_implicit_strings
|
|
26
64
|
silence_warnings do
|
|
27
65
|
assert_equal Sass::Script::String.new("foo"), eval("foo")
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: haml-edge
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.3.
|
|
4
|
+
version: 2.3.83
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan Weizenbaum
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2009-11-
|
|
13
|
+
date: 2009-11-12 00:00:00 -05:00
|
|
14
14
|
default_executable:
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|