haml 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of haml might be problematic. Click here for more details.

Files changed (87) hide show
  1. data/VERSION +1 -1
  2. data/vendor/sass/Rakefile +22 -46
  3. data/vendor/sass/VERSION +1 -1
  4. data/vendor/sass/VERSION_NAME +1 -1
  5. data/vendor/sass/bin/scss +8 -0
  6. data/vendor/sass/doc-src/SASS_CHANGELOG.md +125 -9
  7. data/vendor/sass/doc-src/SASS_REFERENCE.md +84 -8
  8. data/vendor/sass/lib/sass.rb +0 -3
  9. data/vendor/sass/lib/sass/cache_stores.rb +1 -0
  10. data/vendor/sass/lib/sass/cache_stores/base.rb +2 -2
  11. data/vendor/sass/lib/sass/cache_stores/chain.rb +33 -0
  12. data/vendor/sass/lib/sass/cache_stores/filesystem.rb +6 -4
  13. data/vendor/sass/lib/sass/cache_stores/memory.rb +8 -12
  14. data/vendor/sass/lib/sass/engine.rb +65 -56
  15. data/vendor/sass/lib/sass/environment.rb +5 -2
  16. data/vendor/sass/lib/sass/exec.rb +52 -21
  17. data/vendor/sass/lib/sass/importers/filesystem.rb +32 -9
  18. data/vendor/sass/lib/sass/less.rb +1 -1
  19. data/vendor/sass/lib/sass/plugin.rb +11 -1
  20. data/vendor/sass/lib/sass/plugin/compiler.rb +21 -12
  21. data/vendor/sass/lib/sass/plugin/rails.rb +8 -82
  22. data/vendor/sass/lib/sass/plugin/staleness_checker.rb +10 -10
  23. data/vendor/sass/lib/sass/railtie.rb +3 -2
  24. data/vendor/sass/lib/sass/script.rb +2 -25
  25. data/vendor/sass/lib/sass/script/color.rb +4 -15
  26. data/vendor/sass/lib/sass/script/funcall.rb +63 -19
  27. data/vendor/sass/lib/sass/script/functions.rb +257 -19
  28. data/vendor/sass/lib/sass/script/lexer.rb +1 -4
  29. data/vendor/sass/lib/sass/script/list.rb +2 -2
  30. data/vendor/sass/lib/sass/script/node.rb +0 -27
  31. data/vendor/sass/lib/sass/script/number.rb +1 -1
  32. data/vendor/sass/lib/sass/script/operation.rb +0 -5
  33. data/vendor/sass/lib/sass/script/parser.rb +30 -12
  34. data/vendor/sass/lib/sass/script/string.rb +2 -17
  35. data/vendor/sass/lib/sass/script/string_interpolation.rb +1 -0
  36. data/vendor/sass/lib/sass/scss/parser.rb +58 -18
  37. data/vendor/sass/lib/sass/scss/rx.rb +2 -1
  38. data/vendor/sass/lib/sass/scss/script_lexer.rb +1 -1
  39. data/vendor/sass/lib/sass/selector/comma_sequence.rb +2 -3
  40. data/vendor/sass/lib/sass/selector/sequence.rb +3 -6
  41. data/vendor/sass/lib/sass/selector/simple_sequence.rb +2 -3
  42. data/vendor/sass/lib/sass/tree/charset_node.rb +0 -15
  43. data/vendor/sass/lib/sass/tree/comment_node.rb +20 -71
  44. data/vendor/sass/lib/sass/tree/debug_node.rb +4 -22
  45. data/vendor/sass/lib/sass/tree/directive_node.rb +0 -52
  46. data/vendor/sass/lib/sass/tree/each_node.rb +8 -38
  47. data/vendor/sass/lib/sass/tree/extend_node.rb +12 -48
  48. data/vendor/sass/lib/sass/tree/for_node.rb +20 -51
  49. data/vendor/sass/lib/sass/tree/function_node.rb +27 -0
  50. data/vendor/sass/lib/sass/tree/if_node.rb +22 -57
  51. data/vendor/sass/lib/sass/tree/import_node.rb +0 -56
  52. data/vendor/sass/lib/sass/tree/media_node.rb +0 -43
  53. data/vendor/sass/lib/sass/tree/mixin_def_node.rb +12 -45
  54. data/vendor/sass/lib/sass/tree/mixin_node.rb +13 -124
  55. data/vendor/sass/lib/sass/tree/node.rb +18 -304
  56. data/vendor/sass/lib/sass/tree/prop_node.rb +24 -92
  57. data/vendor/sass/lib/sass/tree/return_node.rb +18 -0
  58. data/vendor/sass/lib/sass/tree/root_node.rb +4 -133
  59. data/vendor/sass/lib/sass/tree/rule_node.rb +21 -164
  60. data/vendor/sass/lib/sass/tree/variable_node.rb +14 -23
  61. data/vendor/sass/lib/sass/tree/visitors/base.rb +75 -0
  62. data/vendor/sass/lib/sass/tree/visitors/check_nesting.rb +134 -0
  63. data/vendor/sass/lib/sass/tree/visitors/convert.rb +255 -0
  64. data/vendor/sass/lib/sass/tree/visitors/cssize.rb +175 -0
  65. data/vendor/sass/lib/sass/tree/visitors/perform.rb +301 -0
  66. data/vendor/sass/lib/sass/tree/visitors/to_css.rb +216 -0
  67. data/vendor/sass/lib/sass/tree/warn_node.rb +4 -28
  68. data/vendor/sass/lib/sass/tree/while_node.rb +5 -35
  69. data/vendor/sass/lib/sass/util.rb +0 -50
  70. data/vendor/sass/sass.gemspec +1 -1
  71. data/vendor/sass/test/sass/conversion_test.rb +53 -102
  72. data/vendor/sass/test/sass/engine_test.rb +416 -540
  73. data/vendor/sass/test/sass/functions_test.rb +306 -4
  74. data/vendor/sass/test/sass/importer_test.rb +0 -22
  75. data/vendor/sass/test/sass/plugin_test.rb +51 -21
  76. data/vendor/sass/test/sass/results/if.css +3 -0
  77. data/vendor/sass/test/sass/script_conversion_test.rb +0 -38
  78. data/vendor/sass/test/sass/script_test.rb +19 -4
  79. data/vendor/sass/test/sass/scss/scss_test.rb +32 -11
  80. data/vendor/sass/test/sass/templates/if.sass +11 -0
  81. data/vendor/sass/test/sass/templates/nested_import.sass +2 -0
  82. data/vendor/sass/test/sass/util_test.rb +0 -21
  83. data/vendor/sass/test/test_helper.rb +0 -3
  84. metadata +268 -258
  85. data/vendor/sass/bin/css2sass +0 -13
  86. data/vendor/sass/lib/sass/cache_stores/active_support.rb +0 -28
  87. data/vendor/sass/lib/sass/importers/rails.rb +0 -75
@@ -88,6 +88,17 @@ module Sass::Script
88
88
  # \{#transparentize transparentize($color, $amount)} / \{#fade_out fade-out($color, $amount)}
89
89
  # : Makes a color more transparent.
90
90
  #
91
+ # ## Other Color Functions
92
+ #
93
+ # \{#adjust_color adjust-color($color, \[$red\], \[$green\], \[$blue\], \[$hue\], \[$saturation\], \[$lightness\], \[$alpha\]}
94
+ # : Increase or decrease any of the components of a color.
95
+ #
96
+ # \{#scale_color scale-color($color, \[$red\], \[$green\], \[$blue\], \[$hue\], \[$saturation\], \[$lightness\], \[$alpha\]}
97
+ # : Fluidly scale one or more components of a color.
98
+ #
99
+ # \{#change_color change-color($color, \[$red\], \[$green\], \[$blue\], \[$hue\], \[$saturation\], \[$lightness\], \[$alpha\]}
100
+ # : Changes one or more properties of a color.
101
+ #
91
102
  # ## String Functions
92
103
  #
93
104
  # \{#unquote unquote($string)}
@@ -138,6 +149,11 @@ module Sass::Script
138
149
  # \{#comparable comparable($number-1, $number-2)}
139
150
  # : Returns whether two numbers can be added or compared.
140
151
  #
152
+ # ## Miscellaneous Functions
153
+ #
154
+ # \{#if if($condition, $if-true, $if-false)}
155
+ # : Returns one of two values, depending on whether or not a condition is true.
156
+ #
141
157
  # ## Adding Custom Functions
142
158
  #
143
159
  # New Sass functions can be added by adding Ruby methods to this module.
@@ -223,6 +239,8 @@ module Sass::Script
223
239
  # in addition to those in `:args`.
224
240
  # If this is true, the Ruby function will be passed a hash from strings
225
241
  # to {Sass::Script::Literal}s as the last argument.
242
+ # In addition, if this is true and `:var_args` is not,
243
+ # Sass will ensure that the last argument passed is a hash.
226
244
  #
227
245
  # @example
228
246
  # declare :rgba, [:hex, :alpha]
@@ -277,6 +295,8 @@ module Sass::Script
277
295
  # That means that all instance methods of {EvaluationContext}
278
296
  # are available to use in functions.
279
297
  class EvaluationContext
298
+ include Functions
299
+
280
300
  # The options hash for the {Sass::Engine} that is processing the function call
281
301
  #
282
302
  # @return [{Symbol => Object}]
@@ -285,10 +305,6 @@ module Sass::Script
285
305
  # @param options [{Symbol => Object}] See \{#options}
286
306
  def initialize(options)
287
307
  @options = options
288
-
289
- # We need to include this individually in each instance
290
- # because of an icky Ruby restriction
291
- class << self; include Sass::Script::Functions; end
292
308
  end
293
309
 
294
310
  # Asserts that the type of a given SassScript value
@@ -303,14 +319,31 @@ module Sass::Script
303
319
  # assert_type value, :Number
304
320
  # @param value [Sass::Script::Literal] A SassScript value
305
321
  # @param type [Symbol] The name of the type the value is expected to be
306
- def assert_type(value, type)
322
+ # @param name [String, nil] The name of the argument.
323
+ def assert_type(value, type, name = nil)
307
324
  return if value.is_a?(Sass::Script.const_get(type))
308
- raise ArgumentError.new("#{value.inspect} is not a #{type.to_s.downcase}")
325
+ err = "#{value.inspect} is not a #{type.to_s.downcase}"
326
+ err = "$#{name}: " + err if name
327
+ raise ArgumentError.new(err)
309
328
  end
310
329
  end
311
330
 
312
- instance_methods.each { |m| undef_method m unless m.to_s =~ /^__/ }
313
-
331
+ class << self
332
+ # Returns whether user function with a given name exists.
333
+ #
334
+ # @param function_name [String]
335
+ # @return [Boolean]
336
+ alias_method :callable?, :public_method_defined?
337
+
338
+ private
339
+ def include(*args)
340
+ r = super
341
+ # We have to re-include ourselves into EvaluationContext to work around
342
+ # an icky Ruby restriction.
343
+ EvaluationContext.send :include, self
344
+ r
345
+ end
346
+ end
314
347
 
315
348
  # Creates a {Color} object from red, green, and blue values.
316
349
  #
@@ -581,7 +614,7 @@ module Sass::Script
581
614
  # @raise [ArgumentError] If `color` isn't a color,
582
615
  # or `number` isn't a number between 0 and 1
583
616
  def opacify(color, amount)
584
- adjust(color, amount, :alpha, 0..1, :+)
617
+ _adjust(color, amount, :alpha, 0..1, :+)
585
618
  end
586
619
  declare :opacify, [:color, :amount]
587
620
 
@@ -602,7 +635,7 @@ module Sass::Script
602
635
  # @raise [ArgumentError] If `color` isn't a color,
603
636
  # or `number` isn't a number between 0 and 1
604
637
  def transparentize(color, amount)
605
- adjust(color, amount, :alpha, 0..1, :-)
638
+ _adjust(color, amount, :alpha, 0..1, :-)
606
639
  end
607
640
  declare :transparentize, [:color, :amount]
608
641
 
@@ -623,7 +656,7 @@ module Sass::Script
623
656
  # @raise [ArgumentError] If `color` isn't a color,
624
657
  # or `number` isn't a number between 0% and 100%
625
658
  def lighten(color, amount)
626
- adjust(color, amount, :lightness, 0..100, :+, "%")
659
+ _adjust(color, amount, :lightness, 0..100, :+, "%")
627
660
  end
628
661
  declare :lighten, [:color, :amount]
629
662
 
@@ -641,7 +674,7 @@ module Sass::Script
641
674
  # @raise [ArgumentError] If `color` isn't a color,
642
675
  # or `number` isn't a number between 0% and 100%
643
676
  def darken(color, amount)
644
- adjust(color, amount, :lightness, 0..100, :-, "%")
677
+ _adjust(color, amount, :lightness, 0..100, :-, "%")
645
678
  end
646
679
  declare :darken, [:color, :amount]
647
680
 
@@ -659,7 +692,7 @@ module Sass::Script
659
692
  # @raise [ArgumentError] If `color` isn't a color,
660
693
  # or `number` isn't a number between 0% and 100%
661
694
  def saturate(color, amount)
662
- adjust(color, amount, :saturation, 0..100, :+, "%")
695
+ _adjust(color, amount, :saturation, 0..100, :+, "%")
663
696
  end
664
697
  declare :saturate, [:color, :amount]
665
698
 
@@ -677,7 +710,7 @@ module Sass::Script
677
710
  # @raise [ArgumentError] If `color` isn't a color,
678
711
  # or `number` isn't a number between 0% and 100%
679
712
  def desaturate(color, amount)
680
- adjust(color, amount, :saturation, 0..100, :-, "%")
713
+ _adjust(color, amount, :saturation, 0..100, :-, "%")
681
714
  end
682
715
  declare :desaturate, [:color, :amount]
683
716
 
@@ -700,6 +733,189 @@ module Sass::Script
700
733
  end
701
734
  declare :adjust_hue, [:color, :degrees]
702
735
 
736
+ # Adjusts one or more properties of a color.
737
+ # This can change the red, green, blue, hue, saturation, value, and alpha properties.
738
+ # The properties are specified as keyword arguments,
739
+ # and are added to or subtracted from the color's current value for that property.
740
+ #
741
+ # `$red`, `$green`, and `$blue` properties should be between 0 and 255.
742
+ # `$saturation` and `$lightness` should be between 0% and 100%.
743
+ # `$alpha` should be between 0 and 1.
744
+ #
745
+ # All properties are optional.
746
+ # You can't specify both RGB properties (`$red`, `$green`, `$blue`)
747
+ # and HSL properties (`$hue`, `$saturation`, `$value`) at the same time.
748
+ #
749
+ # @example
750
+ # adjust-color(#102030, $blue: 5) => #102035
751
+ # adjust-color(#102030, $red: -5, $blue: 5) => #0b2035
752
+ # adjust-color(hsl(25, 100%, 80%), $lightness: -30%, $alpha: -0.4) => hsla(25, 100%, 50%, 0.6)
753
+ # @param color [Color]
754
+ # @param red [Number]
755
+ # @param green [Number]
756
+ # @param blue [Number]
757
+ # @param hue [Number]
758
+ # @param saturation [Number]
759
+ # @param lightness [Number]
760
+ # @param alpha [Number]
761
+ # @return [Color]
762
+ # @raise [ArgumentError] if `color` is not a color,
763
+ # if any keyword argument is not a number,
764
+ # if any keyword argument is not in the legal range,
765
+ # if an unexpected keyword argument is given,
766
+ # or if both HSL and RGB properties are given.
767
+ def adjust_color(color, kwargs)
768
+ assert_type color, :Color
769
+ with = Sass::Util.map_hash({
770
+ "red" => [-255..255, ""],
771
+ "green" => [-255..255, ""],
772
+ "blue" => [-255..255, ""],
773
+ "hue" => nil,
774
+ "saturation" => [-100..100, "%"],
775
+ "lightness" => [-100..100, "%"],
776
+ "alpha" => [-1..1, ""]
777
+ }) do |name, (range, units)|
778
+
779
+ next unless val = kwargs.delete(name)
780
+ assert_type val, :Number, name
781
+ if range && !range.include?(val.value)
782
+ raise ArgumentError.new("$#{name}: Amount #{val} must be between #{range.first}#{units} and #{range.last}#{units}")
783
+ end
784
+ adjusted = color.send(name) + val.value
785
+ adjusted = [0, Sass::Util.restrict(adjusted, range)].max if range
786
+ [name.to_sym, adjusted]
787
+ end
788
+
789
+ unless kwargs.empty?
790
+ name, val = kwargs.to_a.first
791
+ raise ArgumentError.new("Unknown argument $#{name} (#{val})")
792
+ end
793
+
794
+ color.with(with)
795
+ end
796
+ declare :adjust_color, [:color], :var_kwargs => true
797
+
798
+ # Scales one or more properties of a color by a percentage value.
799
+ # Unlike \{#adjust_color adjust-color}, which changes a color's properties by fixed amounts,
800
+ # \{#scale_color scale-color} fluidly changes them based on how high or low they already are.
801
+ # That means that lightening an already-light color with \{#scale_color scale-color}
802
+ # won't change the lightness much,
803
+ # but lightening a dark color by the same amount will change it more dramatically.
804
+ # This has the benefit of making `scale-color($color, ...)` have a similar effect
805
+ # regardless of what `$color` is.
806
+ #
807
+ # For example, the lightness of a color can be anywhere between 0 and 100.
808
+ # If `scale-color($color, $lightness: 40%)` is called, the resulting color's lightness
809
+ # will be 40% of the way between its original lightness and 100.
810
+ # If `scale-color($color, $lightness: -40%)` is called instead,
811
+ # the lightness will be 40% of the way between the original and 0.
812
+ #
813
+ # This can change the red, green, blue, saturation, value, and alpha properties.
814
+ # The properties are specified as keyword arguments.
815
+ # All arguments should be percentages between 0% and 100%.
816
+ #
817
+ # All properties are optional.
818
+ # You can't specify both RGB properties (`$red`, `$green`, `$blue`)
819
+ # and HSL properties (`$saturation`, `$value`) at the same time.
820
+ #
821
+ # @example
822
+ # scale-color(hsl(120, 70, 80), $lightness: 50%) => hsl(120, 70, 90)
823
+ # scale-color(rgb(200, 150, 170), $green: -40%, $blue: 70%) => rgb(200, 90, 229)
824
+ # scale-color(hsl(200, 70, 80), $saturation: -90%, $alpha: -30%) => hsla(200, 7, 80, 0.7)
825
+ # @param color [Color]
826
+ # @param red [Number]
827
+ # @param green [Number]
828
+ # @param blue [Number]
829
+ # @param saturation [Number]
830
+ # @param lightness [Number]
831
+ # @param alpha [Number]
832
+ # @return [Color]
833
+ # @raise [ArgumentError] if `color` is not a color,
834
+ # if any keyword argument is not a percentage between 0% and 100%,
835
+ # if an unexpected keyword argument is given,
836
+ # or if both HSL and RGB properties are given.
837
+ def scale_color(color, kwargs)
838
+ assert_type color, :Color
839
+ with = Sass::Util.map_hash({
840
+ "red" => 255,
841
+ "green" => 255,
842
+ "blue" => 255,
843
+ "saturation" => 100,
844
+ "lightness" => 100,
845
+ "alpha" => 1
846
+ }) do |name, max|
847
+
848
+ next unless val = kwargs.delete(name)
849
+ assert_type val, :Number, name
850
+ if !(val.numerator_units == ['%'] && val.denominator_units.empty?)
851
+ raise ArgumentError.new("$#{name}: Amount #{val} must be a % (e.g. #{val.value}%)")
852
+ elsif !(-100..100).include?(val.value)
853
+ raise ArgumentError.new("$#{name}: Amount #{val} must be between -100% and 100%")
854
+ end
855
+
856
+ current = color.send(name)
857
+ scale = val.value/100.0
858
+ diff = scale > 0 ? max - current : current
859
+ [name.to_sym, current + diff*scale]
860
+ end
861
+
862
+ unless kwargs.empty?
863
+ name, val = kwargs.to_a.first
864
+ raise ArgumentError.new("Unknown argument $#{name} (#{val})")
865
+ end
866
+
867
+ color.with(with)
868
+ end
869
+ declare :scale_color, [:color], :var_kwargs => true
870
+
871
+ # Changes one or more properties of a color.
872
+ # This can change the red, green, blue, hue, saturation, value, and alpha properties.
873
+ # The properties are specified as keyword arguments,
874
+ # and replace the color's current value for that property.
875
+ #
876
+ # `$red`, `$green`, and `$blue` properties should be between 0 and 255.
877
+ # `$saturation` and `$lightness` should be between 0% and 100%.
878
+ # `$alpha` should be between 0 and 1.
879
+ #
880
+ # All properties are optional.
881
+ # You can't specify both RGB properties (`$red`, `$green`, `$blue`)
882
+ # and HSL properties (`$hue`, `$saturation`, `$value`) at the same time.
883
+ #
884
+ # @example
885
+ # change-color(#102030, $blue: 5) => #102005
886
+ # change-color(#102030, $red: 120, $blue: 5) => #782005
887
+ # change-color(hsl(25, 100%, 80%), $lightness: 40%, $alpha: 0.8) => hsla(25, 100%, 40%, 0.8)
888
+ # @param color [Color]
889
+ # @param red [Number]
890
+ # @param green [Number]
891
+ # @param blue [Number]
892
+ # @param hue [Number]
893
+ # @param saturation [Number]
894
+ # @param lightness [Number]
895
+ # @param alpha [Number]
896
+ # @return [Color]
897
+ # @raise [ArgumentError] if `color` is not a color,
898
+ # if any keyword argument is not a number,
899
+ # if any keyword argument is not in the legal range,
900
+ # if an unexpected keyword argument is given,
901
+ # or if both HSL and RGB properties are given.
902
+ def change_color(color, kwargs)
903
+ assert_type color, :Color
904
+ with = Sass::Util.map_hash(%w[red green blue hue saturation lightness alpha]) do |name, max|
905
+ next unless val = kwargs.delete(name)
906
+ assert_type val, :Number, name
907
+ [name.to_sym, val.value]
908
+ end
909
+
910
+ unless kwargs.empty?
911
+ name, val = kwargs.to_a.first
912
+ raise ArgumentError.new("Unknown argument $#{name} (#{val})")
913
+ end
914
+
915
+ color.with(with)
916
+ end
917
+ declare :change_color, [:color], :var_kwargs => true
918
+
703
919
  # Mixes together two colors.
704
920
  # Specifically, takes the average of each of the RGB components,
705
921
  # optionally weighted by the given percentage.
@@ -815,8 +1031,11 @@ module Sass::Script
815
1031
  # unquote("foo") => foo
816
1032
  # unquote(foo) => foo
817
1033
  def unquote(string)
818
- assert_type string, :String
819
- Sass::Script::String.new(string.value, :identifier)
1034
+ if string.is_a?(Sass::Script::String)
1035
+ Sass::Script::String.new(string.value, :identifier)
1036
+ else
1037
+ string
1038
+ end
820
1039
  end
821
1040
  declare :unquote, [:string]
822
1041
 
@@ -998,6 +1217,8 @@ module Sass::Script
998
1217
  raise ArgumentError.new("List index #{n} must be an integer")
999
1218
  elsif n.to_i < 1
1000
1219
  raise ArgumentError.new("List index #{n} must be greater than or equal to 1")
1220
+ elsif list.to_a.size == 0
1221
+ raise ArgumentError.new("List index is #{n} but list has no items")
1001
1222
  elsif n.to_i > (size = list.to_a.size)
1002
1223
  raise ArgumentError.new("List index is #{n} but list is only #{size} item#{'s' if size != 1} long")
1003
1224
  end
@@ -1030,8 +1251,8 @@ module Sass::Script
1030
1251
  unless %w[auto space comma].include?(separator.value)
1031
1252
  raise ArgumentError.new("Separator name must be space, comma, or auto")
1032
1253
  end
1033
- sep1 = list1.separator if list1.is_a?(Sass::Script::List)
1034
- sep2 = list2.separator if list2.is_a?(Sass::Script::List)
1254
+ sep1 = list1.separator if list1.is_a?(Sass::Script::List) && !list1.value.empty?
1255
+ sep2 = list2.separator if list2.is_a?(Sass::Script::List) && !list2.value.empty?
1035
1256
  Sass::Script::List.new(
1036
1257
  list1.to_a + list2.to_a,
1037
1258
  if separator.value == 'auto'
@@ -1078,6 +1299,23 @@ module Sass::Script
1078
1299
  declare :append, [:list, :val]
1079
1300
  declare :append, [:list, :val, :separator]
1080
1301
 
1302
+ # Returns one of two values based on the truth value of the first argument.
1303
+ #
1304
+ # @example
1305
+ # if(true, 1px, 2px) => 1px
1306
+ # if(false, 1px, 2px) => 2px
1307
+ # @param condition [Bool] Whether the first or second value will be returned.
1308
+ # @param if_true [Literal] The value that will be returned if `$condition` is true.
1309
+ # @param if_false [Literal] The value that will be returned if `$condition` is false.
1310
+ def if(condition, if_true, if_false)
1311
+ if condition.to_bool
1312
+ if_true
1313
+ else
1314
+ if_false
1315
+ end
1316
+ end
1317
+ declare :if, [:condition, :if_true, :if_false]
1318
+
1081
1319
  private
1082
1320
 
1083
1321
  # This method implements the pattern of transforming a numeric value into
@@ -1088,7 +1326,7 @@ module Sass::Script
1088
1326
  Sass::Script::Number.new(yield(value.value), value.numerator_units, value.denominator_units)
1089
1327
  end
1090
1328
 
1091
- def adjust(color, amount, attr, range, op, units = "")
1329
+ def _adjust(color, amount, attr, range, op, units = "")
1092
1330
  assert_type color, :Color
1093
1331
  assert_type amount, :Number
1094
1332
  unless range.include?(amount.value)
@@ -87,7 +87,7 @@ module Sass
87
87
  :whitespace => /\s+/,
88
88
  :comment => COMMENT,
89
89
  :single_line_comment => SINGLE_LINE_COMMENT,
90
- :variable => /([!\$])(#{IDENT})/,
90
+ :variable => /(\$)(#{IDENT})/,
91
91
  :ident => /(#{IDENT})(\()?/,
92
92
  :number => /(-)?(?:(\d*\.\d+)|(\d+))([a-zA-Z%]+)?/,
93
93
  :color => HEXCOLOR,
@@ -242,9 +242,6 @@ module Sass
242
242
  line = @line
243
243
  offset = @offset
244
244
  return unless scan(rx)
245
- if @scanner[1] == '!' && @scanner[2] != 'important'
246
- Script.var_warning(@scanner[2], line, offset + 1, @options[:filename])
247
- end
248
245
 
249
246
  [:const, @scanner[2]]
250
247
  end
@@ -33,7 +33,8 @@ module Sass::Script
33
33
 
34
34
  # @see Node#to_s
35
35
  def to_s(opts = {})
36
- return value.map {|e| e.to_s(opts)}.join(sep_str)
36
+ raise Sass::SyntaxError.new("() isn't a valid CSS value.") if value.empty?
37
+ return value.reject {|e| e.is_a?(List) && e.value.empty?}.map {|e| e.to_s(opts)}.join(sep_str)
37
38
  end
38
39
 
39
40
  # @see Node#to_sass
@@ -61,7 +62,6 @@ module Sass::Script
61
62
  value.map {|e| e.perform(environment)},
62
63
  separator)
63
64
  list.options = self.options
64
- list.context = self.context
65
65
  list
66
66
  end
67
67
 
@@ -8,18 +8,6 @@ module Sass::Script
8
8
  # @return [{Symbol => Object}]
9
9
  attr_reader :options
10
10
 
11
- # The context in which this node was parsed,
12
- # which determines how some operations are performed.
13
- #
14
- # Can be `:equals`, which means it's part of a `$var = val` or `prop = val` assignment,
15
- # or `:default`, which means it's anywhere else
16
- # (including `$var: val` and `prop: val` assignments,
17
- # `#{}`-interpolations,
18
- # and other script contexts such as `@if` conditions).
19
- #
20
- # @return [Symbol]
21
- attr_reader :context
22
-
23
11
  # The line of the document on which this node appeared.
24
12
  #
25
13
  # @return [Fixnum]
@@ -41,21 +29,6 @@ module Sass::Script
41
29
  end
42
30
  end
43
31
 
44
- # Sets the context for this node,
45
- # as well as for all child nodes.
46
- #
47
- # @param context [Symbol]
48
- # @see #context
49
- def context=(context)
50
- @context = context
51
- children.each {|c| c.context = context}
52
- end
53
-
54
- # Creates a new script node.
55
- def initialize
56
- @context = :default
57
- end
58
-
59
32
  # Evaluates the node.
60
33
  #
61
34
  # \{#perform} shouldn't be overridden directly;