sass 3.2.7 → 3.3.0.rc.1

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 (184) hide show
  1. data/MIT-LICENSE +2 -2
  2. data/README.md +14 -2
  3. data/Rakefile +25 -1
  4. data/VERSION +1 -1
  5. data/VERSION_DATE +1 -1
  6. data/VERSION_NAME +1 -1
  7. data/lib/sass/cache_stores/base.rb +4 -2
  8. data/lib/sass/cache_stores/chain.rb +2 -1
  9. data/lib/sass/cache_stores/filesystem.rb +2 -6
  10. data/lib/sass/cache_stores/memory.rb +1 -1
  11. data/lib/sass/cache_stores/null.rb +2 -2
  12. data/lib/sass/callbacks.rb +1 -0
  13. data/lib/sass/css.rb +10 -10
  14. data/lib/sass/engine.rb +403 -150
  15. data/lib/sass/environment.rb +136 -57
  16. data/lib/sass/error.rb +7 -7
  17. data/lib/sass/exec.rb +123 -39
  18. data/lib/sass/features.rb +41 -0
  19. data/lib/sass/importers/base.rb +33 -2
  20. data/lib/sass/importers/deprecated_path.rb +45 -0
  21. data/lib/sass/importers/filesystem.rb +25 -14
  22. data/lib/sass/importers.rb +1 -0
  23. data/lib/sass/logger/base.rb +3 -3
  24. data/lib/sass/logger/log_level.rb +4 -6
  25. data/lib/sass/media.rb +19 -19
  26. data/lib/sass/plugin/compiler.rb +141 -101
  27. data/lib/sass/plugin/configuration.rb +18 -22
  28. data/lib/sass/plugin/merb.rb +1 -1
  29. data/lib/sass/plugin/staleness_checker.rb +24 -8
  30. data/lib/sass/plugin.rb +4 -2
  31. data/lib/sass/repl.rb +3 -3
  32. data/lib/sass/script/css_lexer.rb +9 -4
  33. data/lib/sass/script/css_parser.rb +6 -2
  34. data/lib/sass/script/functions.rb +1343 -590
  35. data/lib/sass/script/lexer.rb +84 -52
  36. data/lib/sass/script/parser.rb +217 -97
  37. data/lib/sass/script/tree/funcall.rb +290 -0
  38. data/lib/sass/script/{interpolation.rb → tree/interpolation.rb} +34 -13
  39. data/lib/sass/script/tree/list_literal.rb +80 -0
  40. data/lib/sass/script/tree/literal.rb +47 -0
  41. data/lib/sass/script/tree/map_literal.rb +64 -0
  42. data/lib/sass/script/{node.rb → tree/node.rb} +22 -12
  43. data/lib/sass/script/{operation.rb → tree/operation.rb} +17 -25
  44. data/lib/sass/script/tree/selector.rb +30 -0
  45. data/lib/sass/script/{string_interpolation.rb → tree/string_interpolation.rb} +5 -4
  46. data/lib/sass/script/{unary_operation.rb → tree/unary_operation.rb} +14 -9
  47. data/lib/sass/script/tree/variable.rb +57 -0
  48. data/lib/sass/script/tree.rb +16 -0
  49. data/lib/sass/script/{arg_list.rb → value/arg_list.rb} +4 -24
  50. data/lib/sass/script/value/base.rb +248 -0
  51. data/lib/sass/script/value/bool.rb +36 -0
  52. data/lib/sass/script/{color.rb → value/color.rb} +239 -195
  53. data/lib/sass/script/value/helpers.rb +155 -0
  54. data/lib/sass/script/value/list.rb +119 -0
  55. data/lib/sass/script/value/map.rb +70 -0
  56. data/lib/sass/script/value/null.rb +45 -0
  57. data/lib/sass/script/{number.rb → value/number.rb} +91 -65
  58. data/lib/sass/script/{string.rb → value/string.rb} +9 -11
  59. data/lib/sass/script/value.rb +11 -0
  60. data/lib/sass/script.rb +35 -8
  61. data/lib/sass/scss/css_parser.rb +2 -1
  62. data/lib/sass/scss/parser.rb +338 -170
  63. data/lib/sass/scss/rx.rb +5 -6
  64. data/lib/sass/scss/script_lexer.rb +1 -0
  65. data/lib/sass/scss/script_parser.rb +1 -0
  66. data/lib/sass/scss/static_parser.rb +23 -6
  67. data/lib/sass/selector/abstract_sequence.rb +2 -2
  68. data/lib/sass/selector/comma_sequence.rb +21 -16
  69. data/lib/sass/selector/sequence.rb +60 -34
  70. data/lib/sass/selector/simple.rb +11 -12
  71. data/lib/sass/selector/simple_sequence.rb +55 -33
  72. data/lib/sass/selector.rb +52 -48
  73. data/lib/sass/source/map.rb +211 -0
  74. data/lib/sass/source/position.rb +39 -0
  75. data/lib/sass/source/range.rb +41 -0
  76. data/lib/sass/stack.rb +120 -0
  77. data/lib/sass/supports.rb +12 -13
  78. data/lib/sass/tree/at_root_node.rb +82 -0
  79. data/lib/sass/tree/comment_node.rb +3 -3
  80. data/lib/sass/tree/css_import_node.rb +11 -11
  81. data/lib/sass/tree/debug_node.rb +2 -2
  82. data/lib/sass/tree/directive_node.rb +13 -2
  83. data/lib/sass/tree/each_node.rb +8 -8
  84. data/lib/sass/tree/extend_node.rb +13 -6
  85. data/lib/sass/tree/for_node.rb +4 -4
  86. data/lib/sass/tree/function_node.rb +5 -4
  87. data/lib/sass/tree/if_node.rb +1 -1
  88. data/lib/sass/tree/import_node.rb +4 -5
  89. data/lib/sass/tree/media_node.rb +4 -14
  90. data/lib/sass/tree/mixin_def_node.rb +4 -4
  91. data/lib/sass/tree/mixin_node.rb +21 -8
  92. data/lib/sass/tree/node.rb +29 -12
  93. data/lib/sass/tree/prop_node.rb +38 -18
  94. data/lib/sass/tree/return_node.rb +3 -2
  95. data/lib/sass/tree/root_node.rb +19 -3
  96. data/lib/sass/tree/rule_node.rb +25 -17
  97. data/lib/sass/tree/supports_node.rb +0 -13
  98. data/lib/sass/tree/trace_node.rb +2 -1
  99. data/lib/sass/tree/variable_node.rb +9 -3
  100. data/lib/sass/tree/visitors/base.rb +6 -6
  101. data/lib/sass/tree/visitors/check_nesting.rb +12 -9
  102. data/lib/sass/tree/visitors/convert.rb +63 -38
  103. data/lib/sass/tree/visitors/cssize.rb +63 -23
  104. data/lib/sass/tree/visitors/deep_copy.rb +6 -5
  105. data/lib/sass/tree/visitors/extend.rb +7 -7
  106. data/lib/sass/tree/visitors/perform.rb +256 -151
  107. data/lib/sass/tree/visitors/set_options.rb +6 -6
  108. data/lib/sass/tree/visitors/to_css.rb +231 -81
  109. data/lib/sass/tree/warn_node.rb +2 -2
  110. data/lib/sass/tree/while_node.rb +2 -2
  111. data/lib/sass/util/multibyte_string_scanner.rb +2 -0
  112. data/lib/sass/util/normalized_map.rb +65 -0
  113. data/lib/sass/util/ordered_hash.rb +188 -0
  114. data/lib/sass/util/subset_map.rb +3 -2
  115. data/lib/sass/util/test.rb +9 -0
  116. data/lib/sass/util.rb +220 -34
  117. data/lib/sass/version.rb +9 -9
  118. data/lib/sass.rb +14 -7
  119. data/test/sass/compiler_test.rb +213 -0
  120. data/test/sass/conversion_test.rb +235 -9
  121. data/test/sass/engine_test.rb +230 -60
  122. data/test/sass/exec_test.rb +86 -0
  123. data/test/sass/extend_test.rb +215 -147
  124. data/test/sass/functions_test.rb +584 -99
  125. data/test/sass/importer_test.rb +165 -17
  126. data/test/sass/plugin_test.rb +19 -13
  127. data/test/sass/script_conversion_test.rb +40 -0
  128. data/test/sass/script_test.rb +231 -21
  129. data/test/sass/scss/css_test.rb +14 -5
  130. data/test/sass/scss/scss_test.rb +1266 -66
  131. data/test/sass/source_map_test.rb +879 -0
  132. data/test/sass/templates/bork5.sass +3 -0
  133. data/test/sass/util/normalized_map_test.rb +30 -0
  134. data/test/sass/util_test.rb +90 -0
  135. data/test/sass/value_helpers_test.rb +181 -0
  136. data/test/test_helper.rb +7 -2
  137. metadata +316 -291
  138. data/lib/sass/script/bool.rb +0 -18
  139. data/lib/sass/script/funcall.rb +0 -231
  140. data/lib/sass/script/list.rb +0 -84
  141. data/lib/sass/script/literal.rb +0 -239
  142. data/lib/sass/script/null.rb +0 -34
  143. data/lib/sass/script/variable.rb +0 -58
  144. data/test/Gemfile +0 -3
  145. data/vendor/listen/CHANGELOG.md +0 -221
  146. data/vendor/listen/CONTRIBUTING.md +0 -38
  147. data/vendor/listen/Gemfile +0 -30
  148. data/vendor/listen/Guardfile +0 -8
  149. data/vendor/listen/LICENSE +0 -20
  150. data/vendor/listen/README.md +0 -315
  151. data/vendor/listen/Rakefile +0 -47
  152. data/vendor/listen/Vagrantfile +0 -96
  153. data/vendor/listen/lib/listen/adapter.rb +0 -214
  154. data/vendor/listen/lib/listen/adapters/bsd.rb +0 -112
  155. data/vendor/listen/lib/listen/adapters/darwin.rb +0 -85
  156. data/vendor/listen/lib/listen/adapters/linux.rb +0 -113
  157. data/vendor/listen/lib/listen/adapters/polling.rb +0 -67
  158. data/vendor/listen/lib/listen/adapters/windows.rb +0 -87
  159. data/vendor/listen/lib/listen/dependency_manager.rb +0 -126
  160. data/vendor/listen/lib/listen/directory_record.rb +0 -371
  161. data/vendor/listen/lib/listen/listener.rb +0 -225
  162. data/vendor/listen/lib/listen/multi_listener.rb +0 -143
  163. data/vendor/listen/lib/listen/turnstile.rb +0 -28
  164. data/vendor/listen/lib/listen/version.rb +0 -3
  165. data/vendor/listen/lib/listen.rb +0 -40
  166. data/vendor/listen/listen.gemspec +0 -22
  167. data/vendor/listen/spec/listen/adapter_spec.rb +0 -183
  168. data/vendor/listen/spec/listen/adapters/bsd_spec.rb +0 -36
  169. data/vendor/listen/spec/listen/adapters/darwin_spec.rb +0 -37
  170. data/vendor/listen/spec/listen/adapters/linux_spec.rb +0 -47
  171. data/vendor/listen/spec/listen/adapters/polling_spec.rb +0 -68
  172. data/vendor/listen/spec/listen/adapters/windows_spec.rb +0 -30
  173. data/vendor/listen/spec/listen/dependency_manager_spec.rb +0 -107
  174. data/vendor/listen/spec/listen/directory_record_spec.rb +0 -1225
  175. data/vendor/listen/spec/listen/listener_spec.rb +0 -169
  176. data/vendor/listen/spec/listen/multi_listener_spec.rb +0 -174
  177. data/vendor/listen/spec/listen/turnstile_spec.rb +0 -56
  178. data/vendor/listen/spec/listen_spec.rb +0 -73
  179. data/vendor/listen/spec/spec_helper.rb +0 -21
  180. data/vendor/listen/spec/support/adapter_helper.rb +0 -629
  181. data/vendor/listen/spec/support/directory_record_helper.rb +0 -55
  182. data/vendor/listen/spec/support/fixtures_helper.rb +0 -29
  183. data/vendor/listen/spec/support/listeners_helper.rb +0 -156
  184. data/vendor/listen/spec/support/platform_helper.rb +0 -15
@@ -1,6 +1,4 @@
1
- require 'sass/script/literal'
2
-
3
- module Sass::Script
1
+ module Sass::Script::Value
4
2
  # A SassScript object representing a number.
5
3
  # SassScript numbers can have decimal values,
6
4
  # and can also have units.
@@ -9,7 +7,7 @@ module Sass::Script
9
7
  #
10
8
  # Numbers can also have more complex units, such as `1px*em/in`.
11
9
  # These cannot be inputted directly in Sass code at the moment.
12
- class Number < Literal
10
+ class Number < Base
13
11
  # The Ruby value of the number.
14
12
  #
15
13
  # @return [Numeric]
@@ -17,7 +15,7 @@ module Sass::Script
17
15
 
18
16
  # A list of units in the numerator of the number.
19
17
  # For example, `1px*em/in*cm` would return `["px", "em"]`
20
- # @return [Array<String>]
18
+ # @return [Array<String>]
21
19
  attr_reader :numerator_units
22
20
 
23
21
  # A list of units in the denominator of the number.
@@ -53,24 +51,15 @@ module Sass::Script
53
51
  @precision_factor ||= 10.0**precision
54
52
  end
55
53
 
56
- # Handles the deprecation warning for the PRECISION constant
57
- # This can be removed in 3.2.
58
- def self.const_missing(const)
59
- if const == :PRECISION
60
- Sass::Util.sass_warn("Sass::Script::Number::PRECISION is deprecated and will be removed in a future release. Use Sass::Script::Number.precision_factor instead.")
61
- const_set(:PRECISION, self.precision_factor)
62
- else
63
- super
64
- end
65
- end
66
-
67
54
  # Used so we don't allocate two new arrays for each new number.
68
55
  NO_UNITS = []
69
56
 
70
57
  # @param value [Numeric] The value of the number
71
- # @param numerator_units [Array<String>] See \{#numerator\_units}
72
- # @param denominator_units [Array<String>] See \{#denominator\_units}
58
+ # @param numerator_units [::String, Array<::String>] See \{#numerator\_units}
59
+ # @param denominator_units [::String, Array<::String>] See \{#denominator\_units}
73
60
  def initialize(value, numerator_units = NO_UNITS, denominator_units = NO_UNITS)
61
+ numerator_units = [numerator_units] if numerator_units.is_a?(::String)
62
+ denominator_units = [denominator_units] if denominator_units.is_a?(::String)
74
63
  super(value)
75
64
  @numerator_units = numerator_units
76
65
  @denominator_units = denominator_units
@@ -86,11 +75,11 @@ module Sass::Script
86
75
  # {Color}
87
76
  # : Adds this number to each of the RGB color channels.
88
77
  #
89
- # {Literal}
90
- # : See {Literal#plus}.
78
+ # {Value}
79
+ # : See {Value::Base#plus}.
91
80
  #
92
- # @param other [Literal] The right-hand side of the operator
93
- # @return [Literal] The result of the operation
81
+ # @param other [Value] The right-hand side of the operator
82
+ # @return [Value] The result of the operation
94
83
  # @raise [Sass::UnitConversionError] if `other` is a number with incompatible units
95
84
  def plus(other)
96
85
  if other.is_a? Number
@@ -108,11 +97,11 @@ module Sass::Script
108
97
  # {Number}
109
98
  # : Subtracts this number from the other, converting units if possible.
110
99
  #
111
- # {Literal}
112
- # : See {Literal#minus}.
100
+ # {Value}
101
+ # : See {Value::Base#minus}.
113
102
  #
114
- # @param other [Literal] The right-hand side of the operator
115
- # @return [Literal] The result of the operation
103
+ # @param other [Value] The right-hand side of the operator
104
+ # @return [Value] The result of the operation
116
105
  # @raise [Sass::UnitConversionError] if `other` is a number with incompatible units
117
106
  def minus(other)
118
107
  if other.is_a? Number
@@ -164,16 +153,16 @@ module Sass::Script
164
153
  # {Number}
165
154
  # : Divides this number by the other, converting units appropriately.
166
155
  #
167
- # {Literal}
168
- # : See {Literal#div}.
156
+ # {Value}
157
+ # : See {Value::Base#div}.
169
158
  #
170
- # @param other [Literal] The right-hand side of the operator
171
- # @return [Literal] The result of the operation
159
+ # @param other [Value] The right-hand side of the operator
160
+ # @return [Value] The result of the operation
172
161
  def div(other)
173
162
  if other.is_a? Number
174
163
  res = operate(other, :/)
175
- if self.original && other.original
176
- res.original = "#{self.original}/#{other.original}"
164
+ if original && other.original
165
+ res.original = "#{original}/#{other.original}"
177
166
  end
178
167
  res
179
168
  else
@@ -190,7 +179,8 @@ module Sass::Script
190
179
  def mod(other)
191
180
  if other.is_a?(Number)
192
181
  unless other.unitless?
193
- raise Sass::UnitConversionError.new("Cannot modulo by a number with units: #{other.inspect}.")
182
+ raise Sass::UnitConversionError.new(
183
+ "Cannot modulo by a number with units: #{other.inspect}.")
194
184
  end
195
185
  operate(other, :%)
196
186
  else
@@ -200,10 +190,10 @@ module Sass::Script
200
190
 
201
191
  # The SassScript `==` operation.
202
192
  #
203
- # @param other [Literal] The right-hand side of the operator
193
+ # @param other [Value] The right-hand side of the operator
204
194
  # @return [Boolean] Whether this number is equal to the other object
205
195
  def eq(other)
206
- return Sass::Script::Bool.new(false) unless other.is_a?(Sass::Script::Number)
196
+ return Bool::FALSE unless other.is_a?(Sass::Script::Value::Number)
207
197
  this = self
208
198
  begin
209
199
  if unitless?
@@ -212,10 +202,21 @@ module Sass::Script
212
202
  other = other.coerce(@numerator_units, @denominator_units)
213
203
  end
214
204
  rescue Sass::UnitConversionError
215
- return Sass::Script::Bool.new(false)
205
+ return Bool::FALSE
216
206
  end
207
+ Bool.new(this.value == other.value)
208
+ end
209
+
210
+ def hash
211
+ [value, numerator_units, denominator_units].hash
212
+ end
217
213
 
218
- Sass::Script::Bool.new(this.value == other.value)
214
+ # Hash-equality works differently than `==` equality for numbers.
215
+ # Hash-equality must be transitive, so it just compares the exact value,
216
+ # numerator units, and denominator units.
217
+ def eql?(other)
218
+ value == other.value && numerator_units == other.numerator_units &&
219
+ denominator_units == other.denominator_units
219
220
  end
220
221
 
221
222
  # The SassScript `>` operation.
@@ -283,7 +284,7 @@ module Sass::Script
283
284
  # @raise [Sass::SyntaxError] if the number isn't an integer
284
285
  def to_i
285
286
  super unless int?
286
- return value
287
+ value
287
288
  end
288
289
 
289
290
  # @return [Boolean] Whether or not this number is an integer.
@@ -296,6 +297,24 @@ module Sass::Script
296
297
  @numerator_units.empty? && @denominator_units.empty?
297
298
  end
298
299
 
300
+ # Checks whether the number has the numerator unit specified.
301
+ #
302
+ # @example
303
+ # number = Sass::Script::Value::Number.new(10, "px")
304
+ # number.is_unit?("px") => true
305
+ # number.is_unit?(nil) => false
306
+ #
307
+ # @param unit [::String, nil] The unit the number should have or nil if the number
308
+ # should be unitless.
309
+ # @see Number#unitless? The unitless? method may be more readable.
310
+ def is_unit?(unit)
311
+ if unit
312
+ denominator_units.size == 0 && numerator_units.size == 1 && numerator_units.first == unit
313
+ else
314
+ unitless?
315
+ end
316
+ end
317
+
299
318
  # @return [Boolean] Whether or not this number has units that can be represented in CSS
300
319
  # (that is, zero or one \{#numerator\_units}).
301
320
  def legal_units?
@@ -320,9 +339,9 @@ module Sass::Script
320
339
  # current units
321
340
  def coerce(num_units, den_units)
322
341
  Number.new(if unitless?
323
- self.value
342
+ value
324
343
  else
325
- self.value * coercion_factor(@numerator_units, num_units) /
344
+ value * coercion_factor(@numerator_units, num_units) /
326
345
  coercion_factor(@denominator_units, den_units)
327
346
  end, num_units, den_units)
328
347
  end
@@ -330,12 +349,10 @@ module Sass::Script
330
349
  # @param other [Number] A number to decide if it can be compared with this number.
331
350
  # @return [Boolean] Whether or not this number can be compared with the other.
332
351
  def comparable_to?(other)
333
- begin
334
- operate(other, :+)
335
- true
336
- rescue Sass::UnitConversionError
337
- false
338
- end
352
+ operate(other, :+)
353
+ true
354
+ rescue Sass::UnitConversionError
355
+ false
339
356
  end
340
357
 
341
358
  # Returns a human readable representation of the units in this number.
@@ -360,7 +377,7 @@ module Sass::Script
360
377
  elsif num % 1 == 0.0
361
378
  num.to_i
362
379
  else
363
- ((num * self.precision_factor).round / self.precision_factor).to_f
380
+ ((num * precision_factor).round / precision_factor).to_f
364
381
  end
365
382
  end
366
383
 
@@ -376,7 +393,7 @@ module Sass::Script
376
393
  end
377
394
  end
378
395
  # avoid integer division
379
- value = (:/ == operation) ? this.value.to_f : this.value
396
+ value = :/ == operation ? this.value.to_f : this.value
380
397
  result = value.send(operation, other.value)
381
398
 
382
399
  if result.is_a?(Numeric)
@@ -391,29 +408,33 @@ module Sass::Script
391
408
  from_units, to_units = sans_common_units(from_units, to_units)
392
409
 
393
410
  if from_units.size != to_units.size || !convertable?(from_units | to_units)
394
- raise Sass::UnitConversionError.new("Incompatible units: '#{from_units.join('*')}' and '#{to_units.join('*')}'.")
411
+ raise Sass::UnitConversionError.new(
412
+ "Incompatible units: '#{from_units.join('*')}' and '#{to_units.join('*')}'.")
395
413
  end
396
414
 
397
- from_units.zip(to_units).inject(1) {|m,p| m * conversion_factor(p[0], p[1]) }
415
+ from_units.zip(to_units).inject(1) {|m, p| m * conversion_factor(p[0], p[1])}
398
416
  end
399
417
 
400
418
  def compute_units(this, other, operation)
401
419
  case operation
402
420
  when :*
403
- [this.numerator_units + other.numerator_units, this.denominator_units + other.denominator_units]
421
+ [this.numerator_units + other.numerator_units,
422
+ this.denominator_units + other.denominator_units]
404
423
  when :/
405
- [this.numerator_units + other.denominator_units, this.denominator_units + other.numerator_units]
406
- else
424
+ [this.numerator_units + other.denominator_units,
425
+ this.denominator_units + other.numerator_units]
426
+ else
407
427
  [this.numerator_units, this.denominator_units]
408
428
  end
409
429
  end
410
430
 
411
431
  def normalize!
412
432
  return if unitless?
413
- @numerator_units, @denominator_units = sans_common_units(@numerator_units, @denominator_units)
433
+ @numerator_units, @denominator_units =
434
+ sans_common_units(@numerator_units, @denominator_units)
414
435
 
415
436
  @denominator_units.each_with_index do |d, i|
416
- if convertable?(d) && (u = @numerator_units.detect(&method(:convertable?)))
437
+ if convertable?(d) && (u = @numerator_units.find(&method(:convertable?)))
417
438
  @value /= conversion_factor(d, u)
418
439
  @denominator_units.delete_at(i)
419
440
  @numerator_units.delete_at(@numerator_units.index(u))
@@ -422,13 +443,15 @@ module Sass::Script
422
443
  end
423
444
 
424
445
  # A hash of unit names to their index in the conversion table
425
- CONVERTABLE_UNITS = {"in" => 0, "cm" => 1, "pc" => 2, "mm" => 3, "pt" => 4, "px" => 5 }
426
- CONVERSION_TABLE = [[ 1, 2.54, 6, 25.4, 72 , 96 ], # in
427
- [ nil, 1, 2.36220473, 10, 28.3464567, 37.795275591], # cm
428
- [ nil, nil, 1, 4.23333333, 12 , 16 ], # pc
429
- [ nil, nil, nil, 1, 2.83464567, 3.7795275591], # mm
430
- [ nil, nil, nil, nil, 1 , 1.3333333333], # pt
431
- [ nil, nil, nil, nil, nil , 1 ]] # px
446
+ CONVERTABLE_UNITS = %w(in cm pc mm pt px).inject({}) {|m, v| m[v] = m.size; m}
447
+
448
+ # in cm pc mm pt px
449
+ CONVERSION_TABLE = [[1, 2.54, 6, 25.4, 72 , 96], # in
450
+ [nil, 1, 2.36220473, 10, 28.3464567, 37.795275591], # cm
451
+ [nil, nil, 1, 4.23333333, 12 , 16], # pc
452
+ [nil, nil, nil, 1, 2.83464567, 3.7795275591], # mm
453
+ [nil, nil, nil, nil, 1 , 1.3333333333], # pt
454
+ [nil, nil, nil, nil, nil , 1]] # px
432
455
 
433
456
  def conversion_factor(from_unit, to_unit)
434
457
  res = CONVERSION_TABLE[CONVERTABLE_UNITS[from_unit]][CONVERTABLE_UNITS[to_unit]]
@@ -443,11 +466,14 @@ module Sass::Script
443
466
  def sans_common_units(units1, units2)
444
467
  units2 = units2.dup
445
468
  # Can't just use -, because we want px*px to coerce properly to px*mm
446
- return units1.map do |u|
447
- next u unless j = units2.index(u)
469
+ units1 = units1.map do |u|
470
+ j = units2.index(u)
471
+ next u unless j
448
472
  units2.delete_at(j)
449
473
  nil
450
- end.compact, units2
474
+ end
475
+ units1.compact!
476
+ return units1, units2
451
477
  end
452
478
  end
453
479
  end
@@ -1,8 +1,6 @@
1
- require 'sass/script/literal'
2
-
3
- module Sass::Script
1
+ module Sass::Script::Value
4
2
  # A SassScript object representing a CSS string *or* a CSS identifier.
5
- class String < Literal
3
+ class String < Base
6
4
  # The Ruby value of the string.
7
5
  #
8
6
  # @return [String]
@@ -24,26 +22,26 @@ module Sass::Script
24
22
  @type = type
25
23
  end
26
24
 
27
- # @see Literal#plus
25
+ # @see Value#plus
28
26
  def plus(other)
29
- other_str = other.is_a?(Sass::Script::String) ? other.value : other.to_s
30
- Sass::Script::String.new(self.value + other_str, self.type)
27
+ other_str = other.is_a?(Sass::Script::Value::String) ? other.value : other.to_s
28
+ Sass::Script::Value::String.new(value + other_str, type)
31
29
  end
32
30
 
33
- # @see Node#to_s
31
+ # @see Value#to_s
34
32
  def to_s(opts = {})
35
33
  if @type == :identifier
36
- return @value.gsub(/\s+/, " ")
34
+ return @value.gsub(/\n\s*/, " ")
37
35
  end
38
36
 
39
37
  return "\"#{value.gsub('"', "\\\"")}\"" if opts[:quote] == %q{"}
40
38
  return "'#{value.gsub("'", "\\'")}'" if opts[:quote] == %q{'}
41
39
  return "\"#{value}\"" unless value.include?('"')
42
40
  return "'#{value}'" unless value.include?("'")
43
- "\"#{value.gsub('"', "\\\"")}\"" #'
41
+ "\"#{value.gsub('"', "\\\"")}\"" # '
44
42
  end
45
43
 
46
- # @see Node#to_sass
44
+ # @see Value#to_sass
47
45
  def to_sass(opts = {})
48
46
  to_s
49
47
  end
@@ -0,0 +1,11 @@
1
+ module Sass::Script::Value; end
2
+
3
+ require 'sass/script/value/base'
4
+ require 'sass/script/value/string'
5
+ require 'sass/script/value/number'
6
+ require 'sass/script/value/color'
7
+ require 'sass/script/value/bool'
8
+ require 'sass/script/value/null'
9
+ require 'sass/script/value/list'
10
+ require 'sass/script/value/arg_list'
11
+ require 'sass/script/value/map'
data/lib/sass/script.rb CHANGED
@@ -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
@@ -12,7 +7,8 @@ module Sass
12
7
  # This module contains code that handles the parsing and evaluation of SassScript.
13
8
  module Script
14
9
  # The regular expression used to parse variables.
15
- MATCH = /^\$(#{Sass::SCSS::RX::IDENT})\s*:\s*(.+?)(!(?i:default))?$/
10
+ MATCH = /^\$(#{Sass::SCSS::RX::IDENT})\s*:\s*(.+?)
11
+ (!#{Sass::SCSS::RX::IDENT}(?:\s+!#{Sass::SCSS::RX::IDENT})*)?$/x
16
12
 
17
13
  # The regular expression used to validate variables without matching.
18
14
  VALIDATE = /^\$#{Sass::SCSS::RX::IDENT}$/
@@ -26,7 +22,7 @@ module Sass
26
22
  # Used for error reporting
27
23
  # @param options [{Symbol => Object}] An options hash;
28
24
  # see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}
29
- # @return [Script::Node] The root node of the parse tree
25
+ # @return [Script::Tree::Node] The root node of the parse tree
30
26
  def self.parse(value, line, offset, options = {})
31
27
  Parser.parse(value, line, offset, options)
32
28
  rescue Sass::SyntaxError => e
@@ -35,5 +31,36 @@ module Sass
35
31
  raise e
36
32
  end
37
33
 
34
+ require 'sass/script/functions'
35
+ require 'sass/script/parser'
36
+ require 'sass/script/tree'
37
+ require 'sass/script/value'
38
+
39
+ # @private
40
+ CONST_RENAMES = {
41
+ :Literal => Sass::Script::Value::Base,
42
+ :ArgList => Sass::Script::Value::ArgList,
43
+ :Bool => Sass::Script::Value::Bool,
44
+ :Color => Sass::Script::Value::Color,
45
+ :List => Sass::Script::Value::List,
46
+ :Null => Sass::Script::Value::Null,
47
+ :Number => Sass::Script::Value::Number,
48
+ :String => Sass::Script::Value::String,
49
+ :Node => Sass::Script::Tree::Node,
50
+ :Funcall => Sass::Script::Tree::Funcall,
51
+ :Interpolation => Sass::Script::Tree::Interpolation,
52
+ :Operation => Sass::Script::Tree::Operation,
53
+ :StringInterpolation => Sass::Script::Tree::StringInterpolation,
54
+ :UnaryOperation => Sass::Script::Tree::UnaryOperation,
55
+ :Variable => Sass::Script::Tree::Variable,
56
+ }
57
+
58
+ # @private
59
+ def self.const_missing(name)
60
+ klass = CONST_RENAMES[name]
61
+ super unless klass
62
+ CONST_RENAMES.each {|n, k| const_set(n, k)}
63
+ klass
64
+ end
38
65
  end
39
66
  end
@@ -7,6 +7,7 @@ module Sass
7
7
  # parent references, nested selectors, and so forth.
8
8
  # It does support all the same CSS hacks as the SCSS parser, though.
9
9
  class CssParser < StaticParser
10
+
10
11
  private
11
12
 
12
13
  def placeholder_selector; nil; end
@@ -26,7 +27,7 @@ module Sass
26
27
  end
27
28
 
28
29
  def nested_properties!(node, space)
29
- expected('expression (e.g. 1px, bold)');
30
+ expected('expression (e.g. 1px, bold)')
30
31
  end
31
32
 
32
33
  @sass_script_parser = Class.new(Sass::Script::CssParser)