sass 3.3.0.alpha.149 → 3.3.0.alpha.162

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.
Files changed (71) hide show
  1. data/REVISION +1 -1
  2. data/VERSION +1 -1
  3. data/VERSION_DATE +1 -1
  4. data/lib/sass/css.rb +1 -1
  5. data/lib/sass/engine.rb +4 -4
  6. data/lib/sass/environment.rb +1 -1
  7. data/lib/sass/exec.rb +1 -1
  8. data/lib/sass/media.rb +15 -15
  9. data/lib/sass/script.rb +32 -7
  10. data/lib/sass/script/css_lexer.rb +2 -2
  11. data/lib/sass/script/css_parser.rb +1 -1
  12. data/lib/sass/script/functions.rb +246 -232
  13. data/lib/sass/script/lexer.rb +24 -32
  14. data/lib/sass/script/parser.rb +84 -65
  15. data/lib/sass/script/tree.rb +14 -0
  16. data/lib/sass/script/tree/funcall.rb +242 -0
  17. data/lib/sass/script/{interpolation.rb → tree/interpolation.rb} +30 -13
  18. data/lib/sass/script/tree/list_literal.rb +65 -0
  19. data/lib/sass/script/tree/literal.rb +46 -0
  20. data/lib/sass/script/{node.rb → tree/node.rb} +10 -10
  21. data/lib/sass/script/{operation.rb → tree/operation.rb} +16 -27
  22. data/lib/sass/script/{string_interpolation.rb → tree/string_interpolation.rb} +4 -4
  23. data/lib/sass/script/{unary_operation.rb → tree/unary_operation.rb} +7 -8
  24. data/lib/sass/script/tree/variable.rb +56 -0
  25. data/lib/sass/script/value.rb +10 -0
  26. data/lib/sass/script/{arg_list.rb → value/arg_list.rb} +5 -20
  27. data/lib/sass/script/value/base.rb +222 -0
  28. data/lib/sass/script/{bool.rb → value/bool.rb} +2 -2
  29. data/lib/sass/script/{color.rb → value/color.rb} +22 -20
  30. data/lib/sass/script/{list.rb → value/list.rb} +15 -28
  31. data/lib/sass/script/{null.rb → value/null.rb} +3 -3
  32. data/lib/sass/script/{number.rb → value/number.rb} +19 -19
  33. data/lib/sass/script/{string.rb → value/string.rb} +7 -7
  34. data/lib/sass/scss/parser.rb +14 -4
  35. data/lib/sass/selector.rb +26 -26
  36. data/lib/sass/selector/abstract_sequence.rb +1 -1
  37. data/lib/sass/selector/simple.rb +6 -7
  38. data/lib/sass/source/position.rb +13 -0
  39. data/lib/sass/supports.rb +4 -4
  40. data/lib/sass/tree/comment_node.rb +3 -3
  41. data/lib/sass/tree/css_import_node.rb +7 -7
  42. data/lib/sass/tree/debug_node.rb +2 -2
  43. data/lib/sass/tree/directive_node.rb +2 -2
  44. data/lib/sass/tree/each_node.rb +2 -2
  45. data/lib/sass/tree/extend_node.rb +4 -4
  46. data/lib/sass/tree/for_node.rb +4 -4
  47. data/lib/sass/tree/function_node.rb +4 -4
  48. data/lib/sass/tree/media_node.rb +3 -3
  49. data/lib/sass/tree/mixin_def_node.rb +4 -4
  50. data/lib/sass/tree/mixin_node.rb +6 -6
  51. data/lib/sass/tree/prop_node.rb +23 -15
  52. data/lib/sass/tree/return_node.rb +2 -2
  53. data/lib/sass/tree/rule_node.rb +3 -3
  54. data/lib/sass/tree/variable_node.rb +2 -2
  55. data/lib/sass/tree/visitors/convert.rb +2 -2
  56. data/lib/sass/tree/visitors/deep_copy.rb +5 -5
  57. data/lib/sass/tree/visitors/perform.rb +7 -7
  58. data/lib/sass/tree/visitors/set_options.rb +6 -6
  59. data/lib/sass/tree/visitors/to_css.rb +1 -1
  60. data/lib/sass/tree/warn_node.rb +2 -2
  61. data/lib/sass/tree/while_node.rb +2 -2
  62. data/lib/sass/util.rb +2 -2
  63. data/test/sass/engine_test.rb +6 -6
  64. data/test/sass/functions_test.rb +20 -20
  65. data/test/sass/plugin_test.rb +2 -2
  66. data/test/sass/script_test.rb +38 -29
  67. data/test/test_helper.rb +1 -1
  68. metadata +23 -19
  69. data/lib/sass/script/funcall.rb +0 -238
  70. data/lib/sass/script/literal.rb +0 -221
  71. data/lib/sass/script/variable.rb +0 -58
data/REVISION CHANGED
@@ -1 +1 @@
1
- c2ce041855863e29ff5ca89fe6345fe322a1ea0e
1
+ 1560055ae94cf45bb26e6397ebcac5d737d9d791
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.3.0.alpha.149
1
+ 3.3.0.alpha.162
@@ -1 +1 @@
1
- 25 May 2013 00:06:51 GMT
1
+ 29 May 2013 19:57:06 GMT
@@ -326,7 +326,7 @@ module Sass
326
326
  next child
327
327
  end
328
328
 
329
- if prev_rule && prev_rule.children == child.children
329
+ if prev_rule && prev_rule.children.map {|c| c.to_sass} == child.children.map {|c| c.to_sass}
330
330
  prev_rule.parsed_rules.members << first_seq(child)
331
331
  next nil
332
332
  end
@@ -55,12 +55,12 @@ module Sass
55
55
  # `name`: `String`
56
56
  # : The name of the mixin/function.
57
57
  #
58
- # `args`: `Array<(Script::Node, Script::Node)>`
58
+ # `args`: `Array<(Script::Tree::Node, Script::Tree::Node)>`
59
59
  # : The arguments for the mixin/function.
60
60
  # Each element is a tuple containing the variable node of the argument
61
61
  # and the parse tree for the default value of the argument.
62
62
  #
63
- # `splat`: `Script::Node?`
63
+ # `splat`: `Script::Tree::Node?`
64
64
  # : The variable node of the splat argument for this callable, or null.
65
65
  #
66
66
  # `environment`: {Sass::Environment}
@@ -684,7 +684,7 @@ WARNING
684
684
 
685
685
  def parse_property(name, parsed_name, value, prop, line, start_offset)
686
686
  if value.strip.empty?
687
- expr = Sass::Script::String.new("")
687
+ expr = Sass::Script::Tree::Literal.new(Sass::Script::Value::String.new(""))
688
688
  end_offset = start_offset
689
689
  else
690
690
  expr = parse_script(value, :offset => to_parser_offset(start_offset))
@@ -1064,7 +1064,7 @@ WARNING
1064
1064
  end
1065
1065
 
1066
1066
  # It's important that this have strings (at least)
1067
- # at the beginning, the end, and between each Script::Node.
1067
+ # at the beginning, the end, and between each Script::Tree::Node.
1068
1068
  #
1069
1069
  # @private
1070
1070
  def self.parse_interp(text, line, offset, options)
@@ -93,7 +93,7 @@ RUBY
93
93
  end
94
94
 
95
95
  # variable
96
- # Script::Literal
96
+ # Script::Value
97
97
  inherited_hash :var
98
98
  # mixin
99
99
  # Sass::Callable
@@ -263,7 +263,7 @@ END
263
263
  end
264
264
  opts.on('--precision NUMBER_OF_DIGITS', Integer,
265
265
  'How many digits of precision to use when outputting decimal numbers. Defaults to 3.') do |precision|
266
- ::Sass::Script::Number.precision = precision
266
+ ::Sass::Script::Value::Number.precision = precision
267
267
  end
268
268
  opts.on('-q', '--quiet', 'Silence warnings and status messages during compilation.') do
269
269
  @options[:for_engine][:quiet] = true
@@ -43,11 +43,11 @@ module Sass::Media
43
43
  end
44
44
 
45
45
  # Returns a representation of the query as an array of strings and
46
- # potentially {Sass::Script::Node}s (if there's interpolation in it). When
47
- # the interpolation is resolved and the strings are joined together, this
48
- # will be the string representation of this query.
46
+ # potentially {Sass::Script::Tree::Node}s (if there's interpolation in it).
47
+ # When the interpolation is resolved and the strings are joined together,
48
+ # this will be the string representation of this query.
49
49
  #
50
- # @return [Array<String, Sass::Script::Node>]
50
+ # @return [Array<String, Sass::Script::Tree::Node>]
51
51
  def to_a
52
52
  Sass::Util.intersperse(queries.map {|q| q.to_a}, ', ').flatten
53
53
  end
@@ -70,7 +70,7 @@ module Sass::Media
70
70
  # parsed as CSS, it contains a single string (accessible via
71
71
  # \{#resolved_modifier}).
72
72
  #
73
- # @return [Array<String, Sass::Script::Node>]
73
+ # @return [Array<String, Sass::Script::Tree::Node>]
74
74
  attr_accessor :modifier
75
75
 
76
76
  # The type of the query (e.g. `"screen"` or `"print"`).
@@ -79,7 +79,7 @@ module Sass::Media
79
79
  # parsed as CSS, it contains a single string (accessible via
80
80
  # \{#resolved_type}).
81
81
  #
82
- # @return [Array<String, Sass::Script::Node>]
82
+ # @return [Array<String, Sass::Script::Tree::Node>]
83
83
  attr_accessor :type
84
84
 
85
85
  # The trailing expressions in the query.
@@ -87,12 +87,12 @@ module Sass::Media
87
87
  # When parsed as Sass code, each expression contains strings and SassScript
88
88
  # nodes. When parsed as CSS, each one contains a single string.
89
89
  #
90
- # @return [Array<Array<String, Sass::Script::Node>>]
90
+ # @return [Array<Array<String, Sass::Script::Tree::Node>>]
91
91
  attr_accessor :expressions
92
92
 
93
- # @param modifier [Array<String, Sass::Script::Node>] See \{#modifier}
94
- # @param type [Array<String, Sass::Script::Node>] See \{#type}
95
- # @param expressions [Array<Array<String, Sass::Script::Node>>] See \{#expressions}
93
+ # @param modifier [Array<String, Sass::Script::Tree::Node>] See \{#modifier}
94
+ # @param type [Array<String, Sass::Script::Tree::Node>] See \{#type}
95
+ # @param expressions [Array<Array<String, Sass::Script::Tree::Node>>] See \{#expressions}
96
96
  def initialize(modifier, type, expressions)
97
97
  @modifier = modifier
98
98
  @type = type
@@ -156,7 +156,7 @@ module Sass::Media
156
156
  # It's possible for there to be script nodes in Expressions even when
157
157
  # we're converting to CSS in the case where we parsed the document as
158
158
  # CSS originally (as in css_test.rb).
159
- e.map {|c| c.is_a?(Sass::Script::Node) ? c.to_sass : c.to_s}.join
159
+ e.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.to_sass : c.to_s}.join
160
160
  end.join(' and ')
161
161
  css
162
162
  end
@@ -193,15 +193,15 @@ module Sass::Media
193
193
  # @return [Query]
194
194
  def deep_copy
195
195
  Query.new(
196
- modifier.map {|c| c.is_a?(Sass::Script::Node) ? c.deep_copy : c},
197
- type.map {|c| c.is_a?(Sass::Script::Node) ? c.deep_copy : c},
198
- expressions.map {|e| e.map {|c| c.is_a?(Sass::Script::Node) ? c.deep_copy : c}})
196
+ modifier.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.deep_copy : c},
197
+ type.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.deep_copy : c},
198
+ expressions.map {|e| e.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.deep_copy : c}})
199
199
  end
200
200
  end
201
201
 
202
202
  # Converts an interpolation array to source.
203
203
  #
204
- # @param [Array<String, Sass::Script::Node>] The interpolation array to convert.
204
+ # @param [Array<String, Sass::Script::Tree::Node>] The interpolation array to convert.
205
205
  # @param options [{Symbol => Object}] An options hash (see {Sass::CSS#initialize}).
206
206
  # @return [String]
207
207
  def self._interp_to_src(interp, options)
@@ -1,9 +1,4 @@
1
- require 'sass/script/node'
2
- require 'sass/script/variable'
3
- require 'sass/script/funcall'
4
- require 'sass/script/operation'
5
- require 'sass/script/literal'
6
- require 'sass/script/parser'
1
+ require 'sass/scss/rx'
7
2
 
8
3
  module Sass
9
4
  # SassScript is code that's embedded in Sass documents
@@ -26,7 +21,7 @@ module Sass
26
21
  # Used for error reporting
27
22
  # @param options [{Symbol => Object}] An options hash;
28
23
  # see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}
29
- # @return [Script::Node] The root node of the parse tree
24
+ # @return [Script::Tree::Node] The root node of the parse tree
30
25
  def self.parse(value, line, offset, options = {})
31
26
  Parser.parse(value, line, offset, options)
32
27
  rescue Sass::SyntaxError => e
@@ -35,5 +30,35 @@ module Sass
35
30
  raise e
36
31
  end
37
32
 
33
+ require 'sass/script/functions'
34
+ require 'sass/script/parser'
35
+ require 'sass/script/tree'
36
+ require 'sass/script/value'
37
+
38
+ # @private
39
+ CONST_RENAMES = {
40
+ :Literal => Sass::Script::Value::Base,
41
+ :ArgList => Sass::Script::Value::ArgList,
42
+ :Bool => Sass::Script::Value::Bool,
43
+ :Color => Sass::Script::Value::Color,
44
+ :List => Sass::Script::Value::List,
45
+ :Null => Sass::Script::Value::Null,
46
+ :Number => Sass::Script::Value::Number,
47
+ :String => Sass::Script::Value::String,
48
+ :Node => Sass::Script::Tree::Node,
49
+ :Funcall => Sass::Script::Tree::Funcall,
50
+ :Interpolation => Sass::Script::Tree::Interpolation,
51
+ :Operation => Sass::Script::Tree::Operation,
52
+ :StringInterpolation => Sass::Script::Tree::StringInterpolation,
53
+ :UnaryOperation => Sass::Script::Tree::UnaryOperation,
54
+ :Variable => Sass::Script::Tree::Variable,
55
+ }
56
+
57
+ # @private
58
+ def self.const_missing(name)
59
+ super unless klass = CONST_RENAMES[name]
60
+ CONST_RENAMES.each {|n, k| const_set(n, k)}
61
+ klass
62
+ end
38
63
  end
39
64
  end
@@ -13,11 +13,11 @@ module Sass
13
13
  def string(re, *args)
14
14
  if re == :uri
15
15
  return unless uri = scan(URI)
16
- return [:string, Script::String.new(uri)]
16
+ return [:string, Script::Value::String.new(uri)]
17
17
  end
18
18
 
19
19
  return unless scan(STRING)
20
- [:string, Script::String.new((@scanner[1] || @scanner[2]).gsub(/\\(['"])/, '\1'), :string)]
20
+ [:string, Script::Value::String.new((@scanner[1] || @scanner[2]).gsub(/\\(['"])/, '\1'), :string)]
21
21
  end
22
22
 
23
23
  def important
@@ -18,7 +18,7 @@ module Sass
18
18
 
19
19
  def string
20
20
  return number unless tok = try_tok(:string)
21
- return tok.value unless @lexer.peek && @lexer.peek.type == :begin_interpolation
21
+ return literal_node(tok.value, tok.source_range) unless @lexer.peek && @lexer.peek.type == :begin_interpolation
22
22
  end
23
23
 
24
24
  # Short-circuit all the SassScript-only productions
@@ -201,7 +201,7 @@ module Sass::Script
201
201
  # module Sass::Script::Functions
202
202
  # def reverse(string)
203
203
  # assert_type string, :String
204
- # Sass::Script::String.new(string.value.reverse)
204
+ # Sass::Script::Value::String.new(string.value.reverse)
205
205
  # end
206
206
  # declare :reverse, :args => [:string]
207
207
  # end
@@ -211,14 +211,15 @@ module Sass::Script
211
211
  # {declare} can also allow your function to take arbitrary keyword arguments.
212
212
  #
213
213
  # There are a few things to keep in mind when modifying this module.
214
- # First of all, the arguments passed are {Literal} objects.
215
- # Literal objects are also expected to be returned.
214
+ # First of all, the arguments passed are {Value} objects.
215
+ # Value objects are also expected to be returned.
216
216
  # This means that Ruby values must be unwrapped and wrapped.
217
217
  #
218
- # Most Literal objects support the {Literal#value value} accessor
219
- # for getting their Ruby values.
220
- # Color objects, though, must be accessed using {Color#rgb rgb},
221
- # {Color#red red}, {Color#blue green}, or {Color#blue blue}.
218
+ # Most Value objects support the {Value#value value} accessor for getting
219
+ # their Ruby values. Color objects, though, must be accessed using
220
+ # {Sass::Script::Value::Color#rgb rgb}, {Sass::Script::Value::Color#red red},
221
+ # {Sass::Script::Value::Color#blue green}, or {Sass::Script::Value::Color#blue
222
+ # blue}.
222
223
  #
223
224
  # Second, making Ruby functions accessible from Sass introduces the temptation
224
225
  # to do things like database access within stylesheets.
@@ -238,10 +239,10 @@ module Sass::Script
238
239
  #
239
240
  # ### Caveats
240
241
  #
241
- # When creating new {Literal} objects within functions,
242
- # be aware that it's not safe to call {Literal#to_s #to_s}
243
- # (or other methods that use the string representation)
244
- # on those objects without first setting {Node#options= the #options attribute}.
242
+ # When creating new {Value} objects within functions, be aware that it's not
243
+ # safe to call {Value#to_s #to_s} (or other methods that use the string
244
+ # representation) on those objects without first setting {Tree::Node#options=
245
+ # the #options attribute}.
245
246
  module Functions
246
247
  @signatures = {}
247
248
 
@@ -277,7 +278,7 @@ module Sass::Script
277
278
  # Whether the function accepts other keyword arguments
278
279
  # in addition to those in `:args`.
279
280
  # If this is true, the Ruby function will be passed a hash from strings
280
- # to {Literal}s as the last argument.
281
+ # to {Value}s as the last argument.
281
282
  # In addition, if this is true and `:var_args` is not,
282
283
  # Sass will ensure that the last argument passed is a hash.
283
284
  #
@@ -299,8 +300,8 @@ module Sass::Script
299
300
  # If no signatures match, the first signature is returned for error messaging.
300
301
  #
301
302
  # @param method_name [Symbol] The name of the Ruby function to be called.
302
- # @param arg_arity [Number] The number of unnamed arguments the function was passed.
303
- # @param kwarg_arity [Number] The number of keyword arguments the function was passed.
303
+ # @param arg_arity [Fixnum] The number of unnamed arguments the function was passed.
304
+ # @param kwarg_arity [Fixnum] The number of keyword arguments the function was passed.
304
305
  #
305
306
  # @return [{Symbol => Object}, nil]
306
307
  # The signature options for the matching signature,
@@ -363,12 +364,12 @@ module Sass::Script
363
364
  # @example
364
365
  # assert_type value, :String
365
366
  # assert_type value, :Number
366
- # @param value [Literal] A SassScript value
367
+ # @param value [Value] A SassScript value
367
368
  # @param type [Symbol] The name of the type the value is expected to be
368
369
  # @param name [String, nil] The name of the argument.
369
370
  # @raise [ArgumentError] if value is not of the correct type.
370
371
  def assert_type(value, type, name = nil)
371
- return if value.is_a?(Sass::Script.const_get(type))
372
+ return if value.is_a?(Sass::Script::Value.const_get(type))
372
373
  err = "#{value.inspect} is not a #{type.to_s.downcase}"
373
374
  err = "$#{name}: " + err if name
374
375
  raise ArgumentError.new(err)
@@ -379,7 +380,7 @@ module Sass::Script
379
380
  # @example
380
381
  # assert_unit number, "px"
381
382
  # assert_unit number, nil
382
- # @param number [Number] The number to be validated.
383
+ # @param number [Sass::Script::Value::Number] The number to be validated.
383
384
  # @param unit [::String]
384
385
  # The unit that the number must have.
385
386
  # If nil, the number must be unitless.
@@ -401,7 +402,7 @@ module Sass::Script
401
402
  # @example
402
403
  # assert_unit number, "px"
403
404
  # assert_unit number, nil
404
- # @param number [Literal] The literal to be validated.
405
+ # @param number [Sass::Script::Value::Base] The value to be validated.
405
406
  # @param name [::String] The name of the parameter being validated.
406
407
  # @raise [ArgumentError] if number is not an integer or is not a number.
407
408
  def assert_integer(number, name = nil)
@@ -432,25 +433,26 @@ module Sass::Script
432
433
  end
433
434
  end
434
435
 
435
- # Creates a {Color} object from red, green, and blue values.
436
+ # Creates a {Sass::Script::Value::Color Color} object from red, green, and
437
+ # blue values.
436
438
  #
437
- # @param red [Number]
439
+ # @param red [Sass::Script::Value::Number]
438
440
  # A number between 0 and 255 inclusive,
439
441
  # or between 0% and 100% inclusive
440
- # @param green [Number]
442
+ # @param green [Sass::Script::Value::Number]
441
443
  # A number between 0 and 255 inclusive,
442
444
  # or between 0% and 100% inclusive
443
- # @param blue [Number]
445
+ # @param blue [Sass::Script::Value::Number]
444
446
  # A number between 0 and 255 inclusive,
445
447
  # or between 0% and 100% inclusive
446
448
  # @see #rgba
447
- # @return [Color]
449
+ # @return [Sass::Script::Value::Color]
448
450
  def rgb(red, green, blue)
449
451
  assert_type red, :Number
450
452
  assert_type green, :Number
451
453
  assert_type blue, :Number
452
454
 
453
- Color.new([red, green, blue].map do |c|
455
+ Sass::Script::Value::Color.new([red, green, blue].map do |c|
454
456
  v = c.value
455
457
  if c.is_unit?("%")
456
458
  v = Sass::Util.check_range("Color value", 0..100, c, '%')
@@ -466,18 +468,18 @@ module Sass::Script
466
468
 
467
469
  # @see #rgb
468
470
  # @overload rgba(red, green, blue, alpha)
469
- # Creates a {Color} object from red, green, and blue values,
470
- # as well as an alpha channel indicating opacity.
471
+ # Creates a {Sass::Script::Value::Color Color} object from red, green, and
472
+ # blue values, as well as an alpha channel indicating opacity.
471
473
  #
472
- # @param red [Number]
474
+ # @param red [Sass::Script::Value::Number]
473
475
  # A number between 0 and 255 inclusive
474
- # @param green [Number]
476
+ # @param green [Sass::Script::Value::Number]
475
477
  # A number between 0 and 255 inclusive
476
- # @param blue [Number]
478
+ # @param blue [Sass::Script::Value::Number]
477
479
  # A number between 0 and 255 inclusive
478
- # @param alpha [Number]
480
+ # @param alpha [Sass::Script::Value::Number]
479
481
  # A number between 0 and 1
480
- # @return [Color]
482
+ # @return [Sass::Script::Value::Color]
481
483
  #
482
484
  # @overload rgba(color, alpha)
483
485
  # Sets the opacity of a color.
@@ -486,10 +488,10 @@ module Sass::Script
486
488
  # rgba(#102030, 0.5) => rgba(16, 32, 48, 0.5)
487
489
  # rgba(blue, 0.2) => rgba(0, 0, 255, 0.2)
488
490
  #
489
- # @param color [Color]
490
- # @param alpha [Number]
491
+ # @param color [Sass::Script::Value::Color]
492
+ # @param alpha [Sass::Script::Value::Number]
491
493
  # A number between 0 and 1
492
- # @return [Color]
494
+ # @return [Sass::Script::Value::Color]
493
495
  def rgba(*args)
494
496
  case args.size
495
497
  when 2
@@ -510,36 +512,36 @@ module Sass::Script
510
512
  declare :rgba, [:red, :green, :blue, :alpha]
511
513
  declare :rgba, [:color, :alpha]
512
514
 
513
- # Creates a {Color} object from hue, saturation, and lightness.
514
- # Uses the algorithm from the [CSS3 spec](http://www.w3.org/TR/css3-color/#hsl-color).
515
+ # Creates a {Sass::Script::Value::Color Color} object from hue, saturation,
516
+ # and lightness. Uses the algorithm from the [CSS3 spec](http://www.w3.org/TR/css3-color/#hsl-color).
515
517
  #
516
- # @param hue [Number] The hue of the color.
517
- # Should be between 0 and 360 degrees, inclusive
518
- # @param saturation [Number] The saturation of the color.
519
- # Must be between `0%` and `100%`, inclusive
520
- # @param lightness [Number] The lightness of the color.
521
- # Must be between `0%` and `100%`, inclusive
522
- # @return [Color] The resulting color
518
+ # @param hue [Sass::Script::Value::Number]
519
+ # The hue of the color. Should be between 0 and 360 degrees, inclusive
520
+ # @param saturation [Sass::Script::Value::Number]
521
+ # The saturation of the color. Must be between `0%` and `100%`, inclusive
522
+ # @param lightness [Sass::Script::Value::Number]
523
+ # The lightness of the color. Must be between `0%` and `100%`, inclusive
524
+ # @return [Sass::Script::Value::Color] The resulting color
523
525
  # @see #hsla
524
526
  # @raise [ArgumentError] if `saturation` or `lightness` are out of bounds
525
527
  def hsl(hue, saturation, lightness)
526
- hsla(hue, saturation, lightness, Number.new(1))
528
+ hsla(hue, saturation, lightness, Sass::Script::Value::Number.new(1))
527
529
  end
528
530
  declare :hsl, [:hue, :saturation, :lightness]
529
531
 
530
- # Creates a {Color} object from hue, saturation, and lightness,
531
- # as well as an alpha channel indicating opacity.
532
- # Uses the algorithm from the [CSS3 spec](http://www.w3.org/TR/css3-color/#hsl-color).
532
+ # Creates a {Sass::Script::Value::Color Color} object from hue, saturation,
533
+ # and lightness, as well as an alpha channel indicating opacity. Uses the
534
+ # algorithm from the [CSS3 spec](http://www.w3.org/TR/css3-color/#hsl-color).
533
535
  #
534
- # @param hue [Number] The hue of the color.
536
+ # @param hue [Sass::Script::Value::Number] The hue of the color.
535
537
  # Should be between 0 and 360 degrees, inclusive
536
- # @param saturation [Number] The saturation of the color.
538
+ # @param saturation [Sass::Script::Value::Number] The saturation of the color.
537
539
  # Must be between `0%` and `100%`, inclusive
538
- # @param lightness [Number] The lightness of the color.
540
+ # @param lightness [Sass::Script::Value::Number] The lightness of the color.
539
541
  # Must be between `0%` and `100%`, inclusive
540
- # @param alpha [Number] The opacity of the color.
542
+ # @param alpha [Sass::Script::Value::Number] The opacity of the color.
541
543
  # Must be between 0 and 1, inclusive
542
- # @return [Color] The resulting color
544
+ # @return [Sass::Script::Value::Color] The resulting color
543
545
  # @see #hsl
544
546
  # @raise [ArgumentError] if `saturation`, `lightness`, or `alpha` are out of bounds
545
547
  def hsla(hue, saturation, lightness, alpha)
@@ -554,40 +556,40 @@ module Sass::Script
554
556
  s = Sass::Util.check_range('Saturation', 0..100, saturation, '%')
555
557
  l = Sass::Util.check_range('Lightness', 0..100, lightness, '%')
556
558
 
557
- Color.new(:hue => h, :saturation => s, :lightness => l, :alpha => alpha.value)
559
+ Sass::Script::Value::Color.new(:hue => h, :saturation => s, :lightness => l, :alpha => alpha.value)
558
560
  end
559
561
  declare :hsla, [:hue, :saturation, :lightness, :alpha]
560
562
 
561
563
  # Returns the red component of a color.
562
564
  #
563
- # @param color [Color]
564
- # @return [Number]
565
+ # @param color [Sass::Script::Value::Color]
566
+ # @return [Sass::Script::Value::Number]
565
567
  # @raise [ArgumentError] If `color` isn't a color
566
568
  def red(color)
567
569
  assert_type color, :Color
568
- Sass::Script::Number.new(color.red)
570
+ Sass::Script::Value::Number.new(color.red)
569
571
  end
570
572
  declare :red, [:color]
571
573
 
572
574
  # Returns the green component of a color.
573
575
  #
574
- # @param color [Color]
575
- # @return [Number]
576
+ # @param color [Sass::Script::Value::Color]
577
+ # @return [Sass::Script::Value::Number]
576
578
  # @raise [ArgumentError] If `color` isn't a color
577
579
  def green(color)
578
580
  assert_type color, :Color
579
- Sass::Script::Number.new(color.green)
581
+ Sass::Script::Value::Number.new(color.green)
580
582
  end
581
583
  declare :green, [:color]
582
584
 
583
585
  # Returns the blue component of a color.
584
586
  #
585
- # @param color [Color]
586
- # @return [Number]
587
+ # @param color [Sass::Script::Value::Color]
588
+ # @return [Sass::Script::Value::Number]
587
589
  # @raise [ArgumentError] If `color` isn't a color
588
590
  def blue(color)
589
591
  assert_type color, :Color
590
- Sass::Script::Number.new(color.blue)
592
+ Sass::Script::Value::Number.new(color.blue)
591
593
  end
592
594
  declare :blue, [:color]
593
595
 
@@ -597,13 +599,13 @@ module Sass::Script
597
599
  #
598
600
  # Calculated from RGB where necessary via [this algorithm](http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV).
599
601
  #
600
- # @param color [Color]
601
- # @return [Number] between 0deg and 360deg
602
+ # @param color [Sass::Script::Value::Color]
603
+ # @return [Sass::Script::Value::Number] between 0deg and 360deg
602
604
  # @see #adjust_hue
603
605
  # @raise [ArgumentError] if `color` isn't a color
604
606
  def hue(color)
605
607
  assert_type color, :Color
606
- Sass::Script::Number.new(color.hue, ["deg"])
608
+ Sass::Script::Value::Number.new(color.hue, ["deg"])
607
609
  end
608
610
  declare :hue, [:color]
609
611
 
@@ -613,14 +615,14 @@ module Sass::Script
613
615
  #
614
616
  # Calculated from RGB where necessary via [this algorithm](http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV).
615
617
  #
616
- # @param color [Color]
617
- # @return [Number] between 0% and 100%
618
+ # @param color [Sass::Script::Value::Color]
619
+ # @return [Sass::Script::Value::Number] between 0% and 100%
618
620
  # @see #saturate
619
621
  # @see #desaturate
620
622
  # @raise [ArgumentError] if `color` isn't a color
621
623
  def saturation(color)
622
624
  assert_type color, :Color
623
- Sass::Script::Number.new(color.saturation, ["%"])
625
+ Sass::Script::Value::Number.new(color.saturation, ["%"])
624
626
  end
625
627
  declare :saturation, [:color]
626
628
 
@@ -630,14 +632,14 @@ module Sass::Script
630
632
  #
631
633
  # Calculated from RGB where necessary via [this algorithm](http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV).
632
634
  #
633
- # @param color [Color]
634
- # @return [Number] between 0% and 100%
635
+ # @param color [Sass::Script::Value::Color]
636
+ # @return [Sass::Script::Value::Number] between 0% and 100%
635
637
  # @see #lighten
636
638
  # @see #darken
637
639
  # @raise [ArgumentError] if `color` isn't a color
638
640
  def lightness(color)
639
641
  assert_type color, :Color
640
- Sass::Script::Number.new(color.lightness, ["%"])
642
+ Sass::Script::Value::Number.new(color.lightness, ["%"])
641
643
  end
642
644
  declare :lightness, [:color]
643
645
 
@@ -648,39 +650,41 @@ module Sass::Script
648
650
  # `alpha(opacity=20)` syntax.
649
651
  #
650
652
  # @overload def alpha(color)
651
- # @param color [Color]
652
- # @return [Number]
653
+ # @param color [Sass::Script::Value::Color]
654
+ # @return [Sass::Script::Value::Number]
653
655
  # @see #opacify
654
656
  # @see #transparentize
655
657
  # @raise [ArgumentError] If `color` isn't a color
656
658
  def alpha(*args)
657
659
  if args.all? do |a|
658
- a.is_a?(Sass::Script::String) && a.type == :identifier &&
660
+ a.is_a?(Sass::Script::Value::String) && a.type == :identifier &&
659
661
  a.value =~ /^[a-zA-Z]+\s*=/
660
662
  end
661
663
  # Support the proprietary MS alpha() function
662
- return Sass::Script::String.new("alpha(#{args.map {|a| a.to_s}.join(", ")})")
664
+ return Sass::Script::Value::String.new("alpha(#{args.map {|a| a.to_s}.join(", ")})")
663
665
  end
664
666
 
665
667
  raise ArgumentError.new("wrong number of arguments (#{args.size} for 1)") if args.size != 1
666
668
 
667
669
  assert_type args.first, :Color
668
- Sass::Script::Number.new(args.first.alpha)
670
+ Sass::Script::Value::Number.new(args.first.alpha)
669
671
  end
670
672
  declare :alpha, [:color]
671
673
 
672
674
  # Returns the alpha component (opacity) of a color.
673
675
  # This is 1 unless otherwise specified.
674
676
  #
675
- # @param color [Color]
676
- # @return [Number]
677
+ # @param color [Sass::Script::Value::Color]
678
+ # @return [Sass::Script::Value::Number]
677
679
  # @see #opacify
678
680
  # @see #transparentize
679
681
  # @raise [ArgumentError] If `color` isn't a color
680
682
  def opacity(color)
681
- return Sass::Script::String.new("opacity(#{color})") if color.is_a?(Sass::Script::Number)
683
+ if color.is_a?(Sass::Script::Value::Number)
684
+ return Sass::Script::Value::String.new("opacity(#{color})")
685
+ end
682
686
  assert_type color, :Color
683
- Sass::Script::Number.new(color.alpha)
687
+ Sass::Script::Value::Number.new(color.alpha)
684
688
  end
685
689
  declare :opacity, [:color]
686
690
 
@@ -691,9 +695,9 @@ module Sass::Script
691
695
  # @example
692
696
  # opacify(rgba(0, 0, 0, 0.5), 0.1) => rgba(0, 0, 0, 0.6)
693
697
  # opacify(rgba(0, 0, 17, 0.8), 0.2) => #001
694
- # @param color [Color]
695
- # @param amount [Number]
696
- # @return [Color]
698
+ # @param color [Sass::Script::Value::Color]
699
+ # @param amount [Sass::Script::Value::Number]
700
+ # @return [Sass::Script::Value::Color]
697
701
  # @see #transparentize
698
702
  # @raise [ArgumentError] If `color` isn't a color,
699
703
  # or `number` isn't a number between 0 and 1
@@ -712,9 +716,9 @@ module Sass::Script
712
716
  # @example
713
717
  # transparentize(rgba(0, 0, 0, 0.5), 0.1) => rgba(0, 0, 0, 0.4)
714
718
  # transparentize(rgba(0, 0, 0, 0.8), 0.2) => rgba(0, 0, 0, 0.6)
715
- # @param color [Color]
716
- # @param amount [Number]
717
- # @return [Color]
719
+ # @param color [Sass::Script::Value::Color]
720
+ # @param amount [Sass::Script::Value::Number]
721
+ # @return [Sass::Script::Value::Color]
718
722
  # @see #opacify
719
723
  # @raise [ArgumentError] If `color` isn't a color,
720
724
  # or `number` isn't a number between 0 and 1
@@ -733,9 +737,9 @@ module Sass::Script
733
737
  # @example
734
738
  # lighten(hsl(0, 0%, 0%), 30%) => hsl(0, 0, 30)
735
739
  # lighten(#800, 20%) => #e00
736
- # @param color [Color]
737
- # @param amount [Number]
738
- # @return [Color]
740
+ # @param color [Sass::Script::Value::Color]
741
+ # @param amount [Sass::Script::Value::Number]
742
+ # @return [Sass::Script::Value::Color]
739
743
  # @see #darken
740
744
  # @raise [ArgumentError] If `color` isn't a color,
741
745
  # or `number` isn't a number between 0% and 100%
@@ -751,9 +755,9 @@ module Sass::Script
751
755
  # @example
752
756
  # darken(hsl(25, 100%, 80%), 30%) => hsl(25, 100%, 50%)
753
757
  # darken(#800, 20%) => #200
754
- # @param color [Color]
755
- # @param amount [Number]
756
- # @return [Color]
758
+ # @param color [Sass::Script::Value::Color]
759
+ # @param amount [Sass::Script::Value::Number]
760
+ # @return [Sass::Script::Value::Color]
757
761
  # @see #lighten
758
762
  # @raise [ArgumentError] If `color` isn't a color,
759
763
  # or `number` isn't a number between 0% and 100%
@@ -770,16 +774,16 @@ module Sass::Script
770
774
  # saturate(hsl(120, 30%, 90%), 20%) => hsl(120, 50%, 90%)
771
775
  # saturate(#855, 20%) => #9e3f3f
772
776
  # @overload saturate(color, amount)
773
- # @param color [Color]
774
- # @param amount [Number]
775
- # @return [Color]
777
+ # @param color [Sass::Script::Value::Color]
778
+ # @param amount [Sass::Script::Value::Number]
779
+ # @return [Sass::Script::Value::Color]
776
780
  # @see #desaturate
777
781
  # @raise [ArgumentError] If `color` isn't a color,
778
782
  # or `number` isn't a number between 0% and 100%
779
783
  def saturate(color, amount = nil)
780
784
  # Support the filter effects definition of saturate.
781
785
  # https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html
782
- return Sass::Script::String.new("saturate(#{color})") if amount.nil?
786
+ return Sass::Script::Value::String.new("saturate(#{color})") if amount.nil?
783
787
  _adjust(color, amount, :saturation, 0..100, :+, "%")
784
788
  end
785
789
  declare :saturate, [:color, :amount]
@@ -792,9 +796,9 @@ module Sass::Script
792
796
  # @example
793
797
  # desaturate(hsl(120, 30%, 90%), 20%) => hsl(120, 10%, 90%)
794
798
  # desaturate(#855, 20%) => #726b6b
795
- # @param color [Color]
796
- # @param amount [Number]
797
- # @return [Color]
799
+ # @param color [Sass::Script::Value::Color]
800
+ # @param amount [Sass::Script::Value::Number]
801
+ # @return [Sass::Script::Value::Color]
798
802
  # @see #saturate
799
803
  # @raise [ArgumentError] If `color` isn't a color,
800
804
  # or `number` isn't a number between 0% and 100%
@@ -811,9 +815,9 @@ module Sass::Script
811
815
  # adjust-hue(hsl(120, 30%, 90%), 60deg) => hsl(180, 30%, 90%)
812
816
  # adjust-hue(hsl(120, 30%, 90%), 060deg) => hsl(60, 30%, 90%)
813
817
  # adjust-hue(#811, 45deg) => #886a11
814
- # @param color [Color]
815
- # @param amount [Number]
816
- # @return [Color]
818
+ # @param color [Sass::Script::Value::Color]
819
+ # @param amount [Sass::Script::Value::Number]
820
+ # @return [Sass::Script::Value::Color]
817
821
  # @raise [ArgumentError] If `color` isn't a color, or `number` isn't a number
818
822
  def adjust_hue(color, degrees)
819
823
  assert_type color, :Color
@@ -829,13 +833,13 @@ module Sass::Script
829
833
  # ie-hex-str(#abc) => #FFAABBCC
830
834
  # ie-hex-str(#3322BB) => #FF3322BB
831
835
  # ie-hex-str(rgba(0, 255, 0, 0.5)) => #8000FF00
832
- # @param color [Color]
833
- # @return [String]
836
+ # @param color [Sass::Script::Value::Color]
837
+ # @return [Sass::Script::Value::String]
834
838
  # @raise [ArgumentError] If `color` isn't a color
835
839
  def ie_hex_str(color)
836
840
  assert_type color, :Color
837
841
  alpha = (color.alpha * 255).round.to_s(16).rjust(2, '0')
838
- Sass::Script::String.new("##{alpha}#{color.send(:hex_str)[1..-1]}".upcase)
842
+ Sass::Script::Value::String.new("##{alpha}#{color.send(:hex_str)[1..-1]}".upcase)
839
843
  end
840
844
  declare :ie_hex_str, [:color]
841
845
 
@@ -856,15 +860,15 @@ module Sass::Script
856
860
  # adjust-color(#102030, $blue: 5) => #102035
857
861
  # adjust-color(#102030, $red: -5, $blue: 5) => #0b2035
858
862
  # adjust-color(hsl(25, 100%, 80%), $lightness: -30%, $alpha: -0.4) => hsla(25, 100%, 50%, 0.6)
859
- # @param color [Color]
860
- # @param red [Number]
861
- # @param green [Number]
862
- # @param blue [Number]
863
- # @param hue [Number]
864
- # @param saturation [Number]
865
- # @param lightness [Number]
866
- # @param alpha [Number]
867
- # @return [Color]
863
+ # @param color [Sass::Script::Value::Color]
864
+ # @param red [Sass::Script::Value::Number]
865
+ # @param green [Sass::Script::Value::Number]
866
+ # @param blue [Sass::Script::Value::Number]
867
+ # @param hue [Sass::Script::Value::Number]
868
+ # @param saturation [Sass::Script::Value::Number]
869
+ # @param lightness [Sass::Script::Value::Number]
870
+ # @param alpha [Sass::Script::Value::Number]
871
+ # @return [Sass::Script::Value::Color]
868
872
  # @raise [ArgumentError] if `color` is not a color,
869
873
  # if any keyword argument is not a number,
870
874
  # if any keyword argument is not in the legal range,
@@ -926,14 +930,14 @@ module Sass::Script
926
930
  # scale-color(hsl(120, 70, 80), $lightness: 50%) => hsl(120, 70, 90)
927
931
  # scale-color(rgb(200, 150, 170), $green: -40%, $blue: 70%) => rgb(200, 90, 229)
928
932
  # scale-color(hsl(200, 70, 80), $saturation: -90%, $alpha: -30%) => hsla(200, 7, 80, 0.7)
929
- # @param color [Color]
930
- # @param red [Number]
931
- # @param green [Number]
932
- # @param blue [Number]
933
- # @param saturation [Number]
934
- # @param lightness [Number]
935
- # @param alpha [Number]
936
- # @return [Color]
933
+ # @param color [Sass::Script::Value::Color]
934
+ # @param red [Sass::Script::Value::Number]
935
+ # @param green [Sass::Script::Value::Number]
936
+ # @param blue [Sass::Script::Value::Number]
937
+ # @param saturation [Sass::Script::Value::Number]
938
+ # @param lightness [Sass::Script::Value::Number]
939
+ # @param alpha [Sass::Script::Value::Number]
940
+ # @return [Sass::Script::Value::Color]
937
941
  # @raise [ArgumentError] if `color` is not a color,
938
942
  # if any keyword argument is not a percentage between 0% and 100%,
939
943
  # if an unexpected keyword argument is given,
@@ -986,15 +990,15 @@ module Sass::Script
986
990
  # change-color(#102030, $blue: 5) => #102005
987
991
  # change-color(#102030, $red: 120, $blue: 5) => #782005
988
992
  # change-color(hsl(25, 100%, 80%), $lightness: 40%, $alpha: 0.8) => hsla(25, 100%, 40%, 0.8)
989
- # @param color [Color]
990
- # @param red [Number]
991
- # @param green [Number]
992
- # @param blue [Number]
993
- # @param hue [Number]
994
- # @param saturation [Number]
995
- # @param lightness [Number]
996
- # @param alpha [Number]
997
- # @return [Color]
993
+ # @param color [Sass::Script::Value::Color]
994
+ # @param red [Sass::Script::Value::Number]
995
+ # @param green [Sass::Script::Value::Number]
996
+ # @param blue [Sass::Script::Value::Number]
997
+ # @param hue [Sass::Script::Value::Number]
998
+ # @param saturation [Sass::Script::Value::Number]
999
+ # @param lightness [Sass::Script::Value::Number]
1000
+ # @param alpha [Sass::Script::Value::Number]
1001
+ # @return [Sass::Script::Value::Color]
998
1002
  # @raise [ArgumentError] if `color` is not a color,
999
1003
  # if any keyword argument is not a number,
1000
1004
  # if any keyword argument is not in the legal range,
@@ -1034,13 +1038,13 @@ module Sass::Script
1034
1038
  # mix(#f00, #00f, 25%) => #3f00bf
1035
1039
  # mix(rgba(255, 0, 0, 0.5), #00f) => rgba(63, 0, 191, 0.75)
1036
1040
  # @overload mix(color1, color2, weight: 50%)
1037
- # @param color1 [Color]
1038
- # @param color2 [Color]
1039
- # @param weight [Number] between 0% and 100%
1040
- # @return [Color]
1041
+ # @param color1 [Sass::Script::Value::Color]
1042
+ # @param color2 [Sass::Script::Value::Color]
1043
+ # @param weight [Sass::Script::Value::Number] between 0% and 100%
1044
+ # @return [Sass::Script::Value::Color]
1041
1045
  # @raise [ArgumentError] if `color1` or `color2` aren't colors,
1042
1046
  # or `weight` isn't a number between 0% and 100%
1043
- def mix(color1, color2, weight = Number.new(50))
1047
+ def mix(color1, color2, weight = Sass::Script::Value::Number.new(50))
1044
1048
  assert_type color1, :Color
1045
1049
  assert_type color2, :Color
1046
1050
  assert_type weight, :Number
@@ -1075,7 +1079,7 @@ module Sass::Script
1075
1079
 
1076
1080
  rgb = color1.rgb.zip(color2.rgb).map {|v1, v2| v1*w1 + v2*w2}
1077
1081
  alpha = color1.alpha*p + color2.alpha*(1-p)
1078
- Color.new(rgb + [alpha])
1082
+ Sass::Script::Value::Color.new(rgb + [alpha])
1079
1083
  end
1080
1084
  declare :mix, [:color_1, :color_2]
1081
1085
  declare :mix, [:color_1, :color_2, :weight]
@@ -1083,36 +1087,40 @@ module Sass::Script
1083
1087
  # Converts a color to grayscale.
1084
1088
  # This is identical to `desaturate(color, 100%)`.
1085
1089
  #
1086
- # @param color [Color]
1087
- # @return [Color]
1090
+ # @param color [Sass::Script::Value::Color]
1091
+ # @return [Sass::Script::Value::Color]
1088
1092
  # @raise [ArgumentError] if `color` isn't a color
1089
1093
  # @see #desaturate
1090
1094
  def grayscale(color)
1091
- return Sass::Script::String.new("grayscale(#{color})") if color.is_a?(Sass::Script::Number)
1092
- desaturate color, Number.new(100)
1095
+ if color.is_a?(Sass::Script::Value::Number)
1096
+ return Sass::Script::Value::String.new("grayscale(#{color})")
1097
+ end
1098
+ desaturate color, Sass::Script::Value::Number.new(100)
1093
1099
  end
1094
1100
  declare :grayscale, [:color]
1095
1101
 
1096
1102
  # Returns the complement of a color.
1097
1103
  # This is identical to `adjust-hue(color, 180deg)`.
1098
1104
  #
1099
- # @param color [Color]
1100
- # @return [Color]
1105
+ # @param color [Sass::Script::Value::Color]
1106
+ # @return [Sass::Script::Value::Color]
1101
1107
  # @raise [ArgumentError] if `color` isn't a color
1102
1108
  # @see #adjust_hue #adjust-hue
1103
1109
  def complement(color)
1104
- adjust_hue color, Number.new(180)
1110
+ adjust_hue color, Sass::Script::Value::Number.new(180)
1105
1111
  end
1106
1112
  declare :complement, [:color]
1107
1113
 
1108
1114
  # Returns the inverse (negative) of a color.
1109
1115
  # The red, green, and blue values are inverted, while the opacity is left alone.
1110
1116
  #
1111
- # @param color [Color]
1112
- # @return [Color]
1117
+ # @param color [Sass::Script::Value::Color]
1118
+ # @return [Sass::Script::Value::Color]
1113
1119
  # @raise [ArgumentError] if `color` isn't a color
1114
1120
  def invert(color)
1115
- return Sass::Script::String.new("invert(#{color})") if color.is_a?(Sass::Script::Number)
1121
+ if color.is_a?(Sass::Script::Value::Number)
1122
+ return Sass::Script::Value::String.new("invert(#{color})")
1123
+ end
1116
1124
 
1117
1125
  assert_type color, :Color
1118
1126
  color.with(
@@ -1125,16 +1133,16 @@ module Sass::Script
1125
1133
  # Removes quotes from a string if the string is quoted,
1126
1134
  # or returns the same string if it's not.
1127
1135
  #
1128
- # @param string [String]
1129
- # @return [String]
1136
+ # @param string [Sass::Script::Value::String]
1137
+ # @return [Sass::Script::Value::String]
1130
1138
  # @raise [ArgumentError] if `string` isn't a string
1131
1139
  # @see #quote
1132
1140
  # @example
1133
1141
  # unquote("foo") => foo
1134
1142
  # unquote(foo) => foo
1135
1143
  def unquote(string)
1136
- if string.is_a?(Sass::Script::String)
1137
- Sass::Script::String.new(string.value, :identifier)
1144
+ if string.is_a?(Sass::Script::Value::String)
1145
+ Sass::Script::Value::String.new(string.value, :identifier)
1138
1146
  else
1139
1147
  string
1140
1148
  end
@@ -1144,8 +1152,8 @@ module Sass::Script
1144
1152
  # Add quotes to a string if the string isn't quoted,
1145
1153
  # or returns the same string if it is.
1146
1154
  #
1147
- # @param string [String]
1148
- # @return [String]
1155
+ # @param string [Sass::Script::Value::String]
1156
+ # @return [Sass::Script::Value::String]
1149
1157
  # @raise [ArgumentError] if `string` isn't a string
1150
1158
  # @see #unquote
1151
1159
  # @example
@@ -1153,19 +1161,19 @@ module Sass::Script
1153
1161
  # quote(foo) => "foo"
1154
1162
  def quote(string)
1155
1163
  assert_type string, :String
1156
- Sass::Script::String.new(string.value, :string)
1164
+ Sass::Script::Value::String.new(string.value, :string)
1157
1165
  end
1158
1166
  declare :quote, [:string]
1159
1167
 
1160
1168
  # Returns the number of characters in a string.
1161
1169
  #
1162
- # @return [Number]
1170
+ # @return [Sass::Script::Value::Number]
1163
1171
  # @raise [ArgumentError] if `string` isn't a string
1164
1172
  # @example
1165
1173
  # str-length("foo") => 3
1166
1174
  def str_length(string)
1167
1175
  assert_type string, :String
1168
- Sass::Script::Number.new(string.value.size)
1176
+ Sass::Script::Value::Number.new(string.value.size)
1169
1177
  end
1170
1178
  declare :str_length, [:string]
1171
1179
 
@@ -1174,13 +1182,15 @@ module Sass::Script
1174
1182
  # Inserts the `$insert` string into the `$original` before the character at
1175
1183
  # the given `$index`.
1176
1184
  #
1177
- # @param [String] original The string that will receive the insertion.
1178
- # @param [String] insert The string that will be inserted.
1179
- # @param [Number] index
1185
+ # @param original [Sass::Script::Value::String]
1186
+ # The string that will receive the insertion.
1187
+ # @param insert [Sass::Script::Value::String]
1188
+ # The string that will be inserted.
1189
+ # @param index [Sass::Script::Value::Number]
1180
1190
  # The position where inserted string will start.
1181
1191
  # Negative indices count from the end of the original string.
1182
1192
  #
1183
- # @return [String] A new string
1193
+ # @return [Sass::Script::Value::String] A new string
1184
1194
  # @raise [ArgumentError] if `$original` isn't a string, `$insert` isn't a string, or `$index` isn't a number.
1185
1195
  # @example
1186
1196
  # str-insert("abcd", "X", 1) => "Xabcd"
@@ -1193,14 +1203,14 @@ module Sass::Script
1193
1203
  assert_integer index, "index"
1194
1204
  assert_unit index, nil, "index"
1195
1205
  insertion_point = index.value > 0 ? [index.value - 1, original.value.size].min : [index.value, -original.value.size - 1].max
1196
- Sass::Script::String.new(original.value.dup.insert(insertion_point, insert.value), original.type)
1206
+ Sass::Script::Value::String.new(original.value.dup.insert(insertion_point, insert.value), original.type)
1197
1207
  end
1198
1208
  declare :str_insert, [:original, :insert, :index]
1199
1209
 
1200
1210
  # Starting at the left, finds the index of the first location
1201
1211
  # where `substring` is found in `string`.
1202
1212
  #
1203
- # @return [Number] The index of the substring, or 0 if not found.
1213
+ # @return [Sass::Script::Value::Number] The index of the substring, or 0 if not found.
1204
1214
  # @raise [ArgumentError] if `original` isn't a string, `insert` isn't a string, or `index` isn't a number.
1205
1215
  # @param string The string to search
1206
1216
  # @param substring The string to search for
@@ -1213,14 +1223,14 @@ module Sass::Script
1213
1223
  assert_type string, :String
1214
1224
  assert_type substring, :String
1215
1225
  index = string.value.index(substring.value) || -1
1216
- Sass::Script::Number.new(index + 1)
1226
+ Sass::Script::Value::Number.new(index + 1)
1217
1227
  end
1218
1228
  declare :str_index, [:string, :substring]
1219
1229
 
1220
1230
 
1221
1231
  # Slice a substring from `string` from `start-at` index to `end-at` index.
1222
1232
  #
1223
- # @return [String] A new string
1233
+ # @return [Sass::Script::Value::String] A new string
1224
1234
  # @param start_at
1225
1235
  # The index (inclusive) of the first character to slice out of the string.
1226
1236
  # If negative, counts from the end of the string.
@@ -1248,7 +1258,7 @@ module Sass::Script
1248
1258
  assert_type string, :String
1249
1259
  assert_unit start_at, nil, "start-at"
1250
1260
 
1251
- end_at = Sass::Script::Number.new(-1)if end_at.nil?
1261
+ end_at = Sass::Script::Value::Number.new(-1)if end_at.nil?
1252
1262
  assert_unit end_at, nil, "end-at"
1253
1263
 
1254
1264
  s = start_at.value > 0 ? start_at.value - 1 : start_at.value
@@ -1258,34 +1268,34 @@ module Sass::Script
1258
1268
  e = string.value.length + e if e < 0
1259
1269
  e = 0 if s < 0
1260
1270
  extracted = string.value.slice(s..e)
1261
- Sass::Script::String.new(extracted || "", string.type)
1271
+ Sass::Script::Value::String.new(extracted || "", string.type)
1262
1272
  end
1263
1273
  declare :str_slice, [:string, :start_at]
1264
1274
  declare :str_slice, [:string, :start_at, :end_at]
1265
1275
 
1266
1276
  # Convert a string to upper case
1267
1277
  #
1268
- # @return [String]
1278
+ # @return [Sass::Script::Value::String]
1269
1279
  # @raise [ArgumentError] if `string` isn't a string
1270
1280
  # @example
1271
1281
  # to-upper-case(abcd) => ABCD
1272
1282
  # to-upper-case("abcd") => "ABCD"
1273
1283
  def to_upper_case(string)
1274
1284
  assert_type string, :String
1275
- Sass::Script::String.new(string.value.upcase, string.type)
1285
+ Sass::Script::Value::String.new(string.value.upcase, string.type)
1276
1286
  end
1277
1287
  declare :to_upper_case, [:string]
1278
1288
 
1279
1289
  # Convert a string to lower case
1280
1290
  #
1281
- # @return [String]
1291
+ # @return [Sass::Script::Value::String]
1282
1292
  # @raise [ArgumentError] if `string` isn't a string
1283
1293
  # @example
1284
1294
  # to-lower-case(ABCD) => abcd
1285
1295
  # to-lower-case("ABCD") => "abcd"
1286
1296
  def to_lower_case(string)
1287
1297
  assert_type string, :String
1288
- Sass::Script::String.new(string.value.downcase, string.type)
1298
+ Sass::Script::Value::String.new(string.value.downcase, string.type)
1289
1299
  end
1290
1300
  declare :to_lower_case, [:string]
1291
1301
 
@@ -1298,10 +1308,10 @@ module Sass::Script
1298
1308
  # type-of(true) => bool
1299
1309
  # type-of(#fff) => color
1300
1310
  # type-of(blue) => color
1301
- # @param value [Literal] The object to inspect
1302
- # @return [String] The unquoted string name of the literal's type
1311
+ # @param value [Value] The object to inspect
1312
+ # @return [Sass::Script::Value::String] The unquoted string name of the value's type
1303
1313
  def type_of(value)
1304
- Sass::Script::String.new(value.class.name.gsub(/Sass::Script::/,'').downcase)
1314
+ Sass::Script::Value::String.new(value.class.name.gsub(/Sass::Script::Value::/,'').downcase)
1305
1315
  end
1306
1316
  declare :type_of, [:value]
1307
1317
 
@@ -1314,12 +1324,12 @@ module Sass::Script
1314
1324
  # unit(3em) => "em"
1315
1325
  # unit(10px * 5em) => "em*px"
1316
1326
  # unit(10px * 5em / 30cm / 1rem) => "em*px/cm*rem"
1317
- # @param number [Literal] The number to inspect
1318
- # @return [String] The unit(s) of the number
1327
+ # @param number [Value] The number to inspect
1328
+ # @return [Sass::Script::Value::String] The unit(s) of the number
1319
1329
  # @raise [ArgumentError] if `number` isn't a number
1320
1330
  def unit(number)
1321
1331
  assert_type number, :Number
1322
- Sass::Script::String.new(number.unit_str, :string)
1332
+ Sass::Script::Value::String.new(number.unit_str, :string)
1323
1333
  end
1324
1334
  declare :unit, [:number]
1325
1335
 
@@ -1328,12 +1338,12 @@ module Sass::Script
1328
1338
  # @example
1329
1339
  # unitless(100) => true
1330
1340
  # unitless(100px) => false
1331
- # @param number [Literal] The number to inspect
1332
- # @return [Bool] Whether or not the number is unitless
1341
+ # @param number [Value] The number to inspect
1342
+ # @return [Sass::Script::Value::Bool] Whether or not the number is unitless
1333
1343
  # @raise [ArgumentError] if `number` isn't a number
1334
1344
  def unitless(number)
1335
1345
  assert_type number, :Number
1336
- Sass::Script::Bool.new(number.unitless?)
1346
+ Sass::Script::Value::Bool.new(number.unitless?)
1337
1347
  end
1338
1348
  declare :unitless, [:number]
1339
1349
 
@@ -1343,14 +1353,14 @@ module Sass::Script
1343
1353
  # comparable(2px, 1px) => true
1344
1354
  # comparable(100px, 3em) => false
1345
1355
  # comparable(10cm, 3mm) => true
1346
- # @param number_1 [Number]
1347
- # @param number_2 [Number]
1348
- # @return [Bool] indicating if the numbers can be compared.
1356
+ # @param number_1 [Sass::Script::Value::Number]
1357
+ # @param number_2 [Sass::Script::Value::Number]
1358
+ # @return [Sass::Script::Value::Bool] indicating if the numbers can be compared.
1349
1359
  # @raise [ArgumentError] if `number_1` or `number_2` aren't numbers
1350
1360
  def comparable(number_1, number_2)
1351
1361
  assert_type number_1, :Number
1352
1362
  assert_type number_2, :Number
1353
- Sass::Script::Bool.new(number_1.comparable_to?(number_2))
1363
+ Sass::Script::Value::Bool.new(number_1.comparable_to?(number_2))
1354
1364
  end
1355
1365
  declare :comparable, [:number_1, :number_2]
1356
1366
 
@@ -1358,14 +1368,15 @@ module Sass::Script
1358
1368
  #
1359
1369
  # @example
1360
1370
  # percentage(100px / 50px) => 200%
1361
- # @param value [Number] The decimal number to convert to a percentage
1362
- # @return [Number] The percentage
1371
+ # @param value [Sass::Script::Value::Number]
1372
+ # The decimal number to convert to a percentage
1373
+ # @return [Sass::Script::Value::Number] The percentage
1363
1374
  # @raise [ArgumentError] If `value` isn't a unitless number
1364
1375
  def percentage(value)
1365
- unless value.is_a?(Sass::Script::Number) && value.unitless?
1376
+ unless value.is_a?(Sass::Script::Value::Number) && value.unitless?
1366
1377
  raise ArgumentError.new("#{value.inspect} is not a unitless number")
1367
1378
  end
1368
- Sass::Script::Number.new(value.value * 100, ['%'])
1379
+ Sass::Script::Value::Number.new(value.value * 100, ['%'])
1369
1380
  end
1370
1381
  declare :percentage, [:value]
1371
1382
 
@@ -1374,8 +1385,8 @@ module Sass::Script
1374
1385
  # @example
1375
1386
  # round(10.4px) => 10px
1376
1387
  # round(10.6px) => 11px
1377
- # @param value [Number] The number
1378
- # @return [Number] The rounded number
1388
+ # @param value [Sass::Script::Value::Number] The number
1389
+ # @return [Sass::Script::Value::Number] The rounded number
1379
1390
  # @raise [ArgumentError] if `value` isn't a number
1380
1391
  def round(value)
1381
1392
  numeric_transformation(value) {|n| n.round}
@@ -1387,8 +1398,8 @@ module Sass::Script
1387
1398
  # @example
1388
1399
  # ceil(10.4px) => 11px
1389
1400
  # ceil(10.6px) => 11px
1390
- # @param value [Number] The number
1391
- # @return [Number] The rounded number
1401
+ # @param value [Sass::Script::Value::Number] The number
1402
+ # @return [Sass::Script::Value::Number] The rounded number
1392
1403
  # @raise [ArgumentError] if `value` isn't a number
1393
1404
  def ceil(value)
1394
1405
  numeric_transformation(value) {|n| n.ceil}
@@ -1400,8 +1411,8 @@ module Sass::Script
1400
1411
  # @example
1401
1412
  # floor(10.4px) => 10px
1402
1413
  # floor(10.6px) => 10px
1403
- # @param value [Number] The number
1404
- # @return [Number] The rounded number
1414
+ # @param value [Sass::Script::Value::Number] The number
1415
+ # @return [Sass::Script::Value::Number] The rounded number
1405
1416
  # @raise [ArgumentError] if `value` isn't a number
1406
1417
  def floor(value)
1407
1418
  numeric_transformation(value) {|n| n.floor}
@@ -1413,8 +1424,8 @@ module Sass::Script
1413
1424
  # @example
1414
1425
  # abs(10px) => 10px
1415
1426
  # abs(-10px) => 10px
1416
- # @param value [Number] The number
1417
- # @return [Number] The absolute value
1427
+ # @param value [Sass::Script::Value::Number] The number
1428
+ # @return [Sass::Script::Value::Number] The absolute value
1418
1429
  # @raise [ArgumentError] if `value` isn't a number
1419
1430
  def abs(value)
1420
1431
  numeric_transformation(value) {|n| n.abs}
@@ -1427,8 +1438,8 @@ module Sass::Script
1427
1438
  # @example
1428
1439
  # min(1px, 4px) => 1px
1429
1440
  # min(5em, 3em, 4em) => 3em
1430
- # @param values [[Number]] The numbers
1431
- # @return [Number] The minimum value
1441
+ # @param values [Array<Sass::Script::Value::Number>] The numbers
1442
+ # @return [Sass::Script::Value::Number] The minimum value
1432
1443
  # @raise [ArgumentError] if any argument isn't a number, or if not all of
1433
1444
  # the arguments have comparable units
1434
1445
  def min(*values)
@@ -1443,7 +1454,7 @@ module Sass::Script
1443
1454
  # @example
1444
1455
  # max(1px, 4px) => 4px
1445
1456
  # max(5em, 3em, 4em) => 5em
1446
- # @return [Number] The maximum value
1457
+ # @return [Sass::Script::Value::Number] The maximum value
1447
1458
  # @raise [ArgumentError] if any argument isn't a number, or if not all of
1448
1459
  # the arguments have comparable units
1449
1460
  def max(*values)
@@ -1457,10 +1468,10 @@ module Sass::Script
1457
1468
  # @example
1458
1469
  # length(10px) => 1
1459
1470
  # length(10px 20px 30px) => 3
1460
- # @param list [Literal] The list
1461
- # @return [Number] The length
1471
+ # @param list [Value] The list
1472
+ # @return [Sass::Script::Value::Number] The length
1462
1473
  def length(list)
1463
- Sass::Script::Number.new(list.to_a.size)
1474
+ Sass::Script::Value::Number.new(list.to_a.size)
1464
1475
  end
1465
1476
  declare :length, [:list]
1466
1477
 
@@ -1472,9 +1483,9 @@ module Sass::Script
1472
1483
  # @example
1473
1484
  # nth(10px 20px 30px, 1) => 10px
1474
1485
  # nth((Helvetica, Arial, sans-serif), 3) => sans-serif
1475
- # @param list [Literal] The list
1476
- # @param n [Number] The index into the list
1477
- # @return [Literal] The nth item in the list
1486
+ # @param list [Value] The list
1487
+ # @param n [Sass::Script::Value::Number] The index into the list
1488
+ # @return [Sass::Script::Value::Base] The nth item in the list
1478
1489
  # @raise [ArgumentError] If `n` isn't an integer between 1 and the list's length.
1479
1490
  def nth(list, n)
1480
1491
  assert_type n, :Number
@@ -1506,19 +1517,20 @@ module Sass::Script
1506
1517
  # join(10px, 20px, comma) => 10px, 20px
1507
1518
  # join((blue, red), (#abc, #def), space) => blue red #abc #def
1508
1519
  # @overload join(list1, list2, separator: auto)
1509
- # @param list1 [Literal] The first list to join
1510
- # @param list2 [Literal] The second list to join
1511
- # @param separator [String] How the list separator (comma or space) should be determined.
1512
- # If this is `comma` or `space`, that is always the separator;
1513
- # if this is `auto` (the default), the separator is determined as explained above.
1514
- def join(list1, list2, separator = Sass::Script::String.new("auto"))
1520
+ # @param list1 [Value] The first list to join
1521
+ # @param list2 [Value] The second list to join
1522
+ # @param separator [Sass::Script::Value::String]
1523
+ # How the list separator (comma or space) should be determined. If this
1524
+ # is `comma` or `space`, that is always the separator; if this is `auto`
1525
+ # (the default), the separator is determined as explained above.
1526
+ def join(list1, list2, separator = Sass::Script::Value::String.new("auto"))
1515
1527
  assert_type separator, :String
1516
1528
  unless %w[auto space comma].include?(separator.value)
1517
1529
  raise ArgumentError.new("Separator name must be space, comma, or auto")
1518
1530
  end
1519
- sep1 = list1.separator if list1.is_a?(Sass::Script::List) && !list1.value.empty?
1520
- sep2 = list2.separator if list2.is_a?(Sass::Script::List) && !list2.value.empty?
1521
- Sass::Script::List.new(
1531
+ sep1 = list1.separator if list1.is_a?(Sass::Script::Value::List) && !list1.value.empty?
1532
+ sep2 = list2.separator if list2.is_a?(Sass::Script::Value::List) && !list2.value.empty?
1533
+ Sass::Script::Value::List.new(
1522
1534
  list1.to_a + list2.to_a,
1523
1535
  if separator.value == 'auto'
1524
1536
  sep1 || sep2 || :space
@@ -1542,18 +1554,19 @@ module Sass::Script
1542
1554
  # append(10px, 20px, comma) => 10px, 20px
1543
1555
  # append((blue, red), green, space) => blue red green
1544
1556
  # @overload append(list, val, separator: auto)
1545
- # @param list [Literal] The list to add the value to
1546
- # @param val [Literal] The value to add to the end of the list
1547
- # @param separator [String] How the list separator (comma or space) should be determined.
1548
- # If this is `comma` or `space`, that is always the separator;
1549
- # if this is `auto` (the default), the separator is the same as that used by the list.
1550
- def append(list, val, separator = Sass::Script::String.new("auto"))
1557
+ # @param list [Value] The list to add the value to
1558
+ # @param val [Value] The value to add to the end of the list
1559
+ # @param separator [Sass::Script::Value::String]
1560
+ # How the list separator (comma or space) should be determined. If this
1561
+ # is `comma` or `space`, that is always the separator; if this is `auto`
1562
+ # (the default), the separator is the same as that used by the list.
1563
+ def append(list, val, separator = Sass::Script::Value::String.new("auto"))
1551
1564
  assert_type separator, :String
1552
1565
  unless %w[auto space comma].include?(separator.value)
1553
1566
  raise ArgumentError.new("Separator name must be space, comma, or auto")
1554
1567
  end
1555
- sep = list.separator if list.is_a?(Sass::Script::List)
1556
- Sass::Script::List.new(
1568
+ sep = list.separator if list.is_a?(Sass::Script::Value::List)
1569
+ Sass::Script::Value::List.new(
1557
1570
  list.to_a + [val],
1558
1571
  if separator.value == 'auto'
1559
1572
  sep || :space
@@ -1585,7 +1598,7 @@ module Sass::Script
1585
1598
  value.slice!(length)
1586
1599
  end
1587
1600
  new_list_value = values.first.zip(*values[1..-1])
1588
- List.new(new_list_value.map{|list| List.new(list, :space)}, :comma)
1601
+ Sass::Script::Value::List.new(new_list_value.map{|list| Sass::Script::Value::List.new(list, :space)}, :comma)
1589
1602
  end
1590
1603
  declare :zip, [], :var_args => true
1591
1604
 
@@ -1599,9 +1612,9 @@ module Sass::Script
1599
1612
  def index(list, value)
1600
1613
  index = list.to_a.index {|e| e.eq(value).to_bool }
1601
1614
  if index
1602
- Number.new(index + 1)
1615
+ Sass::Script::Value::Number.new(index + 1)
1603
1616
  else
1604
- Bool.new(false)
1617
+ Sass::Script::Value::Bool.new(false)
1605
1618
  end
1606
1619
  end
1607
1620
  declare :index, [:list, :value]
@@ -1614,10 +1627,10 @@ module Sass::Script
1614
1627
  # list-separator(1px, 2px, 3px) => 'comma'
1615
1628
  # list-separator('foo') => 'space'
1616
1629
  def list_separator(list)
1617
- if list.is_a?(Sass::Script::List)
1618
- String.new(list.separator.to_s)
1630
+ if list.is_a?(Sass::Script::Value::List)
1631
+ Sass::Script::Value::String.new(list.separator.to_s)
1619
1632
  else
1620
- String.new('space')
1633
+ Sass::Script::Value::String.new('space')
1621
1634
  end
1622
1635
  end
1623
1636
  declare :separator, [:list]
@@ -1627,9 +1640,10 @@ module Sass::Script
1627
1640
  # @example
1628
1641
  # if(true, 1px, 2px) => 1px
1629
1642
  # if(false, 1px, 2px) => 2px
1630
- # @param condition [Bool] Whether the first or second value will be returned.
1631
- # @param if_true [Literal] The value that will be returned if `$condition` is true.
1632
- # @param if_false [Literal] The value that will be returned if `$condition` is false.
1643
+ # @param condition [Sass::Script::Value::Bool]
1644
+ # Whether the first or second value will be returned.
1645
+ # @param if_true [Value] The value that will be returned if `$condition` is true.
1646
+ # @param if_false [Value] The value that will be returned if `$condition` is false.
1633
1647
  def if(condition, if_true, if_false)
1634
1648
  if condition.to_bool
1635
1649
  if_true
@@ -1648,7 +1662,7 @@ module Sass::Script
1648
1662
  # @example
1649
1663
  # counter(item, ".") => counter(item,".")
1650
1664
  def counter(*args)
1651
- Sass::Script::String.new("counter(#{args.map {|a| a.to_s(options)}.join(',')})")
1665
+ Sass::Script::Value::String.new("counter(#{args.map {|a| a.to_s(options)}.join(',')})")
1652
1666
  end
1653
1667
  declare :counter, [], :var_args => true
1654
1668
 
@@ -1659,7 +1673,7 @@ module Sass::Script
1659
1673
  # It yields a number to a block to perform the operation and return a number
1660
1674
  def numeric_transformation(value)
1661
1675
  assert_type value, :Number
1662
- Sass::Script::Number.new(yield(value.value), value.numerator_units, value.denominator_units)
1676
+ Sass::Script::Value::Number.new(yield(value.value), value.numerator_units, value.denominator_units)
1663
1677
  end
1664
1678
 
1665
1679
  def _adjust(color, amount, attr, range, op, units = "")