SassyExport 1.0.15 → 1.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -9
- data/lib/SassyExport.rb +96 -16
- data/stylesheets/SassyExport.scss +7 -9
- metadata +35 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a0376df2bf1ef80b279783a53fa05181c178cc5
|
4
|
+
data.tar.gz: 5465885674875366b8febbf82e2191fa05f2f9a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6440c955c275386ed84755751fb257d46396973a7b76357779ed6b300acaf8140d6ffc19a4e3fa3865a7a8252cdc167b11158fe8a1282236fce722727b0f1aa
|
7
|
+
data.tar.gz: ebb1f4400249d5761c59d005e887d7b251a086f6f2b23067bf1756324ebb738b8fde7e1fc377bead3aa63a9deffc85ef646577ef634b85eb2072cc1005ec4955
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SassyExport [![Gem Version](https://badge.fury.io/rb/SassyExport.svg)](http://badge.fury.io/rb/SassyExport)
|
2
2
|
|
3
|
-
SassyExport is a lightweight
|
3
|
+
SassyExport is a lightweight Compass extension that allows you to export an encoded Sass map into an external JSON file. Use it anyway you like.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -31,27 +31,32 @@ $map: (
|
|
31
31
|
hello: world,
|
32
32
|
);
|
33
33
|
|
34
|
-
|
34
|
+
// SassyExport : convert passed map to json and write to path/to/filename.json
|
35
|
+
// ----------------------------------------------------------------------------------------------------
|
36
|
+
// @param $path [string] : directory path and filename
|
37
|
+
// @param $map [map] : map to convert to json
|
38
|
+
// @param $pretty [bool] : pretty print json
|
39
|
+
// ----------------------------------------------------------------------------------------------------
|
40
|
+
// @return $string | write json to path
|
41
|
+
|
42
|
+
@include SassyExport("/json/hello.json", $map, true);
|
35
43
|
```
|
36
44
|
|
37
45
|
#### Result
|
38
46
|
|
39
47
|
New JSON file is created at `./json/hello.json`. As you can see, `$path` is relative to where your `config.rb` is located. Simply calling `@include SassyExport("/hello.json", $map)` will write to your directory root.
|
40
48
|
```json
|
41
|
-
{
|
49
|
+
{
|
50
|
+
"hello": "world"
|
51
|
+
}
|
42
52
|
```
|
43
53
|
|
44
54
|
#### Breakdown
|
45
55
|
|
46
|
-
The `
|
56
|
+
The `SassyExport()` mixin takes a directory/filename.json `$path`, and a Sass `$map` as arguments. It then converts the `$map` into a JSON map with SassyJSON's `json_encode()` function, then Ruby 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.
|
47
57
|
|
48
58
|
Enjoy.
|
49
59
|
|
50
60
|
## SassyJSON
|
51
61
|
|
52
62
|
* [Download SassyJSON](https://github.com/HugoGiraudel/SassyJSON)
|
53
|
-
|
54
|
-
## Credits
|
55
|
-
|
56
|
-
* [Fabrice Weinberg](http://twitter.com/fweinb)
|
57
|
-
* [Hugo Giraudel](http://twitter.com/hugogiraudel)
|
data/lib/SassyExport.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# @dependency https://github.com/HugoGiraudel/SassyJSON
|
4
|
-
# ----------------------------------------------------------------------------------------------------
|
5
|
-
|
6
|
-
require "SassyJSON"
|
1
|
+
require "compass"
|
2
|
+
require "json"
|
7
3
|
|
8
4
|
extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
9
5
|
Compass::Frameworks.register('SassyExport', :path => extension_path)
|
@@ -11,24 +7,108 @@ Compass::Frameworks.register('SassyExport', :path => extension_path)
|
|
11
7
|
# Version is a number. If a version contains alphas, it will be created as a prerelease version
|
12
8
|
# Date is in the form of YYYY-MM-DD
|
13
9
|
module SassyExport
|
14
|
-
VERSION = "1.0.
|
15
|
-
DATE = "2014-06-
|
10
|
+
VERSION = "1.0.16"
|
11
|
+
DATE = "2014-06-04"
|
16
12
|
end
|
17
13
|
|
18
|
-
# SassyExport :
|
14
|
+
# SassyExport : convert passed map to json and write to path/to/filename.json
|
19
15
|
# ----------------------------------------------------------------------------------------------------
|
20
|
-
# @param path [string] : directory path
|
21
|
-
# @param
|
16
|
+
# @param path [string] : directory path and filename
|
17
|
+
# @param map [map] : map to convert to json
|
18
|
+
# @param pretty [bool] : pretty print json
|
22
19
|
# ----------------------------------------------------------------------------------------------------
|
23
|
-
# @return string | write
|
20
|
+
# @return string | write json to path
|
24
21
|
|
25
22
|
module Sass::Script::Functions
|
26
|
-
def SassyExport(path,
|
23
|
+
def SassyExport(path, map, pretty)
|
24
|
+
|
25
|
+
def opts(value)
|
26
|
+
value.options = options
|
27
|
+
value
|
28
|
+
end
|
29
|
+
|
30
|
+
# recursive parse to array
|
31
|
+
def recurs_to_a(array)
|
32
|
+
if array.is_a?(Array)
|
33
|
+
array.map do | l |
|
34
|
+
if l.is_a?(Sass::Script::Value::Map)
|
35
|
+
l = recurs_to_h(l)
|
36
|
+
elsif l.is_a?(Sass::Script::Value::List)
|
37
|
+
l = recurs_to_a(l)
|
38
|
+
elsif l.is_a?(Sass::Script::Value::Bool)
|
39
|
+
l = l.to_bool
|
40
|
+
elsif l.is_a?(Sass::Script::Value::Number)
|
41
|
+
if l.unitless?
|
42
|
+
l = l.to_i
|
43
|
+
else
|
44
|
+
l = l.to_s
|
45
|
+
end
|
46
|
+
end
|
47
|
+
l
|
48
|
+
end
|
49
|
+
else
|
50
|
+
recurs_to_a(array.to_a)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# recursive parse to hash
|
55
|
+
def recurs_to_h(hash)
|
56
|
+
if hash.is_a?(Hash)
|
57
|
+
hash.inject({}) do | h, (k, v) |
|
58
|
+
if v.is_a?(Sass::Script::Value::Map)
|
59
|
+
h[k] = recurs_to_h(v)
|
60
|
+
elsif v.is_a?(Sass::Script::Value::List)
|
61
|
+
h[k] = recurs_to_a(v)
|
62
|
+
elsif v.is_a?(Sass::Script::Value::Bool)
|
63
|
+
h[k] = v.to_bool
|
64
|
+
elsif v.is_a?(Sass::Script::Value::Number)
|
65
|
+
if v.unitless?
|
66
|
+
h[k] = v.to_i
|
67
|
+
else
|
68
|
+
h[k] = v.to_s
|
69
|
+
end
|
70
|
+
else
|
71
|
+
h[k] = v.to_s
|
72
|
+
end
|
73
|
+
h
|
74
|
+
end
|
75
|
+
else
|
76
|
+
recurs_to_h(hash.to_h)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# assert types
|
81
|
+
assert_type path, :String, :path
|
82
|
+
assert_type map, :Map, :map
|
83
|
+
assert_type pretty, :Bool, :pretty
|
84
|
+
|
85
|
+
# parse to bool
|
86
|
+
pretty = pretty.to_bool
|
87
|
+
|
27
88
|
# define root path up to current working directory
|
28
89
|
root = Dir.pwd
|
90
|
+
|
91
|
+
# define dir path
|
92
|
+
dir_path = root
|
93
|
+
dir_path += unquote(path).to_s
|
94
|
+
|
95
|
+
# normalize windows path
|
96
|
+
dir_path = Sass::Util.pathname(dir_path)
|
97
|
+
|
98
|
+
# get map values
|
99
|
+
map = opts(Sass::Script::Value::Map.new(map.value))
|
100
|
+
|
101
|
+
# recursive convert map to hash
|
102
|
+
hash = recurs_to_h(map)
|
103
|
+
|
104
|
+
# convert hash to pretty json if pretty
|
105
|
+
pretty ? json = JSON.pretty_generate(hash) : json = JSON.generate(hash)
|
106
|
+
|
29
107
|
# open file [create new file if file does not exist], write string to root/path/to/filename.json
|
30
|
-
File.open("#{
|
31
|
-
|
32
|
-
return
|
108
|
+
File.open("#{dir_path}", "w") { |f| f.write(json) }
|
109
|
+
|
110
|
+
# return a null val
|
111
|
+
return opts(Sass::Script::Value::String.new('JSON was successfully exported with love by SassyExport'))
|
33
112
|
end
|
113
|
+
declare :SassyExport, [:path, :map, :pretty]
|
34
114
|
end
|
@@ -1,17 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
// ----------------------------------------------------------------------------------------------------
|
4
|
-
// SassyExport : write passed json string to $path/to/filename.json
|
1
|
+
// SassyExport : convert passed map to json and write to path/to/filename.json
|
5
2
|
// ----------------------------------------------------------------------------------------------------
|
6
|
-
// @param $path [string] : directory path and filename
|
7
|
-
// @param $map [map] : map to
|
3
|
+
// @param $path [string] : directory path and filename
|
4
|
+
// @param $map [map] : map to convert to json
|
5
|
+
// @param $pretty [bool] : pretty print json
|
8
6
|
// ----------------------------------------------------------------------------------------------------
|
9
|
-
// @return
|
7
|
+
// @return $string | write json to path
|
10
8
|
|
11
|
-
@mixin SassyExport($path, $map) {
|
9
|
+
@mixin SassyExport($path, $map, $pretty: false) {
|
12
10
|
@at-root {
|
13
11
|
%SassyExport {
|
14
|
-
|
12
|
+
/* #{SassyExport($path, $map, $pretty)} */
|
15
13
|
}
|
16
14
|
}
|
17
15
|
}
|
metadata
CHANGED
@@ -1,31 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SassyExport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.16
|
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-
|
11
|
+
date: 2014-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.1
|
19
|
+
version: 1.8.1
|
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
|
-
version: 1.1
|
27
|
-
|
28
|
-
|
26
|
+
version: 1.8.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sass
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: compass
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.12.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.12.1
|
55
|
+
description: SassyExport is a lightweight Compass extension that allows you to export
|
56
|
+
an encoded Sass map into an external JSON file.
|
29
57
|
email:
|
30
58
|
- ezekg@yahoo.com
|
31
59
|
executables: []
|