sass 3.1.0.alpha.15 → 3.1.0.alpha.16

Sign up to get free protection for your applications and to get access to all the features.
data/EDGE_GEM_VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0.alpha.15
1
+ 3.1.0.alpha.16
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0.alpha.15
1
+ 3.1.0.alpha.16
data/lib/sass/engine.rb CHANGED
@@ -731,11 +731,11 @@ WARNING
731
731
  raise SyntaxError.new("Invalid mixin include \"#{line.text}\".") if name.nil?
732
732
 
733
733
  offset = line.offset + line.text.size - arg_string.size
734
- args = Script::Parser.new(arg_string.strip, @line, offset, @options).
734
+ args, keywords = Script::Parser.new(arg_string.strip, @line, offset, @options).
735
735
  parse_mixin_include_arglist
736
736
  raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath mixin directives.",
737
737
  :line => @line + 1) unless line.children.empty?
738
- Tree::MixinNode.new(name, args)
738
+ Tree::MixinNode.new(name, args, keywords)
739
739
  end
740
740
 
741
741
  def parse_script(script, options = {})
@@ -17,6 +17,11 @@ module Sass
17
17
  # @return [Array<Script::Node>]
18
18
  attr_reader :args
19
19
 
20
+ # The keyword arguments to the function.
21
+ #
22
+ # @return [{String => Script::Node}]
23
+ attr_reader :keywords
24
+
20
25
  # Don't set the context for child nodes if this is `url()`,
21
26
  # since `url()` allows quoted strings.
22
27
  #
@@ -27,21 +32,29 @@ module Sass
27
32
  end
28
33
 
29
34
  # @param name [String] See \{#name}
30
- # @param name [Array<Script::Node>] See \{#args}
31
- def initialize(name, args)
35
+ # @param args [Array<Script::Node>] See \{#args}
36
+ # @param keywords [{String => Script::Node}] See \{#keywords}
37
+ def initialize(name, args, keywords)
32
38
  @name = name
33
39
  @args = args
40
+ @keywords = keywords
34
41
  super()
35
42
  end
36
43
 
37
44
  # @return [String] A string representation of the function call
38
45
  def inspect
39
- "#{name}(#{args.map {|a| a.inspect}.join(', ')})"
46
+ args = @args.map {|a| a.inspect}.join(', ')
47
+ keywords = @keywords.sort_by {|k, v| k}.
48
+ map {|k, v| "$#{k}: #{v.inspect}"}.join(', ')
49
+ "#{name}(#{args}#{', ' unless args.empty? || keywords.empty?}#{keywords})"
40
50
  end
41
51
 
42
52
  # @see Node#to_sass
43
53
  def to_sass(opts = {})
44
- "#{dasherize(name, opts)}(#{args.map {|a| a.to_sass(opts)}.join(', ')})"
54
+ args = @args.map {|a| a.to_sass(opts)}.join(', ')
55
+ keywords = @keywords.sort_by {|k, v| k}.
56
+ map {|k, v| "$#{dasherize(k, opts)}: #{v.to_sass(opts)}"}.join(', ')
57
+ "#{dasherize(name, opts)}(#{args}#{', ' unless args.empty? || keywords.empty?}#{keywords})"
45
58
  end
46
59
 
47
60
  # Returns the arguments to the function.
@@ -49,7 +62,7 @@ module Sass
49
62
  # @return [Array<Node>]
50
63
  # @see Node#children
51
64
  def children
52
- @args
65
+ @args + @keywords.values
53
66
  end
54
67
 
55
68
  protected
@@ -60,17 +73,45 @@ module Sass
60
73
  # @return [Literal] The SassScript object that is the value of the function call
61
74
  # @raise [Sass::SyntaxError] if the function call raises an ArgumentError
62
75
  def _perform(environment)
63
- performed_args = @args.map {|a| a.perform(environment)}
76
+ args = @args.map {|a| a.perform(environment)}
77
+ keywords = Sass::Util.map_hash(@keywords) {|k, v| [k, v.perform(environment)]}
64
78
  ruby_name = @name.tr('-', '_')
79
+ args = construct_ruby_args(ruby_name, args, keywords)
80
+
65
81
  unless Sass::Util.has?(:public_instance_method, Functions, ruby_name) && ruby_name !~ /^__/
66
- opts(Script::String.new("#{name}(#{performed_args.join(', ')})"))
82
+ opts(Script::String.new("#{name}(#{args.join(', ')})"))
67
83
  else
68
- opts(Functions::EvaluationContext.new(environment.options).send(ruby_name, *performed_args))
84
+ opts(Functions::EvaluationContext.new(environment.options).send(ruby_name, *args))
69
85
  end
70
86
  rescue ArgumentError => e
71
87
  raise e unless e.backtrace.any? {|t| t =~ /:in `(block in )?(#{name}|perform)'$/}
72
88
  raise Sass::SyntaxError.new("#{e.message} for `#{name}'")
73
89
  end
90
+
91
+ def construct_ruby_args(name, args, keywords)
92
+ return args if keywords.empty?
93
+ unless signature = Functions.signature(name.to_sym, args.size, keywords.size)
94
+ raise Sass::SyntaxError.new("Function #{name} doesn't support keyword arguments")
95
+ end
96
+
97
+ args = args + signature.args[args.size..-1].map do |argname|
98
+ if keywords.has_key?(argname)
99
+ keywords.delete(argname)
100
+ else
101
+ raise Sass::SyntaxError, "Function #{name} requires an argument named $#{argname}"
102
+ end
103
+ end
104
+
105
+ if keywords.size > 0
106
+ if signature.var_kwargs
107
+ args << Sass::Util.map_hash(keywords) {|k, v| [k.to_sym, v]}
108
+ else
109
+ raise Sass::SyntaxError, "Function #{name} doesn't take an argument named $#{keywords.keys.sort.first}"
110
+ end
111
+ end
112
+
113
+ args
114
+ end
74
115
  end
75
116
  end
76
117
  end
@@ -8,122 +8,125 @@ module Sass::Script
8
8
  #
9
9
  # The following functions are provided:
10
10
  #
11
+ # *Note: These functions are described in more detail below.*
12
+ #
11
13
  # ## RGB Functions
12
14
  #
13
- # \{#rgb}
15
+ # \{#rgb rgb($red, $green, $blue)}
14
16
  # : Converts an `rgb(red, green, blue)` triplet into a color.
15
17
  #
16
- # \{#rgba}
18
+ # \{#rgba rgba($red, $green, $blue, $alpha)}
17
19
  # : Converts an `rgba(red, green, blue, alpha)` quadruplet into a color.
18
20
  #
19
- # \{#red}
21
+ # \{#rgba rgba($color, $alpha)}
22
+ # : Adds an alpha layer to any color value.
23
+ #
24
+ # \{#red red($color)}
20
25
  # : Gets the red component of a color.
21
26
  #
22
- # \{#green}
27
+ # \{#green green($color)}
23
28
  # : Gets the green component of a color.
24
29
  #
25
- # \{#blue}
30
+ # \{#blue blue($color)}
26
31
  # : Gets the blue component of a color.
27
32
  #
28
- # \{#mix}
33
+ # \{#mix mix($color-1, $color-2, \[$weight\])}
29
34
  # : Mixes two colors together.
30
35
  #
31
36
  # ## HSL Functions
32
37
  #
33
- # \{#hsl}
38
+ # \{#hsl hsl($hue, $saturation, $lightness)}
34
39
  # : Converts an `hsl(hue, saturation, lightness)` triplet into a color.
35
40
  #
36
- # \{#hsla}
41
+ # \{#hsla hsla($hue, $saturation, $lightness, $alpha)}
37
42
  # : Converts an `hsla(hue, saturation, lightness, alpha)` quadruplet into a color.
38
43
  #
39
- # \{#hue}
44
+ # \{#hue hue($color)}
40
45
  # : Gets the hue component of a color.
41
46
  #
42
- # \{#saturation}
47
+ # \{#saturation saturation($color)}
43
48
  # : Gets the saturation component of a color.
44
49
  #
45
- # \{#lightness}
50
+ # \{#lightness lightness($color)}
46
51
  # : Gets the lightness component of a color.
47
52
  #
48
- # \{#adjust_hue #adjust-hue}
53
+ # \{#adjust_hue adjust-hue($color, $degrees)}
49
54
  # : Changes the hue of a color.
50
55
  #
51
- # \{#lighten}
56
+ # \{#lighten lighten($color, $amount)}
52
57
  # : Makes a color lighter.
53
58
  #
54
- # \{#darken}
59
+ # \{#darken darken($color, $amount)}
55
60
  # : Makes a color darker.
56
61
  #
57
- # \{#saturate}
62
+ # \{#saturate saturate($color, $amount)}
58
63
  # : Makes a color more saturated.
59
64
  #
60
- # \{#desaturate}
65
+ # \{#desaturate desaturate($color, $amount)}
61
66
  # : Makes a color less saturated.
62
67
  #
63
- # \{#grayscale}
68
+ # \{#grayscale grayscale($color)}
64
69
  # : Converts a color to grayscale.
65
70
  #
66
- # \{#complement}
71
+ # \{#complement complement($color)}
67
72
  # : Returns the complement of a color.
68
73
  #
69
- # \{#invert}
74
+ # \{#invert invert($color)}
70
75
  # : Returns the inverse of a color.
71
76
  #
72
77
  # ## Opacity Functions
73
78
  #
74
- # \{#alpha} / \{#opacity}
79
+ # \{#alpha alpha($color)} / \{#opacity opacity($color)}
75
80
  # : Gets the alpha component (opacity) of a color.
76
81
  #
77
- # \{#rgba}
78
- # : Sets the alpha component of a color.
82
+ # \{#rgba rgba($color, $alpha)}
83
+ # : Add or change an alpha layer for any color value.
79
84
  #
80
- # \{#opacify} / \{#fade_in #fade-in}
85
+ # \{#opacify opacify($color, $amount)} / \{#fade_in fade-in($color, $amount)}
81
86
  # : Makes a color more opaque.
82
87
  #
83
- # \{#transparentize} / \{#fade_out #fade-out}
88
+ # \{#transparentize transparentize($color, $amount)} / \{#fade_out fade-out($color, $amount)}
84
89
  # : Makes a color more transparent.
85
90
  #
86
91
  # ## String Functions
87
92
  #
88
- # \{#unquote}
93
+ # \{#unquote unquote($string)}
89
94
  # : Removes the quotes from a string.
90
95
  #
91
- # \{#quote}
96
+ # \{#quote quote($string)}
92
97
  # : Adds quotes to a string.
93
98
  #
94
99
  # ## Number Functions
95
100
  #
96
- # \{#percentage}
101
+ # \{#percentage percentage($value)}
97
102
  # : Converts a unitless number to a percentage.
98
103
  #
99
- # \{#round}
104
+ # \{#round round($value)}
100
105
  # : Rounds a number to the nearest whole number.
101
106
  #
102
- # \{#ceil}
107
+ # \{#ceil ceil($value)}
103
108
  # : Rounds a number up to the nearest whole number.
104
109
  #
105
- # \{#floor}
110
+ # \{#floor floor($value)}
106
111
  # : Rounds a number down to the nearest whole number.
107
112
  #
108
- # \{#abs}
113
+ # \{#abs abs($value)}
109
114
  # : Returns the absolute value of a number.
110
115
  #
111
116
  # ## Introspection Functions
112
117
  #
113
- # \{#type_of}
118
+ # \{#type_of type-of($value)}
114
119
  # : Returns the type of a value.
115
120
  #
116
- # \{#unit}
121
+ # \{#unit unit($number)}
117
122
  # : Returns the units associated with a number.
118
123
  #
119
- # \{#unitless}
124
+ # \{#unitless unitless($number)}
120
125
  # : Returns whether a number has units or not.
121
126
  #
122
- # \{#comparable}
127
+ # \{#comparable comparable($number-1, $number-2)}
123
128
  # : Returns whether two numbers can be added or compared.
124
129
  #
125
- # These functions are described in more detail below.
126
- #
127
130
  # ## Adding Custom Functions
128
131
  #
129
132
  # New Sass functions can be added by adding Ruby methods to this module.
@@ -134,8 +137,13 @@ module Sass::Script
134
137
  # assert_type string, :String
135
138
  # Sass::Script::String.new(string.value.reverse)
136
139
  # end
140
+ # declare :reverse, :args => [:string]
137
141
  # end
138
142
  #
143
+ # Calling {declare} tells Sass the argument names for your function.
144
+ # If omitted, the function will still work, but will not be able to accept keyword arguments.
145
+ # {declare} can also allow your function to take arbitrary keyword arguments.
146
+ #
139
147
  # There are a few things to keep in mind when modifying this module.
140
148
  # First of all, the arguments passed are {Sass::Script::Literal} objects.
141
149
  # Literal objects are also expected to be returned.
@@ -169,6 +177,91 @@ module Sass::Script
169
177
  # (or other methods that use the string representation)
170
178
  # on those objects without first setting {Node#options= the #options attribute}.
171
179
  module Functions
180
+ @signatures = {}
181
+
182
+ # A class representing a Sass function signature.
183
+ #
184
+ # @attr args [Array<Symbol>] The names of the arguments to the function.
185
+ # @attr var_args [Boolean] Whether the function takes a variable number of arguments.
186
+ # @attr var_kwargs [Boolean] Whether the function takes an arbitrary set of keyword arguments.
187
+ Signature = Struct.new(:args, :var_args, :var_kwargs)
188
+
189
+ # Declare a Sass signature for a Ruby-defined function.
190
+ # This includes the names of the arguments,
191
+ # whether the function takes a variable number of arguments,
192
+ # and whether the function takes an arbitrary set of keyword arguments.
193
+ #
194
+ # It's not necessary to declare a signature for a function.
195
+ # However, without a signature it won't support keyword arguments.
196
+ #
197
+ # A single function can have multiple signatures declared
198
+ # as long as each one takes a different number of arguments.
199
+ # It's also possible to declare multiple signatures
200
+ # that all take the same number of arguments,
201
+ # but none of them but the first will be used
202
+ # unless the user uses keyword arguments.
203
+ #
204
+ # @param method_name [Symbol] The name of the method
205
+ # whose signature is being declared.
206
+ # @param args [Array<Symbol>] The names of the arguments for the function signature.
207
+ # @option options :var_args [Boolean] (false)
208
+ # Whether the function accepts a variable number of (unnamed) arguments
209
+ # in addition to the named arguments.
210
+ # @option options :var_kwargs [Boolean] (false)
211
+ # Whether the function accepts other keyword arguments
212
+ # in addition to those in `:args`.
213
+ # If this is true, the Ruby function will be passed a hash from strings
214
+ # to {Sass::Script::Literal}s as the last argument.
215
+ #
216
+ # @example
217
+ # declare :rgba, [:hex, :alpha]
218
+ # declare :rgba, [:red, :green, :blue, :alpha]
219
+ # declare :accepts_anything, [], :var_args => true, :var_kwargs => true
220
+ # declare :some_func, [:foo, :bar, :baz], :var_kwargs => true
221
+ def self.declare(method_name, args, options = {})
222
+ @signatures[method_name] ||= []
223
+ @signatures[method_name] << Signature.new(
224
+ args.map {|s| s.to_s},
225
+ options[:var_args],
226
+ options[:var_kwargs])
227
+ end
228
+
229
+ # Determine the correct signature for the number of arguments
230
+ # passed in for a given function.
231
+ # If no signatures match, the first signature is returned for error messaging.
232
+ #
233
+ # @param method_name [Symbol] The name of the Ruby function to be called.
234
+ # @param arg_arity [Number] The number of unnamed arguments the function was passed.
235
+ # @param kwarg_arity [Number] The number of keyword arguments the function was passed.
236
+ #
237
+ # @return [{Symbol => Object}, nil]
238
+ # The signature options for the matching signature,
239
+ # or nil if no signatures are declared for this function. See {declare}.
240
+ def self.signature(method_name, arg_arity, kwarg_arity)
241
+ return unless @signatures[method_name]
242
+ @signatures[method_name].each do |signature|
243
+ return signature if signature.args.size == arg_arity + kwarg_arity
244
+ next unless signature.args.size < arg_arity + kwarg_arity
245
+
246
+ # We have enough args.
247
+ # Now we need to figure out which args are varargs
248
+ # and if the signature allows them.
249
+ t_arg_arity, t_kwarg_arity = arg_arity, kwarg_arity
250
+ if signature.args.size > t_arg_arity
251
+ # we transfer some kwargs arity to args arity
252
+ # if it does not have enough args -- assuming the names will work out.
253
+ t_kwarg_arity -= (signature.args.size - t_arg_arity)
254
+ t_arg_arity = signature.args.size
255
+ end
256
+
257
+ if ( t_arg_arity == signature.args.size || t_arg_arity > signature.args.size && signature.var_args ) &&
258
+ (t_kwarg_arity == 0 || t_kwarg_arity > 0 && signature.var_kwargs)
259
+ return signature
260
+ end
261
+ end
262
+ @signatures[method_name].first
263
+ end
264
+
172
265
  # The context in which methods in {Script::Functions} are evaluated.
173
266
  # That means that all instance methods of {EvaluationContext}
174
267
  # are available to use in functions.
@@ -237,6 +330,7 @@ module Sass::Script
237
330
  end
238
331
  end)
239
332
  end
333
+ declare :rgb, [:red, :green, :blue]
240
334
 
241
335
  # @see #rgb
242
336
  # @overload rgba(red, green, blue, alpha)
@@ -284,6 +378,8 @@ module Sass::Script
284
378
  raise ArgumentError.new("wrong number of arguments (#{args.size} for 4)")
285
379
  end
286
380
  end
381
+ declare :rgba, [:red, :green, :blue, :alpha]
382
+ declare :rgba, [:color, :alpha]
287
383
 
288
384
  # Creates a {Color} object from hue, saturation, and lightness.
289
385
  # Uses the algorithm from the [CSS3 spec](http://www.w3.org/TR/css3-color/#hsl-color).
@@ -300,6 +396,7 @@ module Sass::Script
300
396
  def hsl(hue, saturation, lightness)
301
397
  hsla(hue, saturation, lightness, Number.new(1))
302
398
  end
399
+ declare :hsl, [:hue, :saturation, :lightness]
303
400
 
304
401
  # Creates a {Color} object from hue, saturation, and lightness,
305
402
  # as well as an alpha channel indicating opacity.
@@ -335,6 +432,7 @@ module Sass::Script
335
432
 
336
433
  Color.new(:hue => h, :saturation => s, :lightness => l, :alpha => alpha.value)
337
434
  end
435
+ declare :hsla, [:hue, :saturation, :lightness, :alpha]
338
436
 
339
437
  # Returns the red component of a color.
340
438
  #
@@ -345,6 +443,7 @@ module Sass::Script
345
443
  assert_type color, :Color
346
444
  Sass::Script::Number.new(color.red)
347
445
  end
446
+ declare :red, [:color]
348
447
 
349
448
  # Returns the green component of a color.
350
449
  #
@@ -355,6 +454,7 @@ module Sass::Script
355
454
  assert_type color, :Color
356
455
  Sass::Script::Number.new(color.green)
357
456
  end
457
+ declare :green, [:color]
358
458
 
359
459
  # Returns the blue component of a color.
360
460
  #
@@ -365,6 +465,7 @@ module Sass::Script
365
465
  assert_type color, :Color
366
466
  Sass::Script::Number.new(color.blue)
367
467
  end
468
+ declare :blue, [:color]
368
469
 
369
470
  # Returns the hue component of a color.
370
471
  #
@@ -380,6 +481,7 @@ module Sass::Script
380
481
  assert_type color, :Color
381
482
  Sass::Script::Number.new(color.hue, ["deg"])
382
483
  end
484
+ declare :hue, [:color]
383
485
 
384
486
  # Returns the saturation component of a color.
385
487
  #
@@ -396,6 +498,7 @@ module Sass::Script
396
498
  assert_type color, :Color
397
499
  Sass::Script::Number.new(color.saturation, ["%"])
398
500
  end
501
+ declare :saturation, [:color]
399
502
 
400
503
  # Returns the hue component of a color.
401
504
  #
@@ -412,6 +515,7 @@ module Sass::Script
412
515
  assert_type color, :Color
413
516
  Sass::Script::Number.new(color.lightness, ["%"])
414
517
  end
518
+ declare :lightness, [:color]
415
519
 
416
520
  # Returns the alpha component (opacity) of a color.
417
521
  # This is 1 unless otherwise specified.
@@ -436,6 +540,7 @@ module Sass::Script
436
540
 
437
541
  opacity(*args)
438
542
  end
543
+ declare :alpha, [:color]
439
544
 
440
545
  # Returns the alpha component (opacity) of a color.
441
546
  # This is 1 unless otherwise specified.
@@ -449,6 +554,7 @@ module Sass::Script
449
554
  assert_type color, :Color
450
555
  Sass::Script::Number.new(color.alpha)
451
556
  end
557
+ declare :opacity, [:color]
452
558
 
453
559
  # Makes a color more opaque.
454
560
  # Takes a color and an amount between 0 and 1,
@@ -466,7 +572,10 @@ module Sass::Script
466
572
  def opacify(color, amount)
467
573
  adjust(color, amount, :alpha, 0..1, :+)
468
574
  end
575
+ declare :opacify, [:color, :amount]
576
+
469
577
  alias_method :fade_in, :opacify
578
+ declare :fade_in, [:color, :amount]
470
579
 
471
580
  # Makes a color more transparent.
472
581
  # Takes a color and an amount between 0 and 1,
@@ -484,7 +593,10 @@ module Sass::Script
484
593
  def transparentize(color, amount)
485
594
  adjust(color, amount, :alpha, 0..1, :-)
486
595
  end
596
+ declare :transparentize, [:color, :amount]
597
+
487
598
  alias_method :fade_out, :transparentize
599
+ declare :fade_out, [:color, :amount]
488
600
 
489
601
  # Makes a color lighter.
490
602
  # Takes a color and an amount between 0% and 100%,
@@ -502,6 +614,7 @@ module Sass::Script
502
614
  def lighten(color, amount)
503
615
  adjust(color, amount, :lightness, 0..100, :+, "%")
504
616
  end
617
+ declare :lighten, [:color, :amount]
505
618
 
506
619
  # Makes a color darker.
507
620
  # Takes a color and an amount between 0% and 100%,
@@ -519,6 +632,7 @@ module Sass::Script
519
632
  def darken(color, amount)
520
633
  adjust(color, amount, :lightness, 0..100, :-, "%")
521
634
  end
635
+ declare :darken, [:color, :amount]
522
636
 
523
637
  # Makes a color more saturated.
524
638
  # Takes a color and an amount between 0% and 100%,
@@ -536,6 +650,7 @@ module Sass::Script
536
650
  def saturate(color, amount)
537
651
  adjust(color, amount, :saturation, 0..100, :+, "%")
538
652
  end
653
+ declare :saturate, [:color, :amount]
539
654
 
540
655
  # Makes a color less saturated.
541
656
  # Takes a color and an amount between 0% and 100%,
@@ -553,6 +668,7 @@ module Sass::Script
553
668
  def desaturate(color, amount)
554
669
  adjust(color, amount, :saturation, 0..100, :-, "%")
555
670
  end
671
+ declare :desaturate, [:color, :amount]
556
672
 
557
673
  # Changes the hue of a color while retaining the lightness and saturation.
558
674
  # Takes a color and a number of degrees (usually between -360deg and 360deg),
@@ -571,6 +687,7 @@ module Sass::Script
571
687
  assert_type degrees, :Number
572
688
  color.with(:hue => color.hue + degrees.value)
573
689
  end
690
+ declare :adjust_hue, [:color, :degrees]
574
691
 
575
692
  # Mixes together two colors.
576
693
  # Specifically, takes the average of each of the RGB components,
@@ -635,6 +752,8 @@ module Sass::Script
635
752
  alpha = color1.alpha*p + color2.alpha*(1-p)
636
753
  Color.new(rgb + [alpha])
637
754
  end
755
+ declare :mix, [:color_1, :color_2]
756
+ declare :mix, [:color_1, :color_2, :weight]
638
757
 
639
758
  # Converts a color to grayscale.
640
759
  # This is identical to `desaturate(color, 100%)`.
@@ -646,6 +765,7 @@ module Sass::Script
646
765
  def grayscale(color)
647
766
  desaturate color, Number.new(100)
648
767
  end
768
+ declare :grayscale, [:color]
649
769
 
650
770
  # Returns the complement of a color.
651
771
  # This is identical to `adjust-hue(color, 180deg)`.
@@ -657,6 +777,7 @@ module Sass::Script
657
777
  def complement(color)
658
778
  adjust_hue color, Number.new(180)
659
779
  end
780
+ declare :complement, [:color]
660
781
 
661
782
  # Returns the inverse (negative) of a color.
662
783
  # The red, green, and blue values are inverted, while the opacity is left alone.
@@ -675,32 +796,34 @@ module Sass::Script
675
796
  # Removes quotes from a string if the string is quoted,
676
797
  # or returns the same string if it's not.
677
798
  #
678
- # @param str [String]
799
+ # @param string [String]
679
800
  # @return [String]
680
- # @raise [ArgumentError] if `str` isn't a string
801
+ # @raise [ArgumentError] if `string` isn't a string
681
802
  # @see #quote
682
803
  # @example
683
804
  # unquote("foo") => foo
684
805
  # unquote(foo) => foo
685
- def unquote(str)
686
- assert_type str, :String
687
- Sass::Script::String.new(str.value, :identifier)
806
+ def unquote(string)
807
+ assert_type string, :String
808
+ Sass::Script::String.new(string.value, :identifier)
688
809
  end
810
+ declare :unquote, [:string]
689
811
 
690
812
  # Add quotes to a string if the string isn't quoted,
691
813
  # or returns the same string if it is.
692
814
  #
693
- # @param str [String]
815
+ # @param string [String]
694
816
  # @return [String]
695
- # @raise [ArgumentError] if `str` isn't a string
817
+ # @raise [ArgumentError] if `string` isn't a string
696
818
  # @see #unquote
697
819
  # @example
698
820
  # quote("foo") => "foo"
699
821
  # quote(foo) => "foo"
700
- def quote(str)
701
- assert_type str, :String
702
- Sass::Script::String.new(str.value, :string)
822
+ def quote(string)
823
+ assert_type string, :String
824
+ Sass::Script::String.new(string.value, :string)
703
825
  end
826
+ declare :quote, [:string]
704
827
 
705
828
  # Inspects the type of the argument, returning it as an unquoted string.
706
829
  #
@@ -711,11 +834,12 @@ module Sass::Script
711
834
  # type-of(true) => bool
712
835
  # type-of(#fff) => color
713
836
  # type-of(blue) => color
714
- # @param obj [Literal] The object to inspect
837
+ # @param value [Literal] The object to inspect
715
838
  # @return [String] The unquoted string name of the literal's type
716
- def type_of(obj)
717
- Sass::Script::String.new(obj.class.name.gsub(/Sass::Script::/,'').downcase)
839
+ def type_of(value)
840
+ Sass::Script::String.new(value.class.name.gsub(/Sass::Script::/,'').downcase)
718
841
  end
842
+ declare :type_of, [:value]
719
843
 
720
844
  # Inspects the unit of the number, returning it as a quoted string.
721
845
  # Complex units are sorted in alphabetical order by numerator and denominator.
@@ -733,6 +857,7 @@ module Sass::Script
733
857
  assert_type number, :Number
734
858
  Sass::Script::String.new(number.unit_str, :string)
735
859
  end
860
+ declare :unit, [:number]
736
861
 
737
862
  # Inspects the unit of the number, returning a boolean indicating if it is unitless.
738
863
  #
@@ -746,6 +871,7 @@ module Sass::Script
746
871
  assert_type number, :Number
747
872
  Sass::Script::Bool.new(number.unitless?)
748
873
  end
874
+ declare :unitless, [:number]
749
875
 
750
876
  # Returns true if two numbers are similar enough to be added, subtracted, or compared.
751
877
  #
@@ -753,15 +879,16 @@ module Sass::Script
753
879
  # comparable(2px, 1px) => true
754
880
  # comparable(100px, 3em) => false
755
881
  # comparable(10cm, 3mm) => true
756
- # @param number1 [Number]
757
- # @param number2 [Number]
882
+ # @param number_1 [Number]
883
+ # @param number_2 [Number]
758
884
  # @return [Bool] indicating if the numbers can be compared.
759
- # @raise [ArgumentError] if `number1` or `number2` aren't numbers
760
- def comparable(number1, number2)
761
- assert_type number1, :Number
762
- assert_type number2, :Number
763
- Sass::Script::Bool.new(number1.comparable_to?(number2))
885
+ # @raise [ArgumentError] if `number_1` or `number_2` aren't numbers
886
+ def comparable(number_1, number_2)
887
+ assert_type number_1, :Number
888
+ assert_type number_2, :Number
889
+ Sass::Script::Bool.new(number_1.comparable_to?(number_2))
764
890
  end
891
+ declare :comparable, [:number_1, :number_2]
765
892
 
766
893
  # Converts a decimal number to a percentage.
767
894
  #
@@ -776,6 +903,7 @@ module Sass::Script
776
903
  end
777
904
  Sass::Script::Number.new(value.value * 100, ['%'])
778
905
  end
906
+ declare :percentage, [:value]
779
907
 
780
908
  # Rounds a number to the nearest whole number.
781
909
  #
@@ -788,6 +916,7 @@ module Sass::Script
788
916
  def round(value)
789
917
  numeric_transformation(value) {|n| n.round}
790
918
  end
919
+ declare :round, [:value]
791
920
 
792
921
  # Rounds a number up to the nearest whole number.
793
922
  #
@@ -800,6 +929,7 @@ module Sass::Script
800
929
  def ceil(value)
801
930
  numeric_transformation(value) {|n| n.ceil}
802
931
  end
932
+ declare :ceil, [:value]
803
933
 
804
934
  # Rounds down to the nearest whole number.
805
935
  #
@@ -812,6 +942,7 @@ module Sass::Script
812
942
  def floor(value)
813
943
  numeric_transformation(value) {|n| n.floor}
814
944
  end
945
+ declare :floor, [:value]
815
946
 
816
947
  # Finds the absolute value of a number.
817
948
  #
@@ -824,6 +955,7 @@ module Sass::Script
824
955
  def abs(value)
825
956
  numeric_transformation(value) {|n| n.abs}
826
957
  end
958
+ declare :abs, [:value]
827
959
 
828
960
  private
829
961