sass 3.3.0.alpha.372 → 3.3.0.alpha.375
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/VERSION_DATE +1 -1
- data/lib/sass/script/functions.rb +42 -8
- data/lib/sass/script/tree/funcall.rb +14 -2
- data/test/sass/functions_test.rb +22 -1
- metadata +3 -3
data/REVISION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
5339def89cc7f0dbcc9f888a42fb8c571e2c326b
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.3.0.alpha.
|
1
|
+
3.3.0.alpha.375
|
data/VERSION_DATE
CHANGED
@@ -1 +1 @@
|
|
1
|
-
10 October 2013
|
1
|
+
10 October 2013 17:02:25 GMT
|
@@ -298,10 +298,12 @@ module Sass::Script
|
|
298
298
|
|
299
299
|
# A class representing a Sass function signature.
|
300
300
|
#
|
301
|
-
# @attr args [Array<
|
301
|
+
# @attr args [Array<String>] The names of the arguments to the function.
|
302
|
+
# @attr delayed_args [Array<String>] The names of the arguments whose evaluation should be
|
303
|
+
# delayed.
|
302
304
|
# @attr var_args [Boolean] Whether the function takes a variable number of arguments.
|
303
305
|
# @attr var_kwargs [Boolean] Whether the function takes an arbitrary set of keyword arguments.
|
304
|
-
Signature = Struct.new(:args, :var_args, :var_kwargs)
|
306
|
+
Signature = Struct.new(:args, :delayed_args, :var_args, :var_kwargs)
|
305
307
|
|
306
308
|
# Declare a Sass signature for a Ruby-defined function.
|
307
309
|
# This includes the names of the arguments,
|
@@ -338,9 +340,23 @@ module Sass::Script
|
|
338
340
|
# In addition, if this is true and `:var_args` is not,
|
339
341
|
# Sass will ensure that the last argument passed is a hash.
|
340
342
|
def self.declare(method_name, args, options = {})
|
343
|
+
delayed_args = []
|
344
|
+
args = args.map do |a|
|
345
|
+
a = a.to_s
|
346
|
+
if a[0] == ?&
|
347
|
+
a = a[1..-1]
|
348
|
+
delayed_args << a
|
349
|
+
end
|
350
|
+
a
|
351
|
+
end
|
352
|
+
# We don't expose this functionality except to certain builtin methods.
|
353
|
+
if delayed_args.any? && method_name != :if
|
354
|
+
raise ArgumentError.new("Delayed arguments are not allowed for method #{method_name}")
|
355
|
+
end
|
341
356
|
@signatures[method_name] ||= []
|
342
357
|
@signatures[method_name] << Signature.new(
|
343
|
-
args
|
358
|
+
args,
|
359
|
+
delayed_args,
|
344
360
|
options[:var_args],
|
345
361
|
options[:var_kwargs])
|
346
362
|
end
|
@@ -478,6 +494,24 @@ module Sass::Script
|
|
478
494
|
raise ArgumentError.new("Expected #{number} to be an integer")
|
479
495
|
end
|
480
496
|
end
|
497
|
+
|
498
|
+
# Performs a node that has been delayed for execution.
|
499
|
+
#
|
500
|
+
# @private
|
501
|
+
# @param node [Sass::Script::Tree::Node,
|
502
|
+
# Sass::Script::Value::Base] When this is a tree node, it's
|
503
|
+
# performed in the caller's environment. When it's a value
|
504
|
+
# (which can happen when the value had to be performed already
|
505
|
+
# -- like for a splat), it's returned as-is.
|
506
|
+
# @param env [Sass::Environment] The environment within which to perform the node.
|
507
|
+
# Defaults to the (read-only) environment of the caller.
|
508
|
+
def perform(node, env = environment.caller)
|
509
|
+
if node.is_a?(Sass::Script::Value::Base)
|
510
|
+
node
|
511
|
+
else
|
512
|
+
node.perform(env)
|
513
|
+
end
|
514
|
+
end
|
481
515
|
end
|
482
516
|
|
483
517
|
class << self
|
@@ -1963,17 +1997,17 @@ module Sass::Script
|
|
1963
1997
|
# @overload if($condition, $if-true, $if-false)
|
1964
1998
|
# @param $condition [Sass::Script::Value::Base] Whether the `$if-true` or
|
1965
1999
|
# `$if-false` will be returned
|
1966
|
-
# @param $if-true [Sass::Script::
|
1967
|
-
# @param $if-false [Sass::Script::
|
2000
|
+
# @param $if-true [Sass::Script::Tree::Node]
|
2001
|
+
# @param $if-false [Sass::Script::Tree::Node]
|
1968
2002
|
# @return [Sass::Script::Value::Base] `$if-true` or `$if-false`
|
1969
2003
|
def if(condition, if_true, if_false)
|
1970
2004
|
if condition.to_bool
|
1971
|
-
if_true
|
2005
|
+
perform(if_true)
|
1972
2006
|
else
|
1973
|
-
if_false
|
2007
|
+
perform(if_false)
|
1974
2008
|
end
|
1975
2009
|
end
|
1976
|
-
declare :if, [:condition, :if_true, :if_false]
|
2010
|
+
declare :if, [:condition, :"&if_true", :"&if_false"]
|
1977
2011
|
|
1978
2012
|
# Returns a unique CSS identifier. The identifier is returned as an unquoted
|
1979
2013
|
# string. The identifier returned is only guaranteed to be unique within the
|
@@ -119,9 +119,12 @@ module Sass::Script::Tree
|
|
119
119
|
# @return [Sass::Script::Value] The SassScript object that is the value of the function call
|
120
120
|
# @raise [Sass::SyntaxError] if the function call raises an ArgumentError
|
121
121
|
def _perform(environment)
|
122
|
-
args = @args.
|
122
|
+
args = Sass::Util.enum_with_index(@args).
|
123
|
+
map {|a, i| perform_arg(a, environment, signature && signature.args[i])}
|
123
124
|
splat = Sass::Tree::Visitors::Perform.perform_splat(@splat, @kwarg_splat, environment)
|
124
|
-
keywords = Sass::Util.map_hash(@keywords)
|
125
|
+
keywords = Sass::Util.map_hash(@keywords) do |k, v|
|
126
|
+
[k, perform_arg(v, environment, k.tr('-', '_'))]
|
127
|
+
end
|
125
128
|
if (fn = environment.function(@name))
|
126
129
|
return perform_sass_fn(fn, args, keywords, splat, environment)
|
127
130
|
end
|
@@ -203,6 +206,15 @@ module Sass::Script::Tree
|
|
203
206
|
|
204
207
|
private
|
205
208
|
|
209
|
+
def perform_arg(argument, environment, name)
|
210
|
+
return argument if signature && signature.delayed_args.include?(name)
|
211
|
+
argument.perform(environment)
|
212
|
+
end
|
213
|
+
|
214
|
+
def signature
|
215
|
+
@signature ||= Sass::Script::Functions.signature(name.to_sym, @args.size, @keywords.size)
|
216
|
+
end
|
217
|
+
|
206
218
|
def construct_ruby_args(name, args, keywords, splat, environment)
|
207
219
|
args += splat.to_a if splat
|
208
220
|
|
data/test/sass/functions_test.rb
CHANGED
@@ -1202,6 +1202,28 @@ MSG
|
|
1202
1202
|
assert_equal("1px", evaluate("if(true, 1px, 2px)"))
|
1203
1203
|
assert_equal("2px", evaluate("if(false, 1px, 2px)"))
|
1204
1204
|
assert_equal("2px", evaluate("if(null, 1px, 2px)"))
|
1205
|
+
assert_equal("1px", evaluate("if(true, 1px, $broken)"))
|
1206
|
+
assert_equal("1px", evaluate("if(false, $broken, 1px)"))
|
1207
|
+
assert_equal("1px", evaluate("if(false, $if-true: $broken, $if-false: 1px)"))
|
1208
|
+
assert_equal("1px", evaluate("if(true, $if-true: 1px, $if-false: $broken)"))
|
1209
|
+
assert_equal(<<CSS, render(<<SCSS))
|
1210
|
+
.if {
|
1211
|
+
result: yay; }
|
1212
|
+
CSS
|
1213
|
+
.if {
|
1214
|
+
$something: yay;
|
1215
|
+
result: if(true, $if-true: $something, $if-false: $broken);
|
1216
|
+
}
|
1217
|
+
SCSS
|
1218
|
+
assert_equal(<<CSS, render(<<SCSS))
|
1219
|
+
.if {
|
1220
|
+
result: 1px; }
|
1221
|
+
CSS
|
1222
|
+
.if {
|
1223
|
+
$splat: 1px, 2px;
|
1224
|
+
result: if(true, $splat...);
|
1225
|
+
}
|
1226
|
+
SCSS
|
1205
1227
|
end
|
1206
1228
|
|
1207
1229
|
def test_counter
|
@@ -1582,5 +1604,4 @@ SCSS
|
|
1582
1604
|
rescue Sass::SyntaxError => e
|
1583
1605
|
assert_equal(message, e.message)
|
1584
1606
|
end
|
1585
|
-
|
1586
1607
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 592302563
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 3
|
9
9
|
- 0
|
10
10
|
- alpha
|
11
|
-
-
|
12
|
-
version: 3.3.0.alpha.
|
11
|
+
- 375
|
12
|
+
version: 3.3.0.alpha.375
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Nathan Weizenbaum
|