sassy_hash 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- M2IyYzhhNGVmZDdjOTYxZTRkYWNjYzczNjg0N2U2YTg2OTQ5NDEyZA==
5
- data.tar.gz: !binary |-
6
- NWYwYzA4NzdkZjliMzdhN2JjMjNiNTljNzQyODk1NzM2ZTVkODUyMQ==
2
+ SHA1:
3
+ metadata.gz: 13bb9d51c0ace3269e1bf46373158e9844dd8539
4
+ data.tar.gz: a437a190e0fecda328a42441cecef347a53e4ac9
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NjA5ODM3NjFmODlmMzQ4OWQ2YjE2MWY1MjYwODBmN2Q5MWJmMmE2MGRiMzZm
10
- Mjk4YTExNTc2YTg5NTkxZTlhZWM3MmE5ZTM1ZjE5NmJmMzQ2MDcwZDg5NGY0
11
- MTllZmE5NmI0ZjdhZWNkODg2NDA4ODI5MzVkZmM1MDcyNGRkZmM=
12
- data.tar.gz: !binary |-
13
- M2RlODc3ZjMwMmVkYTJhNDg3OTgxN2IwZTA1MzlkZTFlNWIyNjVlNjVmODY4
14
- NTliOWMyZDE4ZWI1YzUyMzhjZmEzMmUwYTMxMmFkMWJhNmEzMTlhM2E2ZWZh
15
- ZTQwNWM0ZmRjZjNhZjg1YmQ4Mzg0NDBlNjA2YjQxNDhlODg3ZDg=
6
+ metadata.gz: 0825378dd64e2885f48b7c41ebb6be89204f2fafcc7b83b17375f8b3790a834760dea6e42c4924c26994805d22bf7093bad1f68de78070491afd2eb363e2fce3
7
+ data.tar.gz: 6043501fe1e13cd1b4ce5f3e23261812cbed1205cc8055702622fb4f379b08ef455dafb0db1d10cf1251f5a106e365f2160b5048f51c483347959e3b655cd89d
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ * Full color parsing support
data/lib/sassy_hash.rb CHANGED
@@ -1,10 +1,15 @@
1
+
1
2
  require 'sass'
2
3
  require 'sass/scss/rx'
3
4
  class SassyHashException < Exception; end
4
5
  class SassyHash < Hash
5
- VERSION = "0.0.6"
6
- VALID_UNIT = %r{(?<unit>#{::Sass::SCSS::RX::NMSTART}#{::Sass::SCSS::RX::NMCHAR}|%*)}
7
- VALID_NUMBER = %r{((?<float>^[0-9]*\.[0-9]+)|(?<int>^[0-9]+))#{VALID_UNIT}}
6
+ VERSION = "0.1.0"
7
+ VALID_UNIT = %r{(?<unit>#{::Sass::SCSS::RX::NMSTART}#{::Sass::SCSS::RX::NMCHAR}|%*)}
8
+ FLOAT_OR_INT_MATCH = %r{(?<float>^[0-9]*\.[0-9]+)|(?<int>^[0-9]+)}
9
+ FLOAT_OR_INT = %r{(^[0-9]*\.[0-9]+|^[0-9]+)}
10
+ VALID_NUMBER = %r{(#{FLOAT_OR_INT_MATCH})#{VALID_UNIT}}
11
+ RGB_REGEX = %r{(rgba?\((?<colors>([^)]*))\))}
12
+
8
13
  def self.[](hash_values)
9
14
  super(hash_values).tap do |hash|
10
15
  hash.sassify!
@@ -31,6 +36,25 @@ class SassyHash < Hash
31
36
  super(key, value)
32
37
  end
33
38
 
39
+ def self.parse_color(value)
40
+ sass_colors = Sass::Script::Value::Color::COLOR_NAMES
41
+ if sass_colors.has_key?(value)
42
+ return ::Sass::Script::Value::Color.new sass_colors[value]
43
+ end
44
+ # hex color
45
+ if value =~ Sass::SCSS::RX::HEXCOLOR
46
+ return ::Sass::Script::Value::Color.from_hex(value)
47
+ end
48
+
49
+ if matches = value.match(RGB_REGEX)
50
+ colors = matches[:colors].split(',')
51
+ colors.map!(&:to_f)
52
+ return ::Sass::Script::Value::Color.new colors
53
+ end
54
+
55
+ nil
56
+ end
57
+
34
58
  def self.sass_convert_value(value)
35
59
  case value
36
60
  when Integer, Fixnum
@@ -40,10 +64,8 @@ class SassyHash < Hash
40
64
  when Symbol
41
65
  return ::Sass::Script::Value::String.new(value.to_s)
42
66
  when String
43
- # hex color
44
- if value =~ ::Sass::SCSS::RX::HEXCOLOR
45
- return ::Sass::Script::Value::Color.from_hex(value)
46
- end
67
+ color = self.parse_color(value)
68
+ return color unless color.nil?
47
69
  #number
48
70
  if matches = value.match(VALID_NUMBER)
49
71
  num = if matches[:float]
@@ -85,10 +85,35 @@ describe SassyHash do
85
85
  num.should eq(120.5)
86
86
  end
87
87
 
88
+
89
+ it "should correctly parse an rbg value" do
90
+ string = "rgb(255, 255, 255)"
91
+ color = SassyHash.sass_convert_value(string)
92
+ color.send(:hex_str).should eq('#ffffff')
93
+ end
94
+
95
+ it "should correctly parse an rbga value" do
96
+ string = "rgb(255, 255, 255, 1.0)"
97
+ color = SassyHash.sass_convert_value(string)
98
+ color.send(:hex_str).should eq('#ffffff')
99
+ end
100
+
101
+ it "should parse raw color names" do
102
+ {"green" => '#008000', "blue" => '#0000ff', "orange" => '#ffa500', "fuchsia" => '#ff00ff'}.each do |color, hex|
103
+ color = SassyHash.sass_convert_value(color)
104
+ color.send(:hex_str).should eq(hex)
105
+ end
106
+ end
107
+
88
108
  {
89
109
  "#fff" => ::Sass::Script::Value::Color,
90
110
  "#111" => ::Sass::Script::Value::Color,
91
111
  "#eeeeee" => ::Sass::Script::Value::Color,
112
+ "rgb(1.0, 1.0, 1.0)" => ::Sass::Script::Value::Color,
113
+ "rgba(1.0, 51, 1.0, 0.5)" => ::Sass::Script::Value::Color,
114
+ "green" => ::Sass::Script::Value::Color,
115
+ "yellow" => ::Sass::Script::Value::Color,
116
+ "aqua" => ::Sass::Script::Value::Color,
92
117
  'foo' => ::Sass::Script::Value::String,
93
118
  0 => ::Sass::Script::Value::Number,
94
119
  1.0 => ::Sass::Script::Value::Number,
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sassy_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-19 00:00:00.000000000 Z
11
+ date: 2014-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sass
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 3.3rc2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.3rc2
55
55
  description: SassyHash is a Hash extension that is directly injectable into a Sass::Script::Value::Map
@@ -59,8 +59,9 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
63
- - .rspec
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - CHANGELOG.md
64
65
  - Gemfile
65
66
  - LICENSE.txt
66
67
  - README.md
@@ -80,17 +81,17 @@ require_paths:
80
81
  - lib
81
82
  required_ruby_version: !ruby/object:Gem::Requirement
82
83
  requirements:
83
- - - ! '>='
84
+ - - ">="
84
85
  - !ruby/object:Gem::Version
85
86
  version: '0'
86
87
  required_rubygems_version: !ruby/object:Gem::Requirement
87
88
  requirements:
88
- - - ! '>='
89
+ - - ">="
89
90
  - !ruby/object:Gem::Version
90
91
  version: '0'
91
92
  requirements: []
92
93
  rubyforge_project:
93
- rubygems_version: 2.1.11
94
+ rubygems_version: 2.2.2
94
95
  signing_key:
95
96
  specification_version: 4
96
97
  summary: Hash converter for Sass::Script::Value::Map