SassyExport 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/lib/SassyExport.rb +29 -11
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b5f61b639e7e5a3b68e219446d3a4736ec08d79
4
- data.tar.gz: ce04ad399009cce61d626752c5be8bba12f1246f
3
+ metadata.gz: 508de77d8e8dfcc10b363bd5fefbd93e08af85bc
4
+ data.tar.gz: 5d5e4c8343b0613438ade8808f0ecc00d667bc9b
5
5
  SHA512:
6
- metadata.gz: 92af948797a97578ce2fad65438508ef0087304434e67d1b5b320304b88989146afbf0a544f03eaf849396cdcf84fa3f8210247874c48060e2bd9474c270fdf5
7
- data.tar.gz: d3b6da6afb1d073a89d7762e99a622eed73347d57d249ec3ba6496b017fb5adc2fa3f906cd1586499eb1e73ac741bee73eee9d809bd866049692e04575d801df
6
+ metadata.gz: 74eae49f688f5dafd07e910685eb4bffcfa3dd06649f0ca8be1554733dfbced8c04601abf431e4cc16412248082d25a62cf836e26eae50d21a8bd401ce039b5b
7
+ data.tar.gz: 6822ec43ab3c06c45728aa13fddeb8a5fd49038cb0ecfb709ffa05ae2d494617c421402c7216bd80807061644d7bb2afb62cd976ecbc406c1f2bc300d047c3aa
data/README.md CHANGED
@@ -53,7 +53,9 @@ New JSON file is created at `./json/hello.json`. As you can see, `$path` is rela
53
53
 
54
54
  #### Breakdown
55
55
 
56
- The `SassyExport()` mixin takes a directory/filename.json `$path`, and a Sass `$map` as arguments. It converts the `$map` into a JSON map through Ruby, and then creates a new file (or updates an existing file), and writes the contents of the json string to it. I'm no Ruby expert, so if you belive that you could improve the small amount of code here, feel free to.
56
+ The `SassyExport()` mixin takes a directory/filename.json `$path`, and a Sass `$map` as arguments. There is also an optional argument `$pretty` which defaults to `false`, but will print pretty JSON (nicely indented) if set to `true`.
57
+
58
+ It converts the `$map` into a JSON map through Ruby, and then creates a new file (or updates an existing file), and writes the contents of the JSON string to it. I'm no Ruby expert, so if you belive that you could improve the small amount of code here, feel free to.
57
59
 
58
60
  Enjoy.
59
61
 
@@ -7,8 +7,8 @@ Compass::Frameworks.register('SassyExport', :path => extension_path)
7
7
  # Version is a number. If a version contains alphas, it will be created as a prerelease version
8
8
  # Date is in the form of YYYY-MM-DD
9
9
  module SassyExport
10
- VERSION = "1.1.0"
11
- DATE = "2014-06-04"
10
+ VERSION = "1.1.1"
11
+ DATE = "2014-06-05"
12
12
  end
13
13
 
14
14
  # SassyExport : convert passed map to json and write to path/to/filename.json
@@ -27,22 +27,38 @@ module Sass::Script::Functions
27
27
  value
28
28
  end
29
29
 
30
+ # unquote strings
31
+ def u(s)
32
+ unquote(s)
33
+ end
34
+
30
35
  # recursive parse to array
31
36
  def recurs_to_a(array)
32
37
  if array.is_a?(Array)
33
38
  array.map do | l |
34
39
  if l.is_a?(Sass::Script::Value::Map)
40
+ # if map, recurse to hash
35
41
  l = recurs_to_h(l)
36
42
  elsif l.is_a?(Sass::Script::Value::List)
43
+ # if list, recurse to array
37
44
  l = recurs_to_a(l)
38
45
  elsif l.is_a?(Sass::Script::Value::Bool)
46
+ # convert to bool
39
47
  l = l.to_bool
40
48
  elsif l.is_a?(Sass::Script::Value::Number)
49
+ # if it's a unitless number, convert to ruby val
41
50
  if l.unitless?
42
- l = l.to_i
51
+ l = l.value
52
+ # else convert to string
43
53
  else
44
- l = l.to_s
54
+ l = u(l)
45
55
  end
56
+ elsif l.is_a?(Sass::Script::Value::Color)
57
+ # get hex/rgba value for color
58
+ l = l.inspect
59
+ else
60
+ # convert to string
61
+ l = u(l)
46
62
  end
47
63
  l
48
64
  end
@@ -56,19 +72,21 @@ module Sass::Script::Functions
56
72
  if hash.is_a?(Hash)
57
73
  hash.inject({}) do | h, (k, v) |
58
74
  if v.is_a?(Sass::Script::Value::Map)
59
- h[k] = recurs_to_h(v)
75
+ h[u(k)] = recurs_to_h(v)
60
76
  elsif v.is_a?(Sass::Script::Value::List)
61
- h[k] = recurs_to_a(v)
77
+ h[u(k)] = recurs_to_a(v)
62
78
  elsif v.is_a?(Sass::Script::Value::Bool)
63
- h[k] = v.to_bool
79
+ h[u(k)] = v.to_bool
64
80
  elsif v.is_a?(Sass::Script::Value::Number)
65
81
  if v.unitless?
66
- h[k] = v.to_i
82
+ h[u(k)] = v.value
67
83
  else
68
- h[k] = v.to_s
84
+ h[u(k)] = u(v)
69
85
  end
86
+ elsif v.is_a?(Sass::Script::Value::Color)
87
+ h[u(k)] = v.inspect
70
88
  else
71
- h[k] = v.to_s
89
+ h[u(k)] = u(v)
72
90
  end
73
91
  h
74
92
  end
@@ -107,7 +125,7 @@ module Sass::Script::Functions
107
125
  # open file [create new file if file does not exist], write string to root/path/to/filename.json
108
126
  File.open("#{dir_path}", "w") { |f| f.write(json) }
109
127
 
110
- # return a null val
128
+ # return succcess string
111
129
  return opts(Sass::Script::Value::String.new('JSON was successfully exported with love by SassyExport'))
112
130
  end
113
131
  declare :SassyExport, [:path, :map, :pretty]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SassyExport
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezekiel Gabrielse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-04 00:00:00.000000000 Z
11
+ date: 2014-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json