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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDk3ODY3MjU0ZjMwOWVkZTQ4NDlhMGNkNzRmM2FhM2JkNzE2ZjdiNw==
4
+ M2IyYzhhNGVmZDdjOTYxZTRkYWNjYzczNjg0N2U2YTg2OTQ5NDEyZA==
5
5
  data.tar.gz: !binary |-
6
- OTE1MDYyNmI4NGY3NmUyOWJjY2YwZGIzODJkYTY1NjhhYzJjYjk5OA==
6
+ NWYwYzA4NzdkZjliMzdhN2JjMjNiNTljNzQyODk1NzM2ZTVkODUyMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDY3YWI5ZTRhYzUyNjdkNDg5OThkZmNmODg0MGNhZmRhZDJiMTdkZmJhNjM5
10
- MjRmMDFhZDhjOWMyMzI3NDJlZTgwZGY0OGI3NDY2MzZjZjI4ZDdmNWRlYzBi
11
- ODBkNTQ0ZDFhZWEwZmQ3MGZmNjkzYWQ1NDBmODVmMzYxZTUyM2Q=
9
+ NjA5ODM3NjFmODlmMzQ4OWQ2YjE2MWY1MjYwODBmN2Q5MWJmMmE2MGRiMzZm
10
+ Mjk4YTExNTc2YTg5NTkxZTlhZWM3MmE5ZTM1ZjE5NmJmMzQ2MDcwZDg5NGY0
11
+ MTllZmE5NmI0ZjdhZWNkODg2NDA4ODI5MzVkZmM1MDcyNGRkZmM=
12
12
  data.tar.gz: !binary |-
13
- MzUyYzU0ZWU3ZDNjOTlmN2YwY2MyN2MyMjllYTZlMmFlMzIyYWJjZjE4YTAy
14
- OTgzYTZhNzQ2MjEwMDgwZDc3ZDQyYzgxNTAxZmIzMDRiMTBlZGE0ZTA2MGI1
15
- MzY1MTllMGIxYzk0OTMwNmVkNGJlMTdjYjhjNzcyYjM1N2Y5YjM=
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"
5
+ VERSION = "0.0.6"
6
6
  VALID_UNIT = %r{(?<unit>#{::Sass::SCSS::RX::NMSTART}#{::Sass::SCSS::RX::NMCHAR}|%*)}
7
- VALID_NUMBER = %r{(?<number>#{::Sass::SCSS::RX::NUM})#{VALID_UNIT}}
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, Float
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
- return ::Sass::Script::Value::Number.new(matches[:number], matches[:unit])
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)
@@ -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' => ::Sass::Script::Value::Number,
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sassy_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Davis