sass 3.1.0.alpha.200 → 3.1.0.alpha.204
Sign up to get free protection for your applications and to get access to all the features.
- data/REVISION +1 -1
- data/VERSION +1 -1
- data/lib/sass/plugin/compiler.rb +6 -3
- data/lib/sass/script/color.rb +4 -4
- data/lib/sass/script/funcall.rb +18 -3
- data/lib/sass/script/functions.rb +202 -9
- data/lib/sass/scss/parser.rb +41 -15
- data/lib/sass/tree/visitors/check_nesting.rb +27 -4
- data/lib/sass/tree/visitors/cssize.rb +2 -2
- data/test/sass/engine_test.rb +42 -2
- data/test/sass/functions_test.rb +270 -0
- data/test/sass/plugin_test.rb +8 -0
- data/test/sass/templates/nested_import.sass +2 -0
- metadata +7 -6
data/REVISION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
34fb8b49f9c4ca99b1d59d7d63761a72d0210f5a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.1.0.alpha.
|
1
|
+
3.1.0.alpha.204
|
data/lib/sass/plugin/compiler.rb
CHANGED
@@ -161,12 +161,15 @@ module Sass::Plugin
|
|
161
161
|
# the second is the location of the CSS file that it should be compiled to.
|
162
162
|
def update_stylesheets(individual_files = [])
|
163
163
|
run_updating_stylesheets individual_files
|
164
|
-
|
165
|
-
individual_files.each {|t, c| update_stylesheet(t, c)}
|
166
|
-
|
167
164
|
@checked_for_updates = true
|
168
165
|
staleness_checker = StalenessChecker.new(engine_options)
|
169
166
|
|
167
|
+
individual_files.each do |t, c|
|
168
|
+
if options[:always_update] || staleness_checker.stylesheet_needs_update?(c, t)
|
169
|
+
update_stylesheet(t, c)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
170
173
|
template_location_array.each do |template_location, css_location|
|
171
174
|
|
172
175
|
Dir.glob(File.join(template_location, "**", "[^_]*.s[ca]ss")).sort.each do |file|
|
data/lib/sass/script/color.rb
CHANGED
@@ -102,7 +102,7 @@ module Sass::Script
|
|
102
102
|
next if @attrs[k].nil?
|
103
103
|
@attrs[k] = @attrs[k].to_i
|
104
104
|
next if (0..255).include?(@attrs[k])
|
105
|
-
raise
|
105
|
+
raise ArgumentError.new("#{k.to_s.capitalize} value must be between 0 and 255")
|
106
106
|
end
|
107
107
|
|
108
108
|
[:saturation, :lightness].each do |k|
|
@@ -110,11 +110,11 @@ module Sass::Script
|
|
110
110
|
@attrs[k] = 0 if @attrs[k] < 0.00001 && @attrs[k] > -0.00001
|
111
111
|
@attrs[k] = 100 if @attrs[k] - 100 < 0.00001 && @attrs[k] - 100 > -0.00001
|
112
112
|
next if (0..100).include?(@attrs[k])
|
113
|
-
raise
|
113
|
+
raise ArgumentError.new("#{k.to_s.capitalize} must be between 0 and 100")
|
114
114
|
end
|
115
115
|
|
116
116
|
unless (0..1).include?(@attrs[:alpha])
|
117
|
-
raise
|
117
|
+
raise ArgumentError.new("Alpha channel must be between 0 and 1")
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
@@ -245,7 +245,7 @@ END
|
|
245
245
|
hsl = !([:hue, :saturation, :lightness] & attrs.keys).empty?
|
246
246
|
rgb = !([:red, :green, :blue] & attrs.keys).empty?
|
247
247
|
if hsl && rgb
|
248
|
-
raise ArgumentError.new("
|
248
|
+
raise ArgumentError.new("Cannot specify HSL and RGB values for a color at the same time")
|
249
249
|
end
|
250
250
|
|
251
251
|
if hsl
|
data/lib/sass/script/funcall.rb
CHANGED
@@ -96,16 +96,27 @@ module Sass
|
|
96
96
|
private
|
97
97
|
|
98
98
|
def construct_ruby_args(name, args, keywords)
|
99
|
-
return args if keywords.empty?
|
100
99
|
unless signature = Functions.signature(name.to_sym, args.size, keywords.size)
|
100
|
+
return args if keywords.empty?
|
101
101
|
raise Sass::SyntaxError.new("Function #{name} doesn't support keyword arguments")
|
102
102
|
end
|
103
103
|
|
104
|
+
# If the user passes more non-keyword args than the function expects,
|
105
|
+
# but it does expect keyword args, Ruby's arg handling won't raise an error.
|
106
|
+
# Since we don't want to make functions think about this,
|
107
|
+
# we'll handle it for them here.
|
108
|
+
if signature.var_kwargs && !signature.var_args && args.size > signature.args.size
|
109
|
+
raise Sass::SyntaxError.new(
|
110
|
+
"#{args[signature.args.size].inspect} is not a keyword argument for `#{name}'")
|
111
|
+
elsif keywords.empty?
|
112
|
+
return args
|
113
|
+
end
|
114
|
+
|
104
115
|
args = args + signature.args[args.size..-1].map do |argname|
|
105
116
|
if keywords.has_key?(argname)
|
106
117
|
keywords.delete(argname)
|
107
118
|
else
|
108
|
-
raise Sass::SyntaxError
|
119
|
+
raise Sass::SyntaxError.new("Function #{name} requires an argument named $#{argname}")
|
109
120
|
end
|
110
121
|
end
|
111
122
|
|
@@ -113,7 +124,7 @@ module Sass
|
|
113
124
|
if signature.var_kwargs
|
114
125
|
args << keywords
|
115
126
|
else
|
116
|
-
raise Sass::SyntaxError
|
127
|
+
raise Sass::SyntaxError.new("Function #{name} doesn't take an argument named $#{keywords.keys.sort.first}")
|
117
128
|
end
|
118
129
|
end
|
119
130
|
|
@@ -129,6 +140,10 @@ module Sass
|
|
129
140
|
end
|
130
141
|
end
|
131
142
|
|
143
|
+
if args.size > function.args.size
|
144
|
+
raise ArgumentError.new("Wrong number of arguments (#{args.size} for #{function.args.size})")
|
145
|
+
end
|
146
|
+
|
132
147
|
environment = function.args.zip(args).
|
133
148
|
inject(Sass::Environment.new(function.environment)) do |env, ((var, default), value)|
|
134
149
|
env.set_local_var(var.name,
|
@@ -88,6 +88,11 @@ 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 adjust($color, \[$red\], \[$green\], \[$blue\], \[$hue\], \[$saturation\], \[$lightness\], \[$alpha\]}
|
94
|
+
# : Increase or decrease any of the components of a color.
|
95
|
+
#
|
91
96
|
# ## String Functions
|
92
97
|
#
|
93
98
|
# \{#unquote unquote($string)}
|
@@ -228,6 +233,8 @@ module Sass::Script
|
|
228
233
|
# in addition to those in `:args`.
|
229
234
|
# If this is true, the Ruby function will be passed a hash from strings
|
230
235
|
# to {Sass::Script::Literal}s as the last argument.
|
236
|
+
# In addition, if this is true and `:var_args` is not,
|
237
|
+
# Sass will ensure that the last argument passed is a hash.
|
231
238
|
#
|
232
239
|
# @example
|
233
240
|
# declare :rgba, [:hex, :alpha]
|
@@ -308,9 +315,12 @@ module Sass::Script
|
|
308
315
|
# assert_type value, :Number
|
309
316
|
# @param value [Sass::Script::Literal] A SassScript value
|
310
317
|
# @param type [Symbol] The name of the type the value is expected to be
|
311
|
-
|
318
|
+
# @param name [String, nil] The name of the argument.
|
319
|
+
def assert_type(value, type, name = nil)
|
312
320
|
return if value.is_a?(Sass::Script.const_get(type))
|
313
|
-
|
321
|
+
err = "#{value.inspect} is not a #{type.to_s.downcase}"
|
322
|
+
err = "$#{name}: " + err if name
|
323
|
+
raise ArgumentError.new(err)
|
314
324
|
end
|
315
325
|
end
|
316
326
|
|
@@ -586,7 +596,7 @@ module Sass::Script
|
|
586
596
|
# @raise [ArgumentError] If `color` isn't a color,
|
587
597
|
# or `number` isn't a number between 0 and 1
|
588
598
|
def opacify(color, amount)
|
589
|
-
|
599
|
+
_adjust(color, amount, :alpha, 0..1, :+)
|
590
600
|
end
|
591
601
|
declare :opacify, [:color, :amount]
|
592
602
|
|
@@ -607,7 +617,7 @@ module Sass::Script
|
|
607
617
|
# @raise [ArgumentError] If `color` isn't a color,
|
608
618
|
# or `number` isn't a number between 0 and 1
|
609
619
|
def transparentize(color, amount)
|
610
|
-
|
620
|
+
_adjust(color, amount, :alpha, 0..1, :-)
|
611
621
|
end
|
612
622
|
declare :transparentize, [:color, :amount]
|
613
623
|
|
@@ -628,7 +638,7 @@ module Sass::Script
|
|
628
638
|
# @raise [ArgumentError] If `color` isn't a color,
|
629
639
|
# or `number` isn't a number between 0% and 100%
|
630
640
|
def lighten(color, amount)
|
631
|
-
|
641
|
+
_adjust(color, amount, :lightness, 0..100, :+, "%")
|
632
642
|
end
|
633
643
|
declare :lighten, [:color, :amount]
|
634
644
|
|
@@ -646,7 +656,7 @@ module Sass::Script
|
|
646
656
|
# @raise [ArgumentError] If `color` isn't a color,
|
647
657
|
# or `number` isn't a number between 0% and 100%
|
648
658
|
def darken(color, amount)
|
649
|
-
|
659
|
+
_adjust(color, amount, :lightness, 0..100, :-, "%")
|
650
660
|
end
|
651
661
|
declare :darken, [:color, :amount]
|
652
662
|
|
@@ -664,7 +674,7 @@ module Sass::Script
|
|
664
674
|
# @raise [ArgumentError] If `color` isn't a color,
|
665
675
|
# or `number` isn't a number between 0% and 100%
|
666
676
|
def saturate(color, amount)
|
667
|
-
|
677
|
+
_adjust(color, amount, :saturation, 0..100, :+, "%")
|
668
678
|
end
|
669
679
|
declare :saturate, [:color, :amount]
|
670
680
|
|
@@ -682,7 +692,7 @@ module Sass::Script
|
|
682
692
|
# @raise [ArgumentError] If `color` isn't a color,
|
683
693
|
# or `number` isn't a number between 0% and 100%
|
684
694
|
def desaturate(color, amount)
|
685
|
-
|
695
|
+
_adjust(color, amount, :saturation, 0..100, :-, "%")
|
686
696
|
end
|
687
697
|
declare :desaturate, [:color, :amount]
|
688
698
|
|
@@ -705,6 +715,189 @@ module Sass::Script
|
|
705
715
|
end
|
706
716
|
declare :adjust_hue, [:color, :degrees]
|
707
717
|
|
718
|
+
# Adjusts one or more properties of a color.
|
719
|
+
# This can change the red, green, blue, hue, saturation, value, and alpha properties.
|
720
|
+
# The properties are specified as keyword arguments,
|
721
|
+
# and are added to or subtracted from the color's current value for that property.
|
722
|
+
#
|
723
|
+
# `$red`, `$green`, and `$blue` properties should be between 0 and 255.
|
724
|
+
# `$saturation` and `$lightness` should be between 0% and 100%.
|
725
|
+
# `$alpha` should be between 0 and 1.
|
726
|
+
#
|
727
|
+
# All properties are optional.
|
728
|
+
# You can't specify both RGB properties (`$red`, `$green`, `$blue`)
|
729
|
+
# and HSL properties (`$hue`, `$saturation`, `$value`) at the same time.
|
730
|
+
#
|
731
|
+
# @example
|
732
|
+
# adjust(#102030, $blue: 5) => #102035
|
733
|
+
# adjust(#102030, $red: -5, $blue: 5) => #0b2035
|
734
|
+
# adjust(hsl(25, 100%, 80%), $lightness: -30%, $alpha: -0.4) => hsla(25, 100%, 50%, 0.6)
|
735
|
+
# @param color [Color]
|
736
|
+
# @param red [Number]
|
737
|
+
# @param green [Number]
|
738
|
+
# @param blue [Number]
|
739
|
+
# @param hue [Number]
|
740
|
+
# @param saturation [Number]
|
741
|
+
# @param lightness [Number]
|
742
|
+
# @param alpha [Number]
|
743
|
+
# @return [Color]
|
744
|
+
# @raise [ArgumentError] if `color` is not a color,
|
745
|
+
# if any keyword argument is not a number,
|
746
|
+
# if any keyword argument is not in the legal range,
|
747
|
+
# if an unexpected keyword argument is given,
|
748
|
+
# or if both HSL and RGB properties are given.
|
749
|
+
def adjust(color, kwargs)
|
750
|
+
assert_type color, :Color
|
751
|
+
with = Sass::Util.map_hash({
|
752
|
+
"red" => [-255..255, ""],
|
753
|
+
"green" => [-255..255, ""],
|
754
|
+
"blue" => [-255..255, ""],
|
755
|
+
"hue" => nil,
|
756
|
+
"saturation" => [-100..100, "%"],
|
757
|
+
"lightness" => [-100..100, "%"],
|
758
|
+
"alpha" => [-1..1, ""]
|
759
|
+
}) do |name, (range, units)|
|
760
|
+
|
761
|
+
next unless val = kwargs.delete(name)
|
762
|
+
assert_type val, :Number, name
|
763
|
+
if range && !range.include?(val.value)
|
764
|
+
raise ArgumentError.new("$#{name}: Amount #{val} must be between #{range.first}#{units} and #{range.last}#{units}")
|
765
|
+
end
|
766
|
+
adjusted = color.send(name) + val.value
|
767
|
+
adjusted = [0, Sass::Util.restrict(adjusted, range)].max if range
|
768
|
+
[name.to_sym, adjusted]
|
769
|
+
end
|
770
|
+
|
771
|
+
unless kwargs.empty?
|
772
|
+
name, val = kwargs.to_a.first
|
773
|
+
raise ArgumentError.new("Unknown argument $#{name} (#{val})")
|
774
|
+
end
|
775
|
+
|
776
|
+
color.with(with)
|
777
|
+
end
|
778
|
+
declare :adjust, [:color], :var_kwargs => true
|
779
|
+
|
780
|
+
# Scales one or more properties of a color by a percentage value.
|
781
|
+
# Unlike \{#adjust}, which changes a color's properties by fixed amounts,
|
782
|
+
# \{#scale} fluidly changes them based on how high or low they already are.
|
783
|
+
# That means that lightening an already-light color with \{#scale}
|
784
|
+
# won't change the lightness much,
|
785
|
+
# but lightening a dark color by the same amount will change it more dramatically.
|
786
|
+
# This has the benefit of making `scale($color, ...)` have a similar effect
|
787
|
+
# regardless of what `$color` is.
|
788
|
+
#
|
789
|
+
# For example, the lightness of a color can be anywhere between 0 and 100.
|
790
|
+
# If `scale($color, $lightness: 40%)` is called, the resulting color's lightness
|
791
|
+
# will be 40% of the way between its original lightness and 100.
|
792
|
+
# If `scale($color, $lightness: -40%)` is called instead,
|
793
|
+
# the lightness will be 40% of the way between the original and 0.
|
794
|
+
#
|
795
|
+
# This can change the red, green, blue, saturation, value, and alpha properties.
|
796
|
+
# The properties are specified as keyword arguments.
|
797
|
+
# All arguments should be percentages between 0% and 100%.
|
798
|
+
#
|
799
|
+
# All properties are optional.
|
800
|
+
# You can't specify both RGB properties (`$red`, `$green`, `$blue`)
|
801
|
+
# and HSL properties (`$saturation`, `$value`) at the same time.
|
802
|
+
#
|
803
|
+
# @example
|
804
|
+
# scale(hsl(120, 70, 80), $lightness: 50%) => hsl(120, 70, 90)
|
805
|
+
# scale(rgb(200, 150, 170), $green: -40%, $blue: 70%) => rgb(200, 90, 229)
|
806
|
+
# scale(hsl(200, 70, 80), $saturation: -90%, $alpha: -30%) => hsla(200, 7, 80, 0.7)
|
807
|
+
# @param color [Color]
|
808
|
+
# @param red [Number]
|
809
|
+
# @param green [Number]
|
810
|
+
# @param blue [Number]
|
811
|
+
# @param saturation [Number]
|
812
|
+
# @param lightness [Number]
|
813
|
+
# @param alpha [Number]
|
814
|
+
# @return [Color]
|
815
|
+
# @raise [ArgumentError] if `color` is not a color,
|
816
|
+
# if any keyword argument is not a percentage between 0% and 100%,
|
817
|
+
# if an unexpected keyword argument is given,
|
818
|
+
# or if both HSL and RGB properties are given.
|
819
|
+
def scale(color, kwargs)
|
820
|
+
assert_type color, :Color
|
821
|
+
with = Sass::Util.map_hash({
|
822
|
+
"red" => 255,
|
823
|
+
"green" => 255,
|
824
|
+
"blue" => 255,
|
825
|
+
"saturation" => 100,
|
826
|
+
"lightness" => 100,
|
827
|
+
"alpha" => 1
|
828
|
+
}) do |name, max|
|
829
|
+
|
830
|
+
next unless val = kwargs.delete(name)
|
831
|
+
assert_type val, :Number, name
|
832
|
+
if !(val.numerator_units == ['%'] && val.denominator_units.empty?)
|
833
|
+
raise ArgumentError.new("$#{name}: Amount #{val} must be a % (e.g. #{val.value}%)")
|
834
|
+
elsif !(-100..100).include?(val.value)
|
835
|
+
raise ArgumentError.new("$#{name}: Amount #{val} must be between -100% and 100%")
|
836
|
+
end
|
837
|
+
|
838
|
+
current = color.send(name)
|
839
|
+
scale = val.value/100.0
|
840
|
+
diff = scale > 0 ? max - current : current
|
841
|
+
[name.to_sym, current + diff*scale]
|
842
|
+
end
|
843
|
+
|
844
|
+
unless kwargs.empty?
|
845
|
+
name, val = kwargs.to_a.first
|
846
|
+
raise ArgumentError.new("Unknown argument $#{name} (#{val})")
|
847
|
+
end
|
848
|
+
|
849
|
+
color.with(with)
|
850
|
+
end
|
851
|
+
declare :scale, [:color], :var_kwargs => true
|
852
|
+
|
853
|
+
# Sets on or more properties of a color.
|
854
|
+
# This can set the red, green, blue, hue, saturation, value, and alpha properties.
|
855
|
+
# The properties are specified as keyword arguments,
|
856
|
+
# and replace the color's current value for that property.
|
857
|
+
#
|
858
|
+
# `$red`, `$green`, and `$blue` properties should be between 0 and 255.
|
859
|
+
# `$saturation` and `$lightness` should be between 0% and 100%.
|
860
|
+
# `$alpha` should be between 0 and 1.
|
861
|
+
#
|
862
|
+
# All properties are optional.
|
863
|
+
# You can't specify both RGB properties (`$red`, `$green`, `$blue`)
|
864
|
+
# and HSL properties (`$hue`, `$saturation`, `$value`) at the same time.
|
865
|
+
#
|
866
|
+
# @example
|
867
|
+
# set(#102030, $blue: 5) => #102005
|
868
|
+
# set(#102030, $red: 120, $blue: 5) => #782005
|
869
|
+
# set(hsl(25, 100%, 80%), $lightness: 40%, $alpha: 0.8) => hsla(25, 100%, 40%, 0.8)
|
870
|
+
# @param color [Color]
|
871
|
+
# @param red [Number]
|
872
|
+
# @param green [Number]
|
873
|
+
# @param blue [Number]
|
874
|
+
# @param hue [Number]
|
875
|
+
# @param saturation [Number]
|
876
|
+
# @param lightness [Number]
|
877
|
+
# @param alpha [Number]
|
878
|
+
# @return [Color]
|
879
|
+
# @raise [ArgumentError] if `color` is not a color,
|
880
|
+
# if any keyword argument is not a number,
|
881
|
+
# if any keyword argument is not in the legal range,
|
882
|
+
# if an unexpected keyword argument is given,
|
883
|
+
# or if both HSL and RGB properties are given.
|
884
|
+
def set(color, kwargs)
|
885
|
+
assert_type color, :Color
|
886
|
+
with = Sass::Util.map_hash(%w[red green blue hue saturation lightness alpha]) do |name, max|
|
887
|
+
next unless val = kwargs.delete(name)
|
888
|
+
assert_type val, :Number, name
|
889
|
+
[name.to_sym, val.value]
|
890
|
+
end
|
891
|
+
|
892
|
+
unless kwargs.empty?
|
893
|
+
name, val = kwargs.to_a.first
|
894
|
+
raise ArgumentError.new("Unknown argument $#{name} (#{val})")
|
895
|
+
end
|
896
|
+
|
897
|
+
color.with(with)
|
898
|
+
end
|
899
|
+
declare :set, [:color], :var_kwargs => true
|
900
|
+
|
708
901
|
# Mixes together two colors.
|
709
902
|
# Specifically, takes the average of each of the RGB components,
|
710
903
|
# optionally weighted by the given percentage.
|
@@ -1110,7 +1303,7 @@ module Sass::Script
|
|
1110
1303
|
Sass::Script::Number.new(yield(value.value), value.numerator_units, value.denominator_units)
|
1111
1304
|
end
|
1112
1305
|
|
1113
|
-
def
|
1306
|
+
def _adjust(color, amount, attr, range, op, units = "")
|
1114
1307
|
assert_type color, :Color
|
1115
1308
|
assert_type amount, :Number
|
1116
1309
|
unless range.include?(amount.value)
|
data/lib/sass/scss/parser.rb
CHANGED
@@ -236,8 +236,7 @@ module Sass
|
|
236
236
|
end
|
237
237
|
|
238
238
|
def else_directive
|
239
|
-
|
240
|
-
"Invalid CSS: @else must come after @if", :line => @line)
|
239
|
+
err("Invalid CSS: @else must come after @if")
|
241
240
|
end
|
242
241
|
|
243
242
|
def extend_directive
|
@@ -403,11 +402,9 @@ module Sass
|
|
403
402
|
# no colon after the identifier, whitespace after the colon),
|
404
403
|
# but I'm not sure the gains would be worth the added complexity.
|
405
404
|
def declaration_or_ruleset
|
406
|
-
pos = @scanner.pos
|
407
|
-
line = @line
|
408
405
|
old_use_property_exception, @use_property_exception =
|
409
406
|
@use_property_exception, false
|
410
|
-
|
407
|
+
decl_err = catch_error do
|
411
408
|
decl = declaration
|
412
409
|
unless decl && decl.has_children
|
413
410
|
# We want an exception if it's not there,
|
@@ -415,17 +412,10 @@ module Sass
|
|
415
412
|
tok!(/[;}]/) unless tok?(/[;}]/)
|
416
413
|
end
|
417
414
|
return decl
|
418
|
-
rescue Sass::SyntaxError => decl_err
|
419
415
|
end
|
420
416
|
|
421
|
-
|
422
|
-
@
|
423
|
-
|
424
|
-
begin
|
425
|
-
return ruleset
|
426
|
-
rescue Sass::SyntaxError => ruleset_err
|
427
|
-
raise @use_property_exception ? decl_err : ruleset_err
|
428
|
-
end
|
417
|
+
ruleset_err = catch_error {return ruleset}
|
418
|
+
rethrow(@use_property_exception ? decl_err : ruleset_err)
|
429
419
|
ensure
|
430
420
|
@use_property_exception = old_use_property_exception
|
431
421
|
end
|
@@ -684,7 +674,7 @@ MESSAGE
|
|
684
674
|
end
|
685
675
|
|
686
676
|
def nested_properties!(node, space)
|
687
|
-
|
677
|
+
err(<<MESSAGE) unless space
|
688
678
|
Invalid CSS: a space is required between a property and its definition
|
689
679
|
when it has other properties nested beneath it.
|
690
680
|
MESSAGE
|
@@ -798,6 +788,9 @@ MESSAGE
|
|
798
788
|
result = parser.send(*args)
|
799
789
|
@line = parser.line
|
800
790
|
result
|
791
|
+
rescue Sass::SyntaxError => e
|
792
|
+
throw(:_sass_parser_error, true) if @throw_error
|
793
|
+
raise e
|
801
794
|
end
|
802
795
|
|
803
796
|
def merge(arr)
|
@@ -844,9 +837,42 @@ MESSAGE
|
|
844
837
|
end
|
845
838
|
|
846
839
|
def expected(name)
|
840
|
+
throw(:_sass_parser_error, true) if @throw_error
|
847
841
|
self.class.expected(@scanner, @expected || name, @line)
|
848
842
|
end
|
849
843
|
|
844
|
+
def err(msg)
|
845
|
+
throw(:_sass_parser_error, true) if @throw_error
|
846
|
+
raise Sass::SyntaxError.new(msg, :line => @line)
|
847
|
+
end
|
848
|
+
|
849
|
+
def catch_error(&block)
|
850
|
+
old_throw_error, @throw_error = @throw_error, true
|
851
|
+
pos = @scanner.pos
|
852
|
+
line = @line
|
853
|
+
expected = @expected
|
854
|
+
if catch(:_sass_parser_error, &block)
|
855
|
+
@scanner.pos = pos
|
856
|
+
@line = line
|
857
|
+
@expected = expected
|
858
|
+
{:pos => pos, :line => line, :expected => @expected, :block => block}
|
859
|
+
end
|
860
|
+
ensure
|
861
|
+
@throw_error = old_throw_error
|
862
|
+
end
|
863
|
+
|
864
|
+
def rethrow(err)
|
865
|
+
if @throw_err
|
866
|
+
throw :_sass_parser_error, err
|
867
|
+
else
|
868
|
+
@scanner = StringScanner.new(@scanner.string)
|
869
|
+
@scanner.pos = err[:pos]
|
870
|
+
@line = err[:line]
|
871
|
+
@expected = err[:expected]
|
872
|
+
err[:block].call
|
873
|
+
end
|
874
|
+
end
|
875
|
+
|
850
876
|
# @private
|
851
877
|
def self.expected(scanner, expected, line)
|
852
878
|
pos = scanner.pos
|
@@ -3,9 +3,12 @@ class Sass::Tree::Visitors::CheckNesting < Sass::Tree::Visitors::Base
|
|
3
3
|
protected
|
4
4
|
|
5
5
|
def visit(node)
|
6
|
-
if error = @parent && (
|
7
|
-
|
8
|
-
|
6
|
+
if error = (@parent && (
|
7
|
+
try_send("invalid_#{node_name @parent}_child?", @parent, node) ||
|
8
|
+
try_send("invalid_#{node_name node}_parent?", @parent, node))) ||
|
9
|
+
(@real_parent && (
|
10
|
+
try_send("invalid_#{node_name @real_parent}_real_child?", @real_parent, node) ||
|
11
|
+
try_send("invalid_#{node_name node}_real_parent?", @real_parent, node)))
|
9
12
|
raise Sass::SyntaxError.new(error)
|
10
13
|
end
|
11
14
|
super
|
@@ -19,9 +22,11 @@ class Sass::Tree::Visitors::CheckNesting < Sass::Tree::Visitors::Base
|
|
19
22
|
@parent = parent unless is_any_of?(parent,
|
20
23
|
Sass::Tree::EachNode, Sass::Tree::ForNode, Sass::Tree::IfNode,
|
21
24
|
Sass::Tree::ImportNode, Sass::Tree::MixinNode, Sass::Tree::WhileNode)
|
25
|
+
old_real_parent, @real_parent = @real_parent, parent
|
22
26
|
super
|
23
27
|
ensure
|
24
28
|
@parent = old_parent
|
29
|
+
@real_parent = old_real_parent
|
25
30
|
end
|
26
31
|
|
27
32
|
def visit_root(node)
|
@@ -63,7 +68,24 @@ class Sass::Tree::Visitors::CheckNesting < Sass::Tree::Visitors::Base
|
|
63
68
|
end
|
64
69
|
|
65
70
|
def invalid_import_parent?(parent, child)
|
66
|
-
|
71
|
+
if is_any_of?(@real_parent, Sass::Tree::IfNode, Sass::Tree::ForNode, Sass::Tree::WhileNode,
|
72
|
+
Sass::Tree::EachNode, Sass::Tree::MixinDefNode)
|
73
|
+
return "Import directives may not be used within control directives or mixins."
|
74
|
+
end
|
75
|
+
return if parent.is_a?(Sass::Tree::RootNode)
|
76
|
+
return "CSS import directives may only be used at the root of a document." if child.css_import?
|
77
|
+
# If this is a nested @import, we need to make sure it doesn't have anything
|
78
|
+
# that's legal at top-level but not in the current context (e.g. mixin defs).
|
79
|
+
child.imported_file.to_tree.children.each {|c| visit(c)}
|
80
|
+
nil
|
81
|
+
rescue Sass::SyntaxError => e
|
82
|
+
e.modify_backtrace(:filename => child.imported_file.options[:filename])
|
83
|
+
e.add_backtrace(:filename => child.filename, :line => child.line)
|
84
|
+
raise e
|
85
|
+
end
|
86
|
+
|
87
|
+
def invalid_import_real_parent?(parent, child)
|
88
|
+
|
67
89
|
end
|
68
90
|
|
69
91
|
def invalid_mixindef_parent?(parent, child)
|
@@ -99,3 +121,4 @@ class Sass::Tree::Visitors::CheckNesting < Sass::Tree::Visitors::Base
|
|
99
121
|
send(method, *args, &block)
|
100
122
|
end
|
101
123
|
end
|
124
|
+
|
@@ -93,8 +93,8 @@ class Sass::Tree::Visitors::Cssize < Sass::Tree::Visitors::Base
|
|
93
93
|
|
94
94
|
# Modifies exception backtraces to include the imported file.
|
95
95
|
def visit_import(node)
|
96
|
-
|
97
|
-
node.children
|
96
|
+
# Don't use #visit_children to avoid adding the import node to the list of parents.
|
97
|
+
node.children.map {|c| visit(c)}.flatten
|
98
98
|
rescue Sass::SyntaxError => e
|
99
99
|
e.modify_backtrace(:filename => node.children.first.filename)
|
100
100
|
e.add_backtrace(:filename => node.filename, :line => node.line)
|
data/test/sass/engine_test.rb
CHANGED
@@ -64,8 +64,9 @@ File to import not found or unreadable: foo.sass.
|
|
64
64
|
Load path: .
|
65
65
|
MSG
|
66
66
|
"@import templates/basic\n foo" => "Illegal nesting: Nothing may be nested beneath import directives.",
|
67
|
-
"foo\n @import
|
68
|
-
"
|
67
|
+
"foo\n @import foo.css" => "CSS import directives may only be used at the root of a document.",
|
68
|
+
"@if true\n @import foo" => "Import directives may not be used within control directives or mixins.",
|
69
|
+
"@mixin foo\n @import foo" => "Import directives may not be used within control directives or mixins.",
|
69
70
|
'$foo: "bar" "baz" !' => %Q{Invalid CSS after ""bar" "baz" ": expected expression (e.g. 1px, bold), was "!"},
|
70
71
|
"=foo\n :color red\n.bar\n +bang" => "Undefined mixin 'bang'.",
|
71
72
|
"=foo\n :color red\n.bar\n +bang_bop" => "Undefined mixin 'bang_bop'.",
|
@@ -104,6 +105,8 @@ MSG
|
|
104
105
|
"@function foo()\n @return" => 'Invalid @return: expected expression.',
|
105
106
|
"@function foo()\n @return 1\n $var: val" => 'Illegal nesting: Nothing may be nested beneath return directives.',
|
106
107
|
"foo\n @function bar()\n @return 1" => ['Functions may only be defined at the root of a document.', 2],
|
108
|
+
"@function foo($a)\n @return 1\na\n b: foo()" => 'Function foo is missing parameter $a.',
|
109
|
+
"@function foo()\n @return 1\na\n b: foo(2)" => 'Wrong number of arguments (1 for 0) for `foo\'',
|
107
110
|
"@return 1" => '@return may only be used within a function.',
|
108
111
|
"@if true\n @return 1" => '@return may only be used within a function.',
|
109
112
|
"@mixin foo\n @return 1\n@include foo" => ['@return may only be used within a function.', 2],
|
@@ -587,6 +590,43 @@ ERR
|
|
587
590
|
assert !File.exists?(sassc_path("importee"))
|
588
591
|
end
|
589
592
|
|
593
|
+
def test_import_in_rule
|
594
|
+
assert_equal(<<CSS, render(<<SASS, :load_paths => [File.dirname(__FILE__) + '/templates/']))
|
595
|
+
.foo #foo {
|
596
|
+
background-color: #bbaaff; }
|
597
|
+
|
598
|
+
.bar {
|
599
|
+
a: b; }
|
600
|
+
.bar #foo {
|
601
|
+
background-color: #bbaaff; }
|
602
|
+
CSS
|
603
|
+
.foo
|
604
|
+
@import partial
|
605
|
+
|
606
|
+
.bar
|
607
|
+
a: b
|
608
|
+
@import partial
|
609
|
+
SASS
|
610
|
+
end
|
611
|
+
|
612
|
+
def test_nested_import_with_toplevel_constructs
|
613
|
+
Sass::Engine.new(".foo\n @import importee", :load_paths => [File.dirname(__FILE__) + '/templates/']).render
|
614
|
+
rescue Sass::SyntaxError => err
|
615
|
+
assert_equal(3, err.sass_line)
|
616
|
+
assert_match(/(\/|^)importee\.sass$/, err.sass_filename)
|
617
|
+
|
618
|
+
assert_hash_has(err.sass_backtrace.first,
|
619
|
+
:filename => err.sass_filename, :line => err.sass_line)
|
620
|
+
|
621
|
+
assert_nil(err.sass_backtrace[1][:filename])
|
622
|
+
assert_equal(2, err.sass_backtrace[1][:line])
|
623
|
+
|
624
|
+
assert_match(/(\/|^)importee\.sass:3$/, err.backtrace.first)
|
625
|
+
assert_equal("(sass):2", err.backtrace[1])
|
626
|
+
else
|
627
|
+
assert(false, "Exception not raised for importing mixins nested")
|
628
|
+
end
|
629
|
+
|
590
630
|
def test_units
|
591
631
|
renders_correctly "units"
|
592
632
|
end
|
data/test/sass/functions_test.rb
CHANGED
@@ -461,6 +461,276 @@ class SassFunctionTest < Test::Unit::TestCase
|
|
461
461
|
assert_error_message("\"foo\" is not a number for `adjust-hue'", "adjust-hue(#fff, \"foo\")")
|
462
462
|
end
|
463
463
|
|
464
|
+
def test_adjust
|
465
|
+
# HSL
|
466
|
+
assert_equal(evaluate("hsl(180, 30, 90)"),
|
467
|
+
evaluate("adjust(hsl(120, 30, 90), $hue: 60deg)"))
|
468
|
+
assert_equal(evaluate("hsl(120, 50, 90)"),
|
469
|
+
evaluate("adjust(hsl(120, 30, 90), $saturation: 20%)"))
|
470
|
+
assert_equal(evaluate("hsl(120, 30, 60)"),
|
471
|
+
evaluate("adjust(hsl(120, 30, 90), $lightness: -30%)"))
|
472
|
+
# RGB
|
473
|
+
assert_equal(evaluate("rgb(15, 20, 30)"),
|
474
|
+
evaluate("adjust(rgb(10, 20, 30), $red: 5)"))
|
475
|
+
assert_equal(evaluate("rgb(10, 15, 30)"),
|
476
|
+
evaluate("adjust(rgb(10, 20, 30), $green: -5)"))
|
477
|
+
assert_equal(evaluate("rgb(10, 20, 40)"),
|
478
|
+
evaluate("adjust(rgb(10, 20, 30), $blue: 10)"))
|
479
|
+
# Alpha
|
480
|
+
assert_equal(evaluate("hsla(120, 30, 90, 0.65)"),
|
481
|
+
evaluate("adjust(hsl(120, 30, 90), $alpha: -0.35)"))
|
482
|
+
assert_equal(evaluate("rgba(10, 20, 30, 0.9)"),
|
483
|
+
evaluate("adjust(rgba(10, 20, 30, 0.4), $alpha: 0.5)"))
|
484
|
+
|
485
|
+
# HSL composability
|
486
|
+
assert_equal(evaluate("hsl(180, 20, 90)"),
|
487
|
+
evaluate("adjust(hsl(120, 30, 90), $hue: 60deg, $saturation: -10%)"))
|
488
|
+
assert_equal(evaluate("hsl(180, 20, 95)"),
|
489
|
+
evaluate("adjust(hsl(120, 30, 90), $hue: 60deg, $saturation: -10%, $lightness: 5%)"))
|
490
|
+
assert_equal(evaluate("hsla(120, 20, 95, 0.3)"),
|
491
|
+
evaluate("adjust(hsl(120, 30, 90), $saturation: -10%, $lightness: 5%, $alpha: -0.7)"))
|
492
|
+
|
493
|
+
# RGB composability
|
494
|
+
assert_equal(evaluate("rgb(15, 20, 29)"),
|
495
|
+
evaluate("adjust(rgb(10, 20, 30), $red: 5, $blue: -1)"))
|
496
|
+
assert_equal(evaluate("rgb(15, 45, 29)"),
|
497
|
+
evaluate("adjust(rgb(10, 20, 30), $red: 5, $green: 25, $blue: -1)"))
|
498
|
+
assert_equal(evaluate("rgba(10, 25, 29, 0.7)"),
|
499
|
+
evaluate("adjust(rgb(10, 20, 30), $green: 5, $blue: -1, $alpha: -0.3)"))
|
500
|
+
|
501
|
+
# HSL range restriction
|
502
|
+
assert_equal(evaluate("hsl(120, 30, 90)"),
|
503
|
+
evaluate("adjust(hsl(120, 30, 90), $hue: 720deg)"))
|
504
|
+
assert_equal(evaluate("hsl(120, 0, 90)"),
|
505
|
+
evaluate("adjust(hsl(120, 30, 90), $saturation: -90%)"))
|
506
|
+
assert_equal(evaluate("hsl(120, 30, 100)"),
|
507
|
+
evaluate("adjust(hsl(120, 30, 90), $lightness: 30%)"))
|
508
|
+
|
509
|
+
# RGB range restriction
|
510
|
+
assert_equal(evaluate("rgb(255, 20, 30)"),
|
511
|
+
evaluate("adjust(rgb(10, 20, 30), $red: 250)"))
|
512
|
+
assert_equal(evaluate("rgb(10, 0, 30)"),
|
513
|
+
evaluate("adjust(rgb(10, 20, 30), $green: -30)"))
|
514
|
+
assert_equal(evaluate("rgb(10, 20, 0)"),
|
515
|
+
evaluate("adjust(rgb(10, 20, 30), $blue: -40)"))
|
516
|
+
end
|
517
|
+
|
518
|
+
def test_adjust_tests_types
|
519
|
+
assert_error_message("\"foo\" is not a color for `adjust'", "adjust(foo, $hue: 10)")
|
520
|
+
# HSL
|
521
|
+
assert_error_message("$hue: \"foo\" is not a number for `adjust'",
|
522
|
+
"adjust(blue, $hue: foo)")
|
523
|
+
assert_error_message("$saturation: \"foo\" is not a number for `adjust'",
|
524
|
+
"adjust(blue, $saturation: foo)")
|
525
|
+
assert_error_message("$lightness: \"foo\" is not a number for `adjust'",
|
526
|
+
"adjust(blue, $lightness: foo)")
|
527
|
+
# RGB
|
528
|
+
assert_error_message("$red: \"foo\" is not a number for `adjust'",
|
529
|
+
"adjust(blue, $red: foo)")
|
530
|
+
assert_error_message("$green: \"foo\" is not a number for `adjust'",
|
531
|
+
"adjust(blue, $green: foo)")
|
532
|
+
assert_error_message("$blue: \"foo\" is not a number for `adjust'",
|
533
|
+
"adjust(blue, $blue: foo)")
|
534
|
+
# Alpha
|
535
|
+
assert_error_message("$alpha: \"foo\" is not a number for `adjust'",
|
536
|
+
"adjust(blue, $alpha: foo)")
|
537
|
+
end
|
538
|
+
|
539
|
+
def test_adjust_tests_arg_range
|
540
|
+
# HSL
|
541
|
+
assert_error_message("$saturation: Amount 101% must be between -100% and 100% for `adjust'",
|
542
|
+
"adjust(blue, $saturation: 101%)")
|
543
|
+
assert_error_message("$saturation: Amount -101% must be between -100% and 100% for `adjust'",
|
544
|
+
"adjust(blue, $saturation: -101%)")
|
545
|
+
assert_error_message("$lightness: Amount 101% must be between -100% and 100% for `adjust'",
|
546
|
+
"adjust(blue, $lightness: 101%)")
|
547
|
+
assert_error_message("$lightness: Amount -101% must be between -100% and 100% for `adjust'",
|
548
|
+
"adjust(blue, $lightness: -101%)")
|
549
|
+
# RGB
|
550
|
+
assert_error_message("$red: Amount 256 must be between -255 and 255 for `adjust'",
|
551
|
+
"adjust(blue, $red: 256)")
|
552
|
+
assert_error_message("$red: Amount -256 must be between -255 and 255 for `adjust'",
|
553
|
+
"adjust(blue, $red: -256)")
|
554
|
+
assert_error_message("$green: Amount 256 must be between -255 and 255 for `adjust'",
|
555
|
+
"adjust(blue, $green: 256)")
|
556
|
+
assert_error_message("$green: Amount -256 must be between -255 and 255 for `adjust'",
|
557
|
+
"adjust(blue, $green: -256)")
|
558
|
+
assert_error_message("$blue: Amount 256 must be between -255 and 255 for `adjust'",
|
559
|
+
"adjust(blue, $blue: 256)")
|
560
|
+
assert_error_message("$blue: Amount -256 must be between -255 and 255 for `adjust'",
|
561
|
+
"adjust(blue, $blue: -256)")
|
562
|
+
# Alpha
|
563
|
+
assert_error_message("$alpha: Amount 1.1 must be between -1 and 1 for `adjust'",
|
564
|
+
"adjust(blue, $alpha: 1.1)")
|
565
|
+
assert_error_message("$alpha: Amount -1.1 must be between -1 and 1 for `adjust'",
|
566
|
+
"adjust(blue, $alpha: -1.1)")
|
567
|
+
end
|
568
|
+
|
569
|
+
def test_adjust_argument_errors
|
570
|
+
assert_error_message("Unknown argument $hoo (260deg) for `adjust'",
|
571
|
+
"adjust(blue, $hoo: 260deg)")
|
572
|
+
assert_error_message("Cannot specify HSL and RGB values for a color at the same time for `adjust'",
|
573
|
+
"adjust(blue, $hue: 120deg, $red: 10)");
|
574
|
+
assert_error_message("10px is not a keyword argument for `adjust'",
|
575
|
+
"adjust(blue, 10px)")
|
576
|
+
assert_error_message("10px is not a keyword argument for `adjust'",
|
577
|
+
"adjust(blue, 10px, 20px)")
|
578
|
+
assert_error_message("10px is not a keyword argument for `adjust'",
|
579
|
+
"adjust(blue, 10px, $hue: 180deg)")
|
580
|
+
end
|
581
|
+
|
582
|
+
def test_scale
|
583
|
+
# HSL
|
584
|
+
assert_equal(evaluate("hsl(120, 51, 90)"),
|
585
|
+
evaluate("scale(hsl(120, 30, 90), $saturation: 30%)"))
|
586
|
+
assert_equal(evaluate("hsl(120, 30, 76.5)"),
|
587
|
+
evaluate("scale(hsl(120, 30, 90), $lightness: -15%)"))
|
588
|
+
# RGB
|
589
|
+
assert_equal(evaluate("rgb(157, 20, 30)"),
|
590
|
+
evaluate("scale(rgb(10, 20, 30), $red: 60%)"))
|
591
|
+
assert_equal(evaluate("rgb(10, 38.8, 30)"),
|
592
|
+
evaluate("scale(rgb(10, 20, 30), $green: 8%)"))
|
593
|
+
assert_equal(evaluate("rgb(10, 20, 20)"),
|
594
|
+
evaluate("scale(rgb(10, 20, 30), $blue: -(1/3)*100%)"))
|
595
|
+
# Alpha
|
596
|
+
assert_equal(evaluate("hsla(120, 30, 90, 0.86)"),
|
597
|
+
evaluate("scale(hsl(120, 30, 90), $alpha: -14%)"))
|
598
|
+
assert_equal(evaluate("rgba(10, 20, 30, 0.82)"),
|
599
|
+
evaluate("scale(rgba(10, 20, 30, 0.8), $alpha: 10%)"))
|
600
|
+
|
601
|
+
# HSL composability
|
602
|
+
assert_equal(evaluate("hsl(120, 51, 76.5)"),
|
603
|
+
evaluate("scale(hsl(120, 30, 90), $saturation: 30%, $lightness: -15%)"))
|
604
|
+
assert_equal(evaluate("hsla(120, 51, 90, 0.2)"),
|
605
|
+
evaluate("scale(hsl(120, 30, 90), $saturation: 30%, $alpha: -80%)"))
|
606
|
+
|
607
|
+
# RGB composability
|
608
|
+
assert_equal(evaluate("rgb(157, 38.8, 30)"),
|
609
|
+
evaluate("scale(rgb(10, 20, 30), $red: 60%, $green: 8%)"))
|
610
|
+
assert_equal(evaluate("rgb(157, 38.8, 20)"),
|
611
|
+
evaluate("scale(rgb(10, 20, 30), $red: 60%, $green: 8%, $blue: -(1/3)*100%)"))
|
612
|
+
assert_equal(evaluate("rgba(10, 38.8, 20, 0.55)"),
|
613
|
+
evaluate("scale(rgba(10, 20, 30, 0.5), $green: 8%, $blue: -(1/3)*100%, $alpha: 10%)"))
|
614
|
+
|
615
|
+
# Extremes
|
616
|
+
assert_equal(evaluate("hsl(120, 100, 90)"),
|
617
|
+
evaluate("scale(hsl(120, 30, 90), $saturation: 100%)"))
|
618
|
+
assert_equal(evaluate("hsl(120, 30, 90)"),
|
619
|
+
evaluate("scale(hsl(120, 30, 90), $saturation: 0%)"))
|
620
|
+
assert_equal(evaluate("hsl(120, 0, 90)"),
|
621
|
+
evaluate("scale(hsl(120, 30, 90), $saturation: -100%)"))
|
622
|
+
end
|
623
|
+
|
624
|
+
def test_scale_tests_types
|
625
|
+
assert_error_message("\"foo\" is not a color for `scale'", "scale(foo, $red: 10%)")
|
626
|
+
# HSL
|
627
|
+
assert_error_message("$saturation: \"foo\" is not a number for `scale'",
|
628
|
+
"scale(blue, $saturation: foo)")
|
629
|
+
assert_error_message("$lightness: \"foo\" is not a number for `scale'",
|
630
|
+
"scale(blue, $lightness: foo)")
|
631
|
+
# RGB
|
632
|
+
assert_error_message("$red: \"foo\" is not a number for `scale'",
|
633
|
+
"scale(blue, $red: foo)")
|
634
|
+
assert_error_message("$green: \"foo\" is not a number for `scale'",
|
635
|
+
"scale(blue, $green: foo)")
|
636
|
+
assert_error_message("$blue: \"foo\" is not a number for `scale'",
|
637
|
+
"scale(blue, $blue: foo)")
|
638
|
+
# Alpha
|
639
|
+
assert_error_message("$alpha: \"foo\" is not a number for `scale'",
|
640
|
+
"scale(blue, $alpha: foo)")
|
641
|
+
end
|
642
|
+
|
643
|
+
def test_scale_argument_errors
|
644
|
+
# Range
|
645
|
+
assert_error_message("$saturation: Amount 101% must be between -100% and 100% for `scale'",
|
646
|
+
"scale(blue, $saturation: 101%)")
|
647
|
+
assert_error_message("$red: Amount -101% must be between -100% and 100% for `scale'",
|
648
|
+
"scale(blue, $red: -101%)")
|
649
|
+
assert_error_message("$alpha: Amount -101% must be between -100% and 100% for `scale'",
|
650
|
+
"scale(blue, $alpha: -101%)")
|
651
|
+
|
652
|
+
# Unit
|
653
|
+
assert_error_message("$saturation: Amount 80 must be a % (e.g. 80%) for `scale'",
|
654
|
+
"scale(blue, $saturation: 80)")
|
655
|
+
assert_error_message("$alpha: Amount 0.5 must be a % (e.g. 0.5%) for `scale'",
|
656
|
+
"scale(blue, $alpha: 0.5)")
|
657
|
+
|
658
|
+
# Unknown argument
|
659
|
+
assert_error_message("Unknown argument $hue (80%) for `scale'", "scale(blue, $hue: 80%)")
|
660
|
+
|
661
|
+
# Non-keyword arg
|
662
|
+
assert_error_message("10px is not a keyword argument for `scale'", "scale(blue, 10px)")
|
663
|
+
|
664
|
+
# HSL/RGB
|
665
|
+
assert_error_message("Cannot specify HSL and RGB values for a color at the same time for `scale'",
|
666
|
+
"scale(blue, $lightness: 10%, $red: 20%)");
|
667
|
+
end
|
668
|
+
|
669
|
+
def test_set
|
670
|
+
# HSL
|
671
|
+
assert_equal(evaluate("hsl(195, 30, 90)"),
|
672
|
+
evaluate("set(hsl(120, 30, 90), $hue: 195deg)"))
|
673
|
+
assert_equal(evaluate("hsl(120, 50, 90)"),
|
674
|
+
evaluate("set(hsl(120, 30, 90), $saturation: 50%)"))
|
675
|
+
assert_equal(evaluate("hsl(120, 30, 40)"),
|
676
|
+
evaluate("set(hsl(120, 30, 90), $lightness: 40%)"))
|
677
|
+
# RGB
|
678
|
+
assert_equal(evaluate("rgb(123, 20, 30)"),
|
679
|
+
evaluate("set(rgb(10, 20, 30), $red: 123)"))
|
680
|
+
assert_equal(evaluate("rgb(10, 234, 30)"),
|
681
|
+
evaluate("set(rgb(10, 20, 30), $green: 234)"))
|
682
|
+
assert_equal(evaluate("rgb(10, 20, 198)"),
|
683
|
+
evaluate("set(rgb(10, 20, 30), $blue: 198)"))
|
684
|
+
# Alpha
|
685
|
+
assert_equal(evaluate("rgba(10, 20, 30, 0.76)"),
|
686
|
+
evaluate("set(rgb(10, 20, 30), $alpha: 0.76)"))
|
687
|
+
|
688
|
+
# HSL composability
|
689
|
+
assert_equal(evaluate("hsl(56, 30, 47)"),
|
690
|
+
evaluate("set(hsl(120, 30, 90), $hue: 56deg, $lightness: 47%)"))
|
691
|
+
assert_equal(evaluate("hsla(56, 30, 47, 0.9)"),
|
692
|
+
evaluate("set(hsl(120, 30, 90), $hue: 56deg, $lightness: 47%, $alpha: 0.9)"))
|
693
|
+
end
|
694
|
+
|
695
|
+
def test_set_tests_types
|
696
|
+
assert_error_message("\"foo\" is not a color for `set'", "set(foo, $red: 10%)")
|
697
|
+
# HSL
|
698
|
+
assert_error_message("$saturation: \"foo\" is not a number for `set'",
|
699
|
+
"set(blue, $saturation: foo)")
|
700
|
+
assert_error_message("$lightness: \"foo\" is not a number for `set'",
|
701
|
+
"set(blue, $lightness: foo)")
|
702
|
+
# RGB
|
703
|
+
assert_error_message("$red: \"foo\" is not a number for `set'", "set(blue, $red: foo)")
|
704
|
+
assert_error_message("$green: \"foo\" is not a number for `set'", "set(blue, $green: foo)")
|
705
|
+
assert_error_message("$blue: \"foo\" is not a number for `set'", "set(blue, $blue: foo)")
|
706
|
+
# Alpha
|
707
|
+
assert_error_message("$alpha: \"foo\" is not a number for `set'", "set(blue, $alpha: foo)")
|
708
|
+
end
|
709
|
+
|
710
|
+
def test_set_argument_errors
|
711
|
+
# Range
|
712
|
+
assert_error_message("Saturation must be between 0 and 100 for `set'",
|
713
|
+
"set(blue, $saturation: 101%)")
|
714
|
+
assert_error_message("Lightness must be between 0 and 100 for `set'",
|
715
|
+
"set(blue, $lightness: 101%)")
|
716
|
+
assert_error_message("Red value must be between 0 and 255 for `set'",
|
717
|
+
"set(blue, $red: -1)")
|
718
|
+
assert_error_message("Green value must be between 0 and 255 for `set'",
|
719
|
+
"set(blue, $green: 256)")
|
720
|
+
assert_error_message("Blue value must be between 0 and 255 for `set'",
|
721
|
+
"set(blue, $blue: 500)")
|
722
|
+
|
723
|
+
# Unknown argument
|
724
|
+
assert_error_message("Unknown argument $hoo (80%) for `set'", "set(blue, $hoo: 80%)")
|
725
|
+
|
726
|
+
# Non-keyword arg
|
727
|
+
assert_error_message("10px is not a keyword argument for `set'", "set(blue, 10px)")
|
728
|
+
|
729
|
+
# HSL/RGB
|
730
|
+
assert_error_message("Cannot specify HSL and RGB values for a color at the same time for `set'",
|
731
|
+
"set(blue, $lightness: 10%, $red: 120)");
|
732
|
+
end
|
733
|
+
|
464
734
|
def test_mix
|
465
735
|
assert_equal("#7f007f", evaluate("mix(#f00, #00f)"))
|
466
736
|
assert_equal("#7f7f7f", evaluate("mix(#f00, #0ff)"))
|
data/test/sass/plugin_test.rb
CHANGED
@@ -74,6 +74,14 @@ class SassPluginTest < Test::Unit::TestCase
|
|
74
74
|
assert_stylesheet_updated 'scss_import'
|
75
75
|
end
|
76
76
|
|
77
|
+
def test_update_needed_when_nested_import_dependency_modified
|
78
|
+
touch 'basic'
|
79
|
+
assert_needs_update 'nested_import'
|
80
|
+
update_all_stylesheets!
|
81
|
+
assert_stylesheet_updated 'basic'
|
82
|
+
assert_stylesheet_updated 'scss_import'
|
83
|
+
end
|
84
|
+
|
77
85
|
def test_full_exception_handling
|
78
86
|
File.delete(tempfile_loc('bork1'))
|
79
87
|
update_all_stylesheets!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.0.alpha.
|
4
|
+
version: 3.1.0.alpha.204
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Weizenbaum
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2010-12-
|
14
|
+
date: 2010-12-17 00:00:00 -05:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -114,17 +114,17 @@ files:
|
|
114
114
|
- lib/sass/tree/debug_node.rb
|
115
115
|
- lib/sass/tree/directive_node.rb
|
116
116
|
- lib/sass/tree/extend_node.rb
|
117
|
-
- lib/sass/tree/if_node.rb
|
118
117
|
- lib/sass/tree/for_node.rb
|
118
|
+
- lib/sass/tree/if_node.rb
|
119
119
|
- lib/sass/tree/import_node.rb
|
120
|
+
- lib/sass/tree/mixin_def_node.rb
|
120
121
|
- lib/sass/tree/mixin_node.rb
|
121
122
|
- lib/sass/tree/node.rb
|
122
|
-
- lib/sass/tree/mixin_def_node.rb
|
123
123
|
- lib/sass/tree/prop_node.rb
|
124
124
|
- lib/sass/tree/root_node.rb
|
125
125
|
- lib/sass/tree/rule_node.rb
|
126
|
-
- lib/sass/tree/warn_node.rb
|
127
126
|
- lib/sass/tree/variable_node.rb
|
127
|
+
- lib/sass/tree/warn_node.rb
|
128
128
|
- lib/sass/tree/while_node.rb
|
129
129
|
- lib/sass/tree/each_node.rb
|
130
130
|
- lib/sass/tree/function_node.rb
|
@@ -248,10 +248,10 @@ files:
|
|
248
248
|
- test/sass/templates/nested_bork2.sass
|
249
249
|
- test/sass/templates/nested_bork3.sass
|
250
250
|
- test/sass/templates/nested_bork4.sass
|
251
|
+
- test/sass/templates/script.sass
|
251
252
|
- test/sass/templates/nested_mixin_bork.sass
|
252
253
|
- test/sass/templates/options.sass
|
253
254
|
- test/sass/templates/parent_ref.sass
|
254
|
-
- test/sass/templates/script.sass
|
255
255
|
- test/sass/templates/scss_import.scss
|
256
256
|
- test/sass/templates/scss_importee.scss
|
257
257
|
- test/sass/templates/subdir/nested_subdir/_nested_partial.sass
|
@@ -260,6 +260,7 @@ files:
|
|
260
260
|
- test/sass/templates/units.sass
|
261
261
|
- test/sass/templates/warn.sass
|
262
262
|
- test/sass/templates/warn_imported.sass
|
263
|
+
- test/sass/templates/nested_import.sass
|
263
264
|
- test/sass/test_helper.rb
|
264
265
|
- test/sass/util/subset_map_test.rb
|
265
266
|
- test/sass/util_test.rb
|