SassyExport 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f067915d223ad465949b3b3f6286870b5642714e
4
- data.tar.gz: e6922fa2950bc503720ea6da71bc9fb43cf46e81
3
+ metadata.gz: 67a9b5c139298c843d294bbb111d69e54ed5cd0e
4
+ data.tar.gz: 6ac620d176d1deb057b93c41c2562fffa0952cc5
5
5
  SHA512:
6
- metadata.gz: 73dd506a1e6db2e83430e7075ae8438380fa5a6fec6f77b6b39c80e3204eb80f85659820be63c55b1d8ae7efcf1a27411e540f9e1305ead3698e81cc8b3b9879
7
- data.tar.gz: 40b0f8938e06432b24322039c0a3d8640a6b604f88c419e043acd2d44c7e569c807ad3f430cb9623a8fbf2a2c9ed852d1b3b5daaed794b9dabe2684a6a6bda98
6
+ metadata.gz: 28aa3f1330f63fc0b713babca147d9b04002c195fda43af5a6b203d2611f961c68b7540c5619ae0c64237b1785b4399a6d18b7b41c7439bb4c2b3dd58f2b4ddc
7
+ data.tar.gz: 0817054a3678c31ad9f016a79c991b3d7673399a4392d04b214bfc8d525da9689e5085268231625c76e18c4f4e2639d03cf958aef1b3535ddf44a8a03fe048ec
data/README.md CHANGED
@@ -23,7 +23,7 @@ root
23
23
 
24
24
  Sass,
25
25
  ```scss
26
- // ./sass/style.scss
26
+ // sass/style.scss
27
27
 
28
28
  @import "SassyExport";
29
29
 
@@ -31,16 +31,18 @@ $map: (
31
31
  hello: world,
32
32
  );
33
33
 
34
- // SassyExport : convert passed map to json and write to path/to/filename.json
35
- // ----------------------------------------------------------------------------------------------------
36
- // @param $path [string] : directory path and filename, valid extensions: [json | js]
37
- // @param $map [map] : map to convert to json
38
- // @param $pretty [bool] : pretty print json
39
- // @param $debug [bool] : print debug string with path
40
- // ----------------------------------------------------------------------------------------------------
41
- // @return $string | write json to path
42
-
43
- @include SassyExport("/json/hello.json", $map, true);
34
+ ///
35
+ /// Convert passed map to json and write to <path>/<filename>.<ext>
36
+ ///
37
+ /// @param {String} $path - Directory path and filename
38
+ /// @param {map} $map - Map to convert to json
39
+ /// @param {Bool} $pretty - Pretty print json
40
+ /// @param {Bool} $debug - Print debug string with path
41
+ /// @param {Bool} $use_env - Use ENV['PWD'] for current directory instead of Dir.pwd
42
+ ///
43
+ /// @return {String} - Write file to path
44
+ ///
45
+ @include SassyExport("/json/hello.json", $map);
44
46
  ```
45
47
 
46
48
  #### Result
@@ -1,37 +1,32 @@
1
- require 'sass'
1
+ require "sass"
2
2
  require "json"
3
3
 
4
- base_directory = File.expand_path(File.join(File.dirname(__FILE__), '..'))
5
- sassyexport_stylesheets_path = File.join(base_directory, 'stylesheets')
4
+ base_directory = File.expand_path(File.join(File.dirname(__FILE__), ".."))
5
+ sassyexport_stylesheets_path = File.join(base_directory, "stylesheets")
6
6
 
7
7
  if (defined? Compass)
8
- Compass::Frameworks.register('SassyExport', :path => base_directory)
8
+ Compass::Frameworks.register("SassyExport", :path => base_directory)
9
9
  else
10
10
  ENV["SASS_PATH"] = [ENV["SASS_PATH"], sassyexport_stylesheets_path].compact.join(File::PATH_SEPARATOR)
11
11
  end
12
12
 
13
13
  module SassyExport
14
- VERSION = "1.4.0"
14
+ VERSION = "1.4.1"
15
15
  end
16
16
 
17
- ###
18
- # Convert passed map to json and write to <path>/<filename>.<ext>
19
- #
20
- # @param {String} path
21
- # Directory path and filename
22
- # @param {map} map
23
- # Map to convert to json
24
- # @param {Bool} pretty
25
- # Pretty print json
26
- # @param {Bool} debug
27
- # Print debug string with path
28
- # @param {Bool} use_env
29
- # Use ENV['PWD'] for current directory instead of Dir.pwd
30
- #
31
- # @return {String}
32
- # Write file to path
33
- ###
34
17
  module Sass::Script::Functions
18
+
19
+ #
20
+ # Convert passed map to json and write to <path>/<filename>.<ext>
21
+ #
22
+ # @param {String} path - Directory path and filename
23
+ # @param {map} map - Map to convert to json
24
+ # @param {Bool} pretty - Pretty print json
25
+ # @param {Bool} debug - Print debug string with path
26
+ # @param {Bool} use_env - Use ENV['PWD'] for current directory instead of Dir.pwd
27
+ #
28
+ # @return {String} - Write file to path
29
+ #
35
30
  def SassyExport(path, map, pretty, debug, use_env)
36
31
 
37
32
  def opts(value)
@@ -39,17 +34,33 @@ module Sass::Script::Functions
39
34
  value
40
35
  end
41
36
 
37
+ #
42
38
  # Unquote strings
43
- def u(s)
44
- unquote(s)
39
+ #
40
+ # @param {*} val
41
+ #
42
+ # @return Unquoted string, if String was passed. Else if will
43
+ # just return the passed value.
44
+ #
45
+ def strip_quotes(value)
46
+ if value.is_a?(String) || value.is_a?(Sass::Script::Value::String)
47
+ unquote(value)
48
+ else
49
+ value
50
+ end
45
51
  end
46
52
 
47
- ###
53
+ #
48
54
  # Recursive parse to array
49
- ###
55
+ #
56
+ # @param {Array} array - Array containing SassScript values
57
+ #
58
+ # @return {Array} - Array containing parsed SassScript->Ruby values
59
+ #
50
60
  def recurs_to_a(array)
51
61
  if array.is_a?(Array)
52
- array.map do | l |
62
+ array.map do |l|
63
+
53
64
  case l
54
65
  when Sass::Script::Value::Map
55
66
  # If map, recurse to hash
@@ -62,14 +73,15 @@ module Sass::Script::Functions
62
73
  l = l.to_bool
63
74
  when Sass::Script::Value::Number
64
75
  # If it's a unitless number, convert to ruby val, else convert to string
65
- l.unitless? ? l = l.value : l = u(l)
76
+ l = l.unitless? ? l.value : strip_quotes(l)
66
77
  when Sass::Script::Value::Color
67
78
  # Get hex/rgba value for color
68
79
  l = l.inspect
69
80
  else
70
81
  # Convert to string
71
- l = u(l)
82
+ l = strip_quotes(l)
72
83
  end
84
+
73
85
  l
74
86
  end
75
87
  else
@@ -77,32 +89,38 @@ module Sass::Script::Functions
77
89
  end
78
90
  end
79
91
 
80
- ###
92
+ #
81
93
  # Recursive parse to hash
82
- ###
94
+ #
95
+ # @param {Hash} hash - Hash containing SassScript values
96
+ #
97
+ # @return {Hash} - Hash containing parsed SassScript->Ruby values
98
+ #
83
99
  def recurs_to_h(hash)
84
100
  if hash.is_a?(Hash)
85
- hash.inject({}) do | h, (k, v) |
101
+ hash.inject({}) do |h, (k, v)|
102
+
86
103
  case v
87
104
  when Sass::Script::Value::Map
88
105
  # If map, recurse to hash
89
- h[u(k)] = recurs_to_h(v)
106
+ h[strip_quotes(k)] = recurs_to_h(v)
90
107
  when Sass::Script::Value::List
91
108
  # If list, recurse to array
92
- h[u(k)] = recurs_to_a(v)
109
+ h[strip_quotes(k)] = recurs_to_a(v)
93
110
  when Sass::Script::Value::Bool
94
111
  # Convert to bool
95
- h[u(k)] = v.to_bool
112
+ h[strip_quotes(k)] = v.to_bool
96
113
  when Sass::Script::Value::Number
97
114
  # If it's a unitless number, convert to ruby val, else convert to string
98
- v.unitless? ? h[u(k)] = v.value : h[u(k)] = u(v)
115
+ h[strip_quotes(k)] = v.unitless? ? v.value : strip_quotes(v)
99
116
  when Sass::Script::Value::Color
100
117
  # Get hex/rgba value for color
101
- h[u(k)] = v.inspect
118
+ h[strip_quotes(k)] = v.inspect
102
119
  else
103
120
  # Convert to string
104
- h[u(k)] = u(v)
121
+ h[strip_quotes(k)] = strip_quotes(v)
105
122
  end
123
+
106
124
  h
107
125
  end
108
126
  else
@@ -126,7 +144,7 @@ module Sass::Script::Functions
126
144
  path = unquote(path).to_s
127
145
 
128
146
  # Define root path up to current working directory
129
- root = use_env ? ENV['PWD'] : Dir.pwd
147
+ root = use_env ? ENV["PWD"] : Dir.pwd
130
148
 
131
149
  # Define dir path
132
150
  dir_path = root
@@ -162,8 +180,8 @@ module Sass::Script::Functions
162
180
  json = "var " + filename + " = " + json if ext == '.js'
163
181
 
164
182
  # Define flags
165
- flag = 'w'
166
- flag = 'wb' if Sass::Util.windows? && options[:unix_newlines]
183
+ flag = "w"
184
+ flag = "wb" if Sass::Util.windows? && options[:unix_newlines]
167
185
 
168
186
  # Ppen file (create new file if file does not exist), write string to root/path/to/filename.json
169
187
  File.open("#{dir_path}", flag) do |file|
@@ -172,7 +190,8 @@ module Sass::Script::Functions
172
190
  end
173
191
 
174
192
  # Define message
175
- debug_msg = "#{ext == '.json' ? 'JSON' : 'JavaScript'} was successfully exported to #{dir_path}"
193
+ # debug_msg = "#{ext == '.json' ? 'JSON' : 'JavaScript'} was successfully exported to #{dir_path}"
194
+ debug_msg = "\e[0;32m export\e[0m #{ext == '.json' ? 'JSON' : 'JavaScript'} to #{dir_path}"
176
195
 
177
196
  # Print path string if debug
178
197
  puts debug_msg if debug
@@ -14,7 +14,7 @@
14
14
  @if $debug {
15
15
  /*! #{SassyExport($path, $map, $pretty, $debug, $use_env)} */
16
16
  } @else {
17
- %SassExport { /*! #{SassyExport($path, $map, $pretty, $debug, $use_env)} */ }
17
+ %SassyExport { /*! #{SassyExport($path, $map, $pretty, $debug, $use_env)} */ }
18
18
  }
19
19
  }
20
20
  }
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.4.0
4
+ version: 1.4.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-11-20 00:00:00.000000000 Z
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sass