SassyExport 1.3.5 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2b1768c99d5f417dd02b0e855f9aa2fa20a083a
4
- data.tar.gz: 47be6265be40ffe56e78262372485168ea713f2f
3
+ metadata.gz: f067915d223ad465949b3b3f6286870b5642714e
4
+ data.tar.gz: e6922fa2950bc503720ea6da71bc9fb43cf46e81
5
5
  SHA512:
6
- metadata.gz: 498999b9ecdbc3187f5bd626e969b21cb91ad44d928b0e4e91415475b882abe39e9c47eebcda6bc7b085fe8da7dfb1bb9565f57d671b386db8114628bf94b583
7
- data.tar.gz: f4c5781bb456c9e8ec7c02d9c29a4334caf616d59afe477fc91d5a43f8f621c0fbf277e7cb7392a9d82fdab185f7aaf301405eae9cf06b89090d71d1dcde2fbc
6
+ metadata.gz: 73dd506a1e6db2e83430e7075ae8438380fa5a6fec6f77b6b39c80e3204eb80f85659820be63c55b1d8ae7efcf1a27411e540f9e1305ead3698e81cc8b3b9879
7
+ data.tar.gz: 40b0f8938e06432b24322039c0a3d8640a6b604f88c419e043acd2d44c7e569c807ad3f430cb9623a8fbf2a2c9ed852d1b3b5daaed794b9dabe2684a6a6bda98
@@ -11,55 +11,63 @@ else
11
11
  end
12
12
 
13
13
  module SassyExport
14
- VERSION = "1.3.5"
15
- DATE = "2014-08-18"
14
+ VERSION = "1.4.0"
16
15
  end
17
16
 
18
- # SassyExport : convert passed map to json and write to path/to/filename.json
19
- # ----------------------------------------------------------------------------------------------------
20
- # @param path [string] : directory path and filename
21
- # @param map [map] : map to convert to json
22
- # @param pretty [bool] : pretty print json
23
- # @param debug [bool] : print debug string with path
24
- # ----------------------------------------------------------------------------------------------------
25
- # @return string | write json to path
26
-
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
+ ###
27
34
  module Sass::Script::Functions
28
- def SassyExport(path, map, pretty, debug)
35
+ def SassyExport(path, map, pretty, debug, use_env)
29
36
 
30
37
  def opts(value)
31
38
  value.options = options
32
39
  value
33
40
  end
34
41
 
35
- # unquote strings
42
+ # Unquote strings
36
43
  def u(s)
37
44
  unquote(s)
38
45
  end
39
46
 
40
- # recursive parse to array
47
+ ###
48
+ # Recursive parse to array
49
+ ###
41
50
  def recurs_to_a(array)
42
51
  if array.is_a?(Array)
43
52
  array.map do | l |
44
53
  case l
45
54
  when Sass::Script::Value::Map
46
- # if map, recurse to hash
55
+ # If map, recurse to hash
47
56
  l = recurs_to_h(l)
48
57
  when Sass::Script::Value::List
49
- # if list, recurse to array
58
+ # If list, recurse to array
50
59
  l = recurs_to_a(l)
51
60
  when Sass::Script::Value::Bool
52
- # convert to bool
61
+ # Convert to bool
53
62
  l = l.to_bool
54
63
  when Sass::Script::Value::Number
55
- # if it's a unitless number, convert to ruby val
56
- # else convert to string
64
+ # If it's a unitless number, convert to ruby val, else convert to string
57
65
  l.unitless? ? l = l.value : l = u(l)
58
66
  when Sass::Script::Value::Color
59
- # get hex/rgba value for color
67
+ # Get hex/rgba value for color
60
68
  l = l.inspect
61
69
  else
62
- # convert to string
70
+ # Convert to string
63
71
  l = u(l)
64
72
  end
65
73
  l
@@ -69,29 +77,30 @@ module Sass::Script::Functions
69
77
  end
70
78
  end
71
79
 
72
- # recursive parse to hash
80
+ ###
81
+ # Recursive parse to hash
82
+ ###
73
83
  def recurs_to_h(hash)
74
84
  if hash.is_a?(Hash)
75
85
  hash.inject({}) do | h, (k, v) |
76
86
  case v
77
87
  when Sass::Script::Value::Map
78
- # if map, recurse to hash
88
+ # If map, recurse to hash
79
89
  h[u(k)] = recurs_to_h(v)
80
90
  when Sass::Script::Value::List
81
- # if list, recurse to array
91
+ # If list, recurse to array
82
92
  h[u(k)] = recurs_to_a(v)
83
93
  when Sass::Script::Value::Bool
84
- # convert to bool
94
+ # Convert to bool
85
95
  h[u(k)] = v.to_bool
86
96
  when Sass::Script::Value::Number
87
- # if it's a unitless number, convert to ruby val
88
- # else convert to string
97
+ # If it's a unitless number, convert to ruby val, else convert to string
89
98
  v.unitless? ? h[u(k)] = v.value : h[u(k)] = u(v)
90
99
  when Sass::Script::Value::Color
91
- # get hex/rgba value for color
100
+ # Get hex/rgba value for color
92
101
  h[u(k)] = v.inspect
93
102
  else
94
- # convert to string
103
+ # Convert to string
95
104
  h[u(k)] = u(v)
96
105
  end
97
106
  h
@@ -101,36 +110,38 @@ module Sass::Script::Functions
101
110
  end
102
111
  end
103
112
 
104
- # assert types
113
+ # Assert types
105
114
  assert_type path, :String, :path
106
115
  assert_type map, :Map, :map
107
116
  assert_type pretty, :Bool, :pretty
108
117
  assert_type debug, :Bool, :debug
118
+ assert_type use_env, :Bool, :use_env
109
119
 
110
- # parse to bool
120
+ # Parse to bool
111
121
  pretty = pretty.to_bool
112
122
  debug = debug.to_bool
123
+ use_env = use_env.to_bool
113
124
 
114
- # parse to string
125
+ # Parse to string
115
126
  path = unquote(path).to_s
116
127
 
117
- # define root path up to current working directory
118
- root = Dir.pwd
128
+ # Define root path up to current working directory
129
+ root = use_env ? ENV['PWD'] : Dir.pwd
119
130
 
120
- # define dir path
131
+ # Define dir path
121
132
  dir_path = root
122
133
  dir_path += path
123
134
 
124
- # get filename
135
+ # Get filename
125
136
  filename = File.basename(dir_path, ".*")
126
137
 
127
- # get extension
138
+ # Get extension
128
139
  ext = File.extname(path)
129
140
 
130
- # normalize windows path
141
+ # Normalize windows path
131
142
  dir_path = Sass::Util.pathname(dir_path)
132
143
 
133
- # check if directory exists, if not make directory
144
+ # Check if directory exists, if not make directory
134
145
  dir = File.dirname(dir_path)
135
146
 
136
147
  unless File.exists?(dir)
@@ -138,36 +149,36 @@ module Sass::Script::Functions
138
149
  puts "Directory was not found. Created new directory: #{dir}"
139
150
  end
140
151
 
141
- # get map values
152
+ # Get map values
142
153
  map = opts(Sass::Script::Value::Map.new(map.value))
143
154
 
144
- # recursive convert map to hash
155
+ # Recursive convert map to hash
145
156
  hash = recurs_to_h(map)
146
157
 
147
- # convert hash to pretty json if pretty
158
+ # Convert hash to pretty json if pretty
148
159
  pretty ? json = JSON.pretty_generate(hash) : json = JSON.generate(hash)
149
160
 
150
- # if we're turning it straight to js put a variable name in front
161
+ # If we're turning it straight to js put a variable name in front
151
162
  json = "var " + filename + " = " + json if ext == '.js'
152
163
 
153
- # define flags
164
+ # Define flags
154
165
  flag = 'w'
155
166
  flag = 'wb' if Sass::Util.windows? && options[:unix_newlines]
156
167
 
157
- # open file [create new file if file does not exist], write string to root/path/to/filename.json
168
+ # Ppen file (create new file if file does not exist), write string to root/path/to/filename.json
158
169
  File.open("#{dir_path}", flag) do |file|
159
170
  file.set_encoding(json.encoding) unless Sass::Util.ruby1_8?
160
171
  file.print(json)
161
172
  end
162
173
 
163
- # define message
174
+ # Define message
164
175
  debug_msg = "#{ext == '.json' ? 'JSON' : 'JavaScript'} was successfully exported to #{dir_path}"
165
176
 
166
- # print path string if debug
177
+ # Print path string if debug
167
178
  puts debug_msg if debug
168
179
 
169
- # return succcess string
180
+ # Return succcess string
170
181
  opts(Sass::Script::Value::String.new(debug_msg))
171
182
  end
172
- declare :SassyExport, [:path, :map, :pretty, :debug]
183
+ declare :SassyExport, [:path, :map, :pretty, :debug, :use_env]
173
184
  end
@@ -1,18 +1,20 @@
1
- // SassyExport : convert passed map to json and write to <path>/<filename>.<ext>
2
- // ----------------------------------------------------------------------------------------------------
3
- // @param $path [string] : directory path and filename, valid extensions: [json | js]
4
- // @param $map [map] : map to convert to json
5
- // @param $pretty [bool] : pretty print json
6
- // @param $debug [bool] : print debug string with path
7
- // ----------------------------------------------------------------------------------------------------
8
- // @return $string | write to path
9
-
10
- @mixin SassyExport($path, $map, $pretty: false, $debug: false) {
1
+ ///
2
+ /// Convert passed map to json and write to <path>/<filename>.<ext>
3
+ ///
4
+ /// @param {String} $path - Directory path and filename
5
+ /// @param {map} $map - Map to convert to json
6
+ /// @param {Bool} $pretty - Pretty print json
7
+ /// @param {Bool} $debug - Print debug string with path
8
+ /// @param {Bool} $use_env - Use ENV['PWD'] for current directory instead of Dir.pwd
9
+ ///
10
+ /// @return {String} - Write file to path
11
+ ///
12
+ @mixin SassyExport($path, $map, $pretty: false, $debug: false, $use_env: false) {
11
13
  @at-root {
12
14
  @if $debug {
13
- /*! #{SassyExport($path, $map, $pretty, $debug)} */
15
+ /*! #{SassyExport($path, $map, $pretty, $debug, $use_env)} */
14
16
  } @else {
15
- %SassExport { /*! #{SassyExport($path, $map, $pretty, $debug)} */ }
17
+ %SassExport { /*! #{SassyExport($path, $map, $pretty, $debug, $use_env)} */ }
16
18
  }
17
19
  }
18
20
  }
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SassyExport
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5
4
+ version: 1.4.0
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-08-18 00:00:00.000000000 Z
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sass
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.3.0
20
20
  type: :runtime
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: 3.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.8.1
34
34
  type: :runtime
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: 1.8.1
41
41
  description: SassyExport is a lightweight Sass extension that allows you to export
@@ -46,9 +46,9 @@ executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - README.md
50
49
  - lib/SassyExport.rb
51
50
  - stylesheets/_SassyExport.scss
51
+ - README.md
52
52
  homepage: https://github.com/ezekg/SassyExport/
53
53
  licenses:
54
54
  - MIT
@@ -60,18 +60,19 @@ require_paths:
60
60
  - stylesheets
61
61
  required_ruby_version: !ruby/object:Gem::Requirement
62
62
  requirements:
63
- - - ">="
63
+ - - '>='
64
64
  - !ruby/object:Gem::Version
65
65
  version: '0'
66
66
  required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ">="
68
+ - - '>='
69
69
  - !ruby/object:Gem::Version
70
70
  version: 1.3.6
71
71
  requirements: []
72
72
  rubyforge_project: SassyExport
73
- rubygems_version: 2.2.2
73
+ rubygems_version: 2.0.14
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: SassyExport allows you to export a Sass map into an external JSON file.
77
77
  test_files: []
78
+ has_rdoc: