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 +4 -4
- data/lib/SassyExport.rb +60 -49
- data/stylesheets/_SassyExport.scss +14 -12
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f067915d223ad465949b3b3f6286870b5642714e
|
4
|
+
data.tar.gz: e6922fa2950bc503720ea6da71bc9fb43cf46e81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73dd506a1e6db2e83430e7075ae8438380fa5a6fec6f77b6b39c80e3204eb80f85659820be63c55b1d8ae7efcf1a27411e540f9e1305ead3698e81cc8b3b9879
|
7
|
+
data.tar.gz: 40b0f8938e06432b24322039c0a3d8640a6b604f88c419e043acd2d44c7e569c807ad3f430cb9623a8fbf2a2c9ed852d1b3b5daaed794b9dabe2684a6a6bda98
|
data/lib/SassyExport.rb
CHANGED
@@ -11,55 +11,63 @@ else
|
|
11
11
|
end
|
12
12
|
|
13
13
|
module SassyExport
|
14
|
-
|
15
|
-
DATE = "2014-08-18"
|
14
|
+
VERSION = "1.4.0"
|
16
15
|
end
|
17
16
|
|
18
|
-
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# @param
|
22
|
-
#
|
23
|
-
# @param
|
24
|
-
#
|
25
|
-
# @
|
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
|
-
#
|
42
|
+
# Unquote strings
|
36
43
|
def u(s)
|
37
44
|
unquote(s)
|
38
45
|
end
|
39
46
|
|
40
|
-
|
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
|
-
#
|
55
|
+
# If map, recurse to hash
|
47
56
|
l = recurs_to_h(l)
|
48
57
|
when Sass::Script::Value::List
|
49
|
-
#
|
58
|
+
# If list, recurse to array
|
50
59
|
l = recurs_to_a(l)
|
51
60
|
when Sass::Script::Value::Bool
|
52
|
-
#
|
61
|
+
# Convert to bool
|
53
62
|
l = l.to_bool
|
54
63
|
when Sass::Script::Value::Number
|
55
|
-
#
|
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
|
-
#
|
67
|
+
# Get hex/rgba value for color
|
60
68
|
l = l.inspect
|
61
69
|
else
|
62
|
-
#
|
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
|
-
|
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
|
-
#
|
88
|
+
# If map, recurse to hash
|
79
89
|
h[u(k)] = recurs_to_h(v)
|
80
90
|
when Sass::Script::Value::List
|
81
|
-
#
|
91
|
+
# If list, recurse to array
|
82
92
|
h[u(k)] = recurs_to_a(v)
|
83
93
|
when Sass::Script::Value::Bool
|
84
|
-
#
|
94
|
+
# Convert to bool
|
85
95
|
h[u(k)] = v.to_bool
|
86
96
|
when Sass::Script::Value::Number
|
87
|
-
#
|
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
|
-
#
|
100
|
+
# Get hex/rgba value for color
|
92
101
|
h[u(k)] = v.inspect
|
93
102
|
else
|
94
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
125
|
+
# Parse to string
|
115
126
|
path = unquote(path).to_s
|
116
127
|
|
117
|
-
#
|
118
|
-
root = Dir.pwd
|
128
|
+
# Define root path up to current working directory
|
129
|
+
root = use_env ? ENV['PWD'] : Dir.pwd
|
119
130
|
|
120
|
-
#
|
131
|
+
# Define dir path
|
121
132
|
dir_path = root
|
122
133
|
dir_path += path
|
123
134
|
|
124
|
-
#
|
135
|
+
# Get filename
|
125
136
|
filename = File.basename(dir_path, ".*")
|
126
137
|
|
127
|
-
#
|
138
|
+
# Get extension
|
128
139
|
ext = File.extname(path)
|
129
140
|
|
130
|
-
#
|
141
|
+
# Normalize windows path
|
131
142
|
dir_path = Sass::Util.pathname(dir_path)
|
132
143
|
|
133
|
-
#
|
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
|
-
#
|
152
|
+
# Get map values
|
142
153
|
map = opts(Sass::Script::Value::Map.new(map.value))
|
143
154
|
|
144
|
-
#
|
155
|
+
# Recursive convert map to hash
|
145
156
|
hash = recurs_to_h(map)
|
146
157
|
|
147
|
-
#
|
158
|
+
# Convert hash to pretty json if pretty
|
148
159
|
pretty ? json = JSON.pretty_generate(hash) : json = JSON.generate(hash)
|
149
160
|
|
150
|
-
#
|
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
|
-
#
|
164
|
+
# Define flags
|
154
165
|
flag = 'w'
|
155
166
|
flag = 'wb' if Sass::Util.windows? && options[:unix_newlines]
|
156
167
|
|
157
|
-
#
|
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
|
-
#
|
174
|
+
# Define message
|
164
175
|
debug_msg = "#{ext == '.json' ? 'JSON' : 'JavaScript'} was successfully exported to #{dir_path}"
|
165
176
|
|
166
|
-
#
|
177
|
+
# Print path string if debug
|
167
178
|
puts debug_msg if debug
|
168
179
|
|
169
|
-
#
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@
|
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.
|
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-
|
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.
|
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:
|