sassy_hash 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/sassy_hash.rb +13 -7
- data/spec/sass_hash_spec.rb +33 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2IyYzhhNGVmZDdjOTYxZTRkYWNjYzczNjg0N2U2YTg2OTQ5NDEyZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWYwYzA4NzdkZjliMzdhN2JjMjNiNTljNzQyODk1NzM2ZTVkODUyMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjA5ODM3NjFmODlmMzQ4OWQ2YjE2MWY1MjYwODBmN2Q5MWJmMmE2MGRiMzZm
|
10
|
+
Mjk4YTExNTc2YTg5NTkxZTlhZWM3MmE5ZTM1ZjE5NmJmMzQ2MDcwZDg5NGY0
|
11
|
+
MTllZmE5NmI0ZjdhZWNkODg2NDA4ODI5MzVkZmM1MDcyNGRkZmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
M2RlODc3ZjMwMmVkYTJhNDg3OTgxN2IwZTA1MzlkZTFlNWIyNjVlNjVmODY4
|
14
|
+
NTliOWMyZDE4ZWI1YzUyMzhjZmEzMmUwYTMxMmFkMWJhNmEzMTlhM2E2ZWZh
|
15
|
+
ZTQwNWM0ZmRjZjNhZjg1YmQ4Mzg0NDBlNjA2YjQxNDhlODg3ZDg=
|
data/lib/sassy_hash.rb
CHANGED
@@ -2,10 +2,9 @@ require 'sass'
|
|
2
2
|
require 'sass/scss/rx'
|
3
3
|
class SassyHashException < Exception; end
|
4
4
|
class SassyHash < Hash
|
5
|
-
VERSION = "0.0.
|
5
|
+
VERSION = "0.0.6"
|
6
6
|
VALID_UNIT = %r{(?<unit>#{::Sass::SCSS::RX::NMSTART}#{::Sass::SCSS::RX::NMCHAR}|%*)}
|
7
|
-
VALID_NUMBER = %r{(?<
|
8
|
-
|
7
|
+
VALID_NUMBER = %r{((?<float>^[0-9]*\.[0-9]+)|(?<int>^[0-9]+))#{VALID_UNIT}}
|
9
8
|
def self.[](hash_values)
|
10
9
|
super(hash_values).tap do |hash|
|
11
10
|
hash.sassify!
|
@@ -34,18 +33,25 @@ class SassyHash < Hash
|
|
34
33
|
|
35
34
|
def self.sass_convert_value(value)
|
36
35
|
case value
|
37
|
-
when Integer,
|
38
|
-
return ::Sass::Script::Value::Number.new(value)
|
36
|
+
when Integer, Fixnum
|
37
|
+
return ::Sass::Script::Value::Number.new(value.to_i)
|
38
|
+
when Float
|
39
|
+
return ::Sass::Script::Value::Number.new(value.to_f)
|
39
40
|
when Symbol
|
40
41
|
return ::Sass::Script::Value::String.new(value.to_s)
|
41
42
|
when String
|
42
|
-
# color
|
43
|
+
# hex color
|
43
44
|
if value =~ ::Sass::SCSS::RX::HEXCOLOR
|
44
45
|
return ::Sass::Script::Value::Color.from_hex(value)
|
45
46
|
end
|
46
47
|
#number
|
47
48
|
if matches = value.match(VALID_NUMBER)
|
48
|
-
|
49
|
+
num = if matches[:float]
|
50
|
+
matches[:float].to_f
|
51
|
+
elsif matches[:int]
|
52
|
+
matches[:int].to_i
|
53
|
+
end
|
54
|
+
return ::Sass::Script::Value::Number.new(num, matches[:unit])
|
49
55
|
end
|
50
56
|
#string
|
51
57
|
return ::Sass::Script::Value::String.new(value)
|
data/spec/sass_hash_spec.rb
CHANGED
@@ -54,15 +54,47 @@ describe SassyHash do
|
|
54
54
|
sassy_hash[sass_value(:foo)].value[2].value[2].class.should eq(::Sass::Script::Value::Map)
|
55
55
|
end
|
56
56
|
|
57
|
+
it "should create a hash valid for a map" do
|
58
|
+
key = 'primaryColor'
|
59
|
+
hash = {'height' => '120px', key => '#111', 'foo' => 'bar'}
|
60
|
+
sassy_hash = SassyHash[hash]
|
61
|
+
sassy_hash[sass_value(key)].class.should eq(::Sass::Script::Value::Color)
|
62
|
+
sassy_hash[sass_value('height')].class.should eq(::Sass::Script::Value::Number)
|
63
|
+
sassy_hash[sass_value('foo')].class.should eq(::Sass::Script::Value::String)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should create nested maps with string keys" do
|
67
|
+
hash = {'foo' => {'bar' => {'baz' => 'hi'}}}
|
68
|
+
sassy_hash = SassyHash[hash]
|
69
|
+
sassy_hash[sass_value('foo')].value[sass_value('bar')].value[sass_value('baz')].value.should eq('hi')
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should create a valid integer number" do
|
73
|
+
hash = {:foo => "120px"}
|
74
|
+
sassy_hash = SassyHash[hash]
|
75
|
+
num = sassy_hash[sass_value(:foo)].value
|
76
|
+
num.class.should eq(Fixnum)
|
77
|
+
num.should eq(120)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should create a valid float number" do
|
81
|
+
hash = {:foo => '120.5px'}
|
82
|
+
sassy_hash = SassyHash[hash]
|
83
|
+
num = sassy_hash[sass_value(:foo)].value
|
84
|
+
num.class.should eq(Float)
|
85
|
+
num.should eq(120.5)
|
86
|
+
end
|
87
|
+
|
57
88
|
{
|
58
89
|
"#fff" => ::Sass::Script::Value::Color,
|
90
|
+
"#111" => ::Sass::Script::Value::Color,
|
59
91
|
"#eeeeee" => ::Sass::Script::Value::Color,
|
60
92
|
'foo' => ::Sass::Script::Value::String,
|
61
93
|
0 => ::Sass::Script::Value::Number,
|
62
94
|
1.0 => ::Sass::Script::Value::Number,
|
63
95
|
"1.0px" => ::Sass::Script::Value::Number,
|
64
96
|
'1px' => ::Sass::Script::Value::Number,
|
65
|
-
'120px'
|
97
|
+
'120px' => ::Sass::Script::Value::Number,
|
66
98
|
:foo => ::Sass::Script::Value::String,
|
67
99
|
true => ::Sass::Script::Value::Bool,
|
68
100
|
false => ::Sass::Script::Value::Bool
|