SassyExport 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/SassyExport.rb +33 -8
- data/stylesheets/SassyExport.scss +2 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 209b92c58f8a66df4c8200ab402b9d3b7269cca3
|
4
|
+
data.tar.gz: 41915122116682b4a85deff0d33bf8f35aa1acf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9cb0a58d571f571afb7a7c47c43de9fb4cee2ee9d85ba6f5ff8b6860c6ddf8aeafa30e1ad2f12a58fc42fd36c0c85383b3d86b96c1450718dce99c4c249a94a
|
7
|
+
data.tar.gz: 5cd16df1d381401af1494a59279e614c8aaf4eddb52b57b0a0a633218e837131b48b04d3f1a551dd551dd24c199154d30a0d7e504b25e629cfb11c21dcdfddda
|
data/README.md
CHANGED
@@ -33,7 +33,7 @@ $map: (
|
|
33
33
|
|
34
34
|
// SassyExport : convert passed map to json and write to path/to/filename.json
|
35
35
|
// ----------------------------------------------------------------------------------------------------
|
36
|
-
// @param $path [string] : directory path and filename
|
36
|
+
// @param $path [string] : directory path and filename, valid extensions: [json | js]
|
37
37
|
// @param $map [map] : map to convert to json
|
38
38
|
// @param $pretty [bool] : pretty print json
|
39
39
|
// @param $debug [bool] : print debug string with path
|
@@ -54,9 +54,11 @@ New JSON file is created at `./json/hello.json`. As you can see, `$path` is rela
|
|
54
54
|
|
55
55
|
#### Breakdown
|
56
56
|
|
57
|
-
The `SassyExport()` mixin takes a directory
|
57
|
+
The `SassyExport()` mixin takes a <directory>/<filename>.<ext> `$path` and a Sass `$map` as arguments. You can export straight to a Javascript object by using the extension `.js` instead of `.json`.
|
58
|
+
There are also optional arguments: `$pretty` which defaults to `false`, but will print pretty JSON (nicely indented) if set to `true`; and `$debug` which will print debug information if set to `true`.
|
58
59
|
|
59
|
-
It converts the `$map` into a JSON map through Ruby,
|
60
|
+
It converts the `$map` into either a JSON map or Javascript object through Ruby, then creates a new directory/file (or updates an existing directory/file), and writes the contents of the JSON string to it.
|
61
|
+
Contributions are welcome. If you believe that you could improve the small amount of code here, feel free to.
|
60
62
|
|
61
63
|
Enjoy.
|
62
64
|
|
data/lib/SassyExport.rb
CHANGED
@@ -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.
|
11
|
-
DATE = "2014-
|
10
|
+
VERSION = "1.3.0"
|
11
|
+
DATE = "2014-07-24"
|
12
12
|
end
|
13
13
|
|
14
14
|
# SassyExport : convert passed map to json and write to path/to/filename.json
|
@@ -106,16 +106,33 @@ module Sass::Script::Functions
|
|
106
106
|
pretty = pretty.to_bool
|
107
107
|
debug = debug.to_bool
|
108
108
|
|
109
|
+
# parse to string
|
110
|
+
path = unquote(path).to_s
|
111
|
+
|
109
112
|
# define root path up to current working directory
|
110
113
|
root = Dir.pwd
|
111
114
|
|
112
115
|
# define dir path
|
113
116
|
dir_path = root
|
114
|
-
dir_path +=
|
117
|
+
dir_path += path
|
118
|
+
|
119
|
+
# get filename
|
120
|
+
filename = File.basename(dir_path, ".*")
|
121
|
+
|
122
|
+
# get extension
|
123
|
+
ext = File.extname(path)
|
115
124
|
|
116
125
|
# normalize windows path
|
117
126
|
dir_path = Sass::Util.pathname(dir_path)
|
118
127
|
|
128
|
+
# check if directory exists, if not make directory
|
129
|
+
dir = File.dirname(dir_path)
|
130
|
+
|
131
|
+
unless File.exists?(dir)
|
132
|
+
FileUtils.mkdir_p(dir)
|
133
|
+
puts "Directory was not found. Created new directory: #{dir}"
|
134
|
+
end
|
135
|
+
|
119
136
|
# get map values
|
120
137
|
map = opts(Sass::Script::Value::Map.new(map.value))
|
121
138
|
|
@@ -125,16 +142,24 @@ module Sass::Script::Functions
|
|
125
142
|
# convert hash to pretty json if pretty
|
126
143
|
pretty ? json = JSON.pretty_generate(hash) : json = JSON.generate(hash)
|
127
144
|
|
145
|
+
# if we're turning it straight to js put a variable name in front
|
146
|
+
ext == '.js' ? json = "var " + filename + " = " + json : json = json
|
147
|
+
|
148
|
+
# define flag
|
149
|
+
flag = 'w'
|
150
|
+
flag = 'wb' if Sass::Util.windows? && options[:unix_newlines]
|
151
|
+
|
128
152
|
# open file [create new file if file does not exist], write string to root/path/to/filename.json
|
129
|
-
File.open("#{dir_path}",
|
153
|
+
File.open("#{dir_path}", flag) { |f| f.write(json) }
|
154
|
+
|
155
|
+
# define message
|
156
|
+
debug_msg = "#{ext == '.json' ? 'JSON' : 'JavaScript'} was successfully exported to #{dir_path}"
|
130
157
|
|
131
158
|
# print path string if debug
|
132
|
-
if debug
|
133
|
-
puts "JSON was successfully exported to #{dir_path}"
|
134
|
-
end
|
159
|
+
puts debug_msg if debug
|
135
160
|
|
136
161
|
# return succcess string
|
137
|
-
|
162
|
+
opts(Sass::Script::Value::String.new(debug_msg))
|
138
163
|
end
|
139
164
|
declare :SassyExport, [:path, :map, :pretty, :debug]
|
140
165
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// SassyExport : convert passed map to json and write to path/to/filename.json
|
2
2
|
// ----------------------------------------------------------------------------------------------------
|
3
|
-
// @param $path [string] : directory path and filename
|
3
|
+
// @param $path [string] : directory path and filename, valid extensions: [json | js]
|
4
4
|
// @param $map [map] : map to convert to json
|
5
5
|
// @param $pretty [bool] : pretty print json
|
6
6
|
// @param $debug [bool] : print debug string with path
|
@@ -8,15 +8,5 @@
|
|
8
8
|
// @return $string | write json to path
|
9
9
|
|
10
10
|
@mixin SassyExport($path, $map, $pretty: false, $debug: false) {
|
11
|
-
@at-root {
|
12
|
-
@if $debug {
|
13
|
-
SassyExport {
|
14
|
-
content: "#{SassyExport($path, $map, $pretty, $debug)}";
|
15
|
-
}
|
16
|
-
} @else {
|
17
|
-
%SassyExport {
|
18
|
-
/* #{SassyExport($path, $map, $pretty, $debug)} */
|
19
|
-
}
|
20
|
-
}
|
21
|
-
}
|
11
|
+
@at-root { @if $debug { /* #{SassyExport($path, $map, $pretty, $debug)} */ } }
|
22
12
|
}
|
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
|
+
version: 1.3.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-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|