sass 3.3.0.alpha.184 → 3.3.0.alpha.195
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.rb +1 -0
- data/lib/sass/features.rb +44 -0
- data/lib/sass/script/functions.rb +28 -9
- data/lib/sass/script/value/bool.rb +20 -0
- data/lib/sass/script/value/number.rb +3 -4
- data/test/sass/functions_test.rb +17 -3
- metadata +5 -4
data/REVISION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
a1dbbf37b919e9b45043a2ade97e7d355609f9de
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.3.0.alpha.
|
1
|
+
3.3.0.alpha.195
|
data/VERSION_DATE
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
19 June 2013 23:49:23 GMT
|
data/lib/sass.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
# Provides `Sass.has_feature?` which allows for simple feature detection
|
4
|
+
# by providing a feature name.
|
5
|
+
module Sass
|
6
|
+
module Features
|
7
|
+
|
8
|
+
# This is the set of features that can be detected.
|
9
|
+
KNOWN_FEATURES = Set[*%w{
|
10
|
+
}]
|
11
|
+
|
12
|
+
# Check if a feature exists by name. This is used to implement
|
13
|
+
# the Sass function `feature-exists($feature)`
|
14
|
+
#
|
15
|
+
# @param feature_name [String] The case sensitive name of the feature to
|
16
|
+
# check if it exists in this version of Sass.
|
17
|
+
# @return [Boolean] whether the feature of that name exists.
|
18
|
+
def has_feature?(feature_name)
|
19
|
+
KNOWN_FEATURES.include?(feature_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Add a feature to Sass. Plugins can use this to easily expose their
|
23
|
+
# availability to end users. Plugins must prefix their feature
|
24
|
+
# names with a dash to distinguish them from official features.
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# Sass.add_feature("-import-globbing")
|
28
|
+
# Sass.add_feature("-math-cos")
|
29
|
+
#
|
30
|
+
#
|
31
|
+
# @param feature_name [String] The case sensitive name of the feature to
|
32
|
+
# to add to Sass. Must begin with a dash.
|
33
|
+
def add_feature(feature_name)
|
34
|
+
unless feature_name[0] == ?-
|
35
|
+
raise ArgumentError.new("Plugin feature names must begin with a dash")
|
36
|
+
end
|
37
|
+
KNOWN_FEATURES << feature_name
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
extend Features
|
42
|
+
end
|
43
|
+
|
44
|
+
|
@@ -176,6 +176,9 @@ module Sass::Script
|
|
176
176
|
#
|
177
177
|
# ## Introspection Functions
|
178
178
|
#
|
179
|
+
# \{#feature_exists feature-exists($feature)}
|
180
|
+
# : Returns whether the named feature exists in the current sass runtime.
|
181
|
+
#
|
179
182
|
# \{#type_of type-of($value)}
|
180
183
|
# : Returns the type of a value.
|
181
184
|
#
|
@@ -1318,6 +1321,20 @@ module Sass::Script
|
|
1318
1321
|
end
|
1319
1322
|
declare :type_of, [:value]
|
1320
1323
|
|
1324
|
+
# Returns true if the feature name specified exists in the current Sass runtime.
|
1325
|
+
#
|
1326
|
+
# @example
|
1327
|
+
# feature-exists(some-feature-that-exists) => true
|
1328
|
+
# feature-exists(what-is-this-i-dont-know) => false
|
1329
|
+
#
|
1330
|
+
# @param feature [Sass::Script::Value::String] The name of the feature to check
|
1331
|
+
# @return [Sass::Script::Value::Bool] Whether the feature is supported in this version of Sass.
|
1332
|
+
def feature_exists(feature)
|
1333
|
+
Sass::Script::Value::Bool.new(Sass.has_feature?(feature.value))
|
1334
|
+
end
|
1335
|
+
declare :feature_exists, [:feature]
|
1336
|
+
|
1337
|
+
|
1321
1338
|
# Inspects the unit of the number, returning it as a quoted string.
|
1322
1339
|
# Complex units are sorted in alphabetical order by numerator and denominator.
|
1323
1340
|
#
|
@@ -1481,28 +1498,30 @@ module Sass::Script
|
|
1481
1498
|
# Gets the nth item in a list.
|
1482
1499
|
#
|
1483
1500
|
# Note that unlike some languages, the first item in a Sass list is number 1,
|
1484
|
-
# the second number 2, and so forth.
|
1501
|
+
# the second number 2, and so forth. You can also use negative numbers to
|
1502
|
+
# count from the end of the list. So -1 is the last item, -2 is the
|
1503
|
+
# second-to-last item, etc.
|
1485
1504
|
#
|
1486
1505
|
# @example
|
1487
1506
|
# nth(10px 20px 30px, 1) => 10px
|
1488
1507
|
# nth((Helvetica, Arial, sans-serif), 3) => sans-serif
|
1508
|
+
# nth((red, green, blue), -2) => green
|
1489
1509
|
# @param list [Value] The list
|
1490
1510
|
# @param n [Sass::Script::Value::Number] The index into the list
|
1491
1511
|
# @return [Sass::Script::Value::Base] The nth item in the list
|
1492
|
-
# @raise [ArgumentError] If `n` isn't an integer between 1 and the list's length.
|
1512
|
+
# @raise [ArgumentError] If `n` isn't an integer whose absolute value is between 1 and the list's length.
|
1493
1513
|
def nth(list, n)
|
1494
1514
|
assert_type n, :Number
|
1495
|
-
if !n.int?
|
1496
|
-
raise ArgumentError.new("List index #{n} must be
|
1497
|
-
elsif n.to_i < 1
|
1498
|
-
raise ArgumentError.new("List index #{n} must be greater than or equal to 1")
|
1515
|
+
if !n.int? || n.to_i == 0
|
1516
|
+
raise ArgumentError.new("List index #{n} must be a non-zero integer")
|
1499
1517
|
elsif list.to_a.size == 0
|
1500
1518
|
raise ArgumentError.new("List index is #{n} but list has no items")
|
1501
|
-
elsif n.to_i > (size = list.to_a.size)
|
1519
|
+
elsif n.to_i.abs > (size = list.to_a.size)
|
1502
1520
|
raise ArgumentError.new("List index is #{n} but list is only #{size} item#{'s' if size != 1} long")
|
1503
1521
|
end
|
1504
1522
|
|
1505
|
-
|
1523
|
+
index = n.to_i > 0 ? n.to_i - 1 : n.to_i
|
1524
|
+
list.to_a[index]
|
1506
1525
|
end
|
1507
1526
|
declare :nth, [:list, :n]
|
1508
1527
|
|
@@ -1617,7 +1636,7 @@ module Sass::Script
|
|
1617
1636
|
if index
|
1618
1637
|
Sass::Script::Value::Number.new(index + 1)
|
1619
1638
|
else
|
1620
|
-
Sass::Script::Value::Bool
|
1639
|
+
Sass::Script::Value::Bool::FALSE
|
1621
1640
|
end
|
1622
1641
|
end
|
1623
1642
|
declare :index, [:list, :value]
|
@@ -1,6 +1,26 @@
|
|
1
1
|
module Sass::Script::Value
|
2
2
|
# A SassScript object representing a boolean (true or false) value.
|
3
3
|
class Bool < Base
|
4
|
+
|
5
|
+
# The true value in SassScript.
|
6
|
+
#
|
7
|
+
# This is assigned before new is overridden below so that we use the default implementation.
|
8
|
+
TRUE = new(true)
|
9
|
+
|
10
|
+
# The false value in SassScript.
|
11
|
+
#
|
12
|
+
# This is assigned before new is overridden below so that we use the default implementation.
|
13
|
+
FALSE = new(false)
|
14
|
+
|
15
|
+
# We override object creation so that users of the core API
|
16
|
+
# will not need to know that booleans are specific constants.
|
17
|
+
#
|
18
|
+
# @param value A ruby value that will be tested for truthiness.
|
19
|
+
# @return [Bool] TRUE if value is truthy, FALSE if value is falsey
|
20
|
+
def self.new(value)
|
21
|
+
value ? TRUE : FALSE
|
22
|
+
end
|
23
|
+
|
4
24
|
# The Ruby value of the boolean.
|
5
25
|
#
|
6
26
|
# @return [Boolean]
|
@@ -192,7 +192,7 @@ module Sass::Script::Value
|
|
192
192
|
# @param other [Value] The right-hand side of the operator
|
193
193
|
# @return [Boolean] Whether this number is equal to the other object
|
194
194
|
def eq(other)
|
195
|
-
return
|
195
|
+
return Bool::FALSE unless other.is_a?(Sass::Script::Value::Number)
|
196
196
|
this = self
|
197
197
|
begin
|
198
198
|
if unitless?
|
@@ -201,10 +201,9 @@ module Sass::Script::Value
|
|
201
201
|
other = other.coerce(@numerator_units, @denominator_units)
|
202
202
|
end
|
203
203
|
rescue Sass::UnitConversionError
|
204
|
-
return
|
204
|
+
return Bool::FALSE
|
205
205
|
end
|
206
|
-
|
207
|
-
Sass::Script::Value::Bool.new(this.value == other.value)
|
206
|
+
Bool.new(this.value == other.value)
|
208
207
|
end
|
209
208
|
|
210
209
|
# The SassScript `>` operation.
|
data/test/sass/functions_test.rb
CHANGED
@@ -977,6 +977,18 @@ MSG
|
|
977
977
|
assert_equal("null", evaluate("type-of(null)"))
|
978
978
|
end
|
979
979
|
|
980
|
+
def test_feature_exists
|
981
|
+
assert_raises ArgumentError do
|
982
|
+
Sass.add_feature("my-test-feature")
|
983
|
+
end
|
984
|
+
Sass.add_feature("-my-test-feature")
|
985
|
+
assert_equal("true", evaluate("feature-exists(-my-test-feature)"))
|
986
|
+
assert_equal("false", evaluate("feature-exists(whatisthisidontevenknow)"))
|
987
|
+
assert_equal("true", evaluate("feature-exists($feature: -my-test-feature)"))
|
988
|
+
ensure
|
989
|
+
Sass::Features::KNOWN_FEATURES.delete("-my-test-feature")
|
990
|
+
end
|
991
|
+
|
980
992
|
def test_unit
|
981
993
|
assert_equal(%Q{""}, evaluate("unit(100)"))
|
982
994
|
assert_equal(%Q{"px"}, evaluate("unit(100px)"))
|
@@ -1017,12 +1029,14 @@ MSG
|
|
1017
1029
|
def test_nth
|
1018
1030
|
assert_equal("1", evaluate("nth(1 2 3, 1)"))
|
1019
1031
|
assert_equal("2", evaluate("nth(1 2 3, 2)"))
|
1032
|
+
assert_equal("3", evaluate("nth(1 2 3, -1)"))
|
1033
|
+
assert_equal("1", evaluate("nth(1 2 3, -3)"))
|
1020
1034
|
assert_equal("3", evaluate("nth((1, 2, 3), 3)"))
|
1021
1035
|
assert_equal("foo", evaluate("nth(foo, 1)"))
|
1022
1036
|
assert_equal("bar baz", evaluate("nth(foo (bar baz) bang, 2)"))
|
1023
|
-
assert_error_message("List index 0 must be
|
1024
|
-
assert_error_message("List index -10
|
1025
|
-
assert_error_message("List index 1.5 must be
|
1037
|
+
assert_error_message("List index 0 must be a non-zero integer for `nth'", "nth(foo, 0)")
|
1038
|
+
assert_error_message("List index is -10 but list is only 1 item long for `nth'", "nth(foo, -10)")
|
1039
|
+
assert_error_message("List index 1.5 must be a non-zero integer for `nth'", "nth(foo, 1.5)")
|
1026
1040
|
assert_error_message("List index is 5 but list is only 4 items long for `nth'", "nth(1 2 3 4, 5)")
|
1027
1041
|
assert_error_message("List index is 2 but list is only 1 item long for `nth'", "nth(foo, 2)")
|
1028
1042
|
assert_error_message("List index is 1 but list has no items for `nth'", "nth((), 1)")
|
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: 592302731
|
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
|
+
- 195
|
12
|
+
version: 3.3.0.alpha.195
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Nathan Weizenbaum
|
@@ -19,7 +19,7 @@ autorequire:
|
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
21
|
|
22
|
-
date: 2013-06-
|
22
|
+
date: 2013-06-19 00:00:00 -04:00
|
23
23
|
default_executable:
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
@@ -193,6 +193,7 @@ files:
|
|
193
193
|
- lib/sass/util/multibyte_string_scanner.rb
|
194
194
|
- lib/sass/util/subset_map.rb
|
195
195
|
- lib/sass/version.rb
|
196
|
+
- lib/sass/features.rb
|
196
197
|
- bin/sass
|
197
198
|
- bin/sass-convert
|
198
199
|
- bin/scss
|