sass-json-vars 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sass-json-vars/importer.rb +13 -8
- data/lib/sass-json-vars/version.rb +1 -1
- data/readme.md +18 -5
- data/test/fixtures/lists/style.scss +5 -0
- data/test/fixtures/lists/variables.json +3 -0
- data/test/fixtures/maps/style.scss +5 -0
- data/test/fixtures/maps/variables.json +5 -0
- data/test/fixtures/strings/style.scss +5 -0
- data/test/fixtures/strings/variables.json +4 -0
- data/test/sass-json-vars_test.rb +33 -7
- metadata +13 -5
- data/test/fixtures/full_path.scss +0 -5
- data/test/fixtures/variables.json +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bee8311004adacb3fe1c3aaf810f585f74e0cd8b
|
4
|
+
data.tar.gz: 7fb0ca0f8a34da3ac0d8dd234f71f840fb9db7ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1207db98b67ade60e3fb44990096d83f1529e1bc8262fb3098dbf357ef80d25a623b3acb4fef9020ce2d61d3a37483fb588bbd5f761ecb3e81d1bf3ca41f93c4
|
7
|
+
data.tar.gz: d6f3ca6e07666a05f9fcceeda7abacd706cea46085dc40e3583808338c71e04ee2047b8aad0d04b8d1e36129fc66546bb253e27980681ba6722a5e9f4d97a551
|
@@ -27,18 +27,23 @@ class SassJSONVars::Importer < Sass::Importers::Base
|
|
27
27
|
other.class == self.class
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
def self.convert_to_sass(item)
|
31
|
+
if item.is_a? Array
|
32
|
+
'(' + item.map { |i| self.convert_to_sass(i) }.join(',') + ')'
|
33
|
+
elsif item.is_a? Hash
|
34
|
+
'(' + item.map {|key, value| key.to_s + ':' + self.convert_to_sass(value) }.join(',') + ')'
|
35
|
+
else
|
36
|
+
item
|
37
|
+
end
|
34
38
|
end
|
35
39
|
|
36
|
-
# Returns a Sass::Engine for this sprite object
|
37
40
|
def self.sass_engine(uri, importer, options)
|
38
|
-
|
41
|
+
json = JSON.parse(IO.read(uri))
|
42
|
+
|
43
|
+
variables = json.map do |name, value|
|
44
|
+
output = self.convert_to_sass(value);
|
39
45
|
|
40
|
-
|
41
|
-
"$#{name}: #{value}"
|
46
|
+
"$#{name}: #{output}"
|
42
47
|
end
|
43
48
|
|
44
49
|
Sass::Engine.new(variables.join("\n"))
|
data/readme.md
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
# Sass JSON Vars
|
2
2
|
|
3
|
-
|
3
|
+
`@import` json data into Sass `$variables`.
|
4
4
|
|
5
|
-
###
|
5
|
+
### Usage
|
6
|
+
|
7
|
+
```shell
|
8
|
+
gem install sass-json-vars
|
9
|
+
```
|
6
10
|
|
7
11
|
Place variables in a JSON file:
|
8
12
|
|
9
13
|
```javascript
|
14
|
+
// variables.json
|
10
15
|
{
|
11
|
-
|
12
|
-
|
16
|
+
"font-sans": "Helvetica, sans-serif",
|
17
|
+
"colors": {
|
18
|
+
"red": "#c33"
|
13
19
|
}
|
14
20
|
}
|
15
21
|
```
|
@@ -20,6 +26,13 @@ Import the file in Sass to expose variable names:
|
|
20
26
|
@import "variables.json"
|
21
27
|
|
22
28
|
body {
|
23
|
-
color: $
|
29
|
+
color: map-get($colors, red);
|
30
|
+
font: $font-sans;
|
24
31
|
}
|
25
32
|
```
|
33
|
+
|
34
|
+
Require sass-json-vars when compiling
|
35
|
+
|
36
|
+
```shell
|
37
|
+
sass style.scss -r sass-json-vars
|
38
|
+
```
|
data/test/sass-json-vars_test.rb
CHANGED
@@ -3,17 +3,43 @@ require 'sass'
|
|
3
3
|
require 'sass-json-vars'
|
4
4
|
|
5
5
|
class SassJSONVarsTest < Test::Unit::TestCase
|
6
|
+
def test_can_convert_arrays_to_lists
|
7
|
+
flattened = SassJSONVars::Importer.convert_to_sass(['#c33', '#33c'])
|
8
|
+
assert_equal '(#c33,#33c)', flattened
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_can_convert_nested_arrays_to_lists
|
12
|
+
flattened = SassJSONVars::Importer.convert_to_sass([['#c33', 'red'], '#33c'])
|
13
|
+
assert_equal '((#c33,red),#33c)', flattened
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_can_convert_hashes_to_maps
|
17
|
+
flattened = SassJSONVars::Importer.convert_to_sass({ red: '#c33' })
|
18
|
+
assert_equal '(red:#c33)', flattened
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_can_convert_nested_hashes_to_maps
|
22
|
+
flattened = SassJSONVars::Importer.convert_to_sass({ colors: { red: '#c33' } })
|
23
|
+
assert_equal '(colors:(red:#c33))', flattened
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_can_convert_complicated_objects
|
27
|
+
flattened = SassJSONVars::Importer.convert_to_sass({ colors: ['red', 'blue', 'green'] })
|
28
|
+
assert_equal '(colors:(red,blue,green))', flattened
|
29
|
+
end
|
6
30
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
})
|
11
|
-
assert_match '#c33', flattened['color-red']
|
31
|
+
def test_strings
|
32
|
+
scss = Sass.compile_file("test/fixtures/strings/style.scss")
|
33
|
+
assert_equal "body {\n color: #cc3333; }\n", scss
|
12
34
|
end
|
13
35
|
|
14
|
-
def
|
15
|
-
scss = Sass.compile_file("test/fixtures/
|
36
|
+
def test_lists
|
37
|
+
scss = Sass.compile_file("test/fixtures/lists/style.scss")
|
16
38
|
assert_equal "body {\n color: #cc3333; }\n", scss
|
17
39
|
end
|
18
40
|
|
41
|
+
def test_maps
|
42
|
+
scss = Sass.compile_file("test/fixtures/maps/style.scss")
|
43
|
+
assert_equal "body {\n color: #cc3333; }\n", scss
|
44
|
+
end
|
19
45
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sass-json-vars
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Hunzaker
|
@@ -36,8 +36,12 @@ files:
|
|
36
36
|
- lib/sass-json-vars/importer.rb
|
37
37
|
- lib/sass-json-vars/version.rb
|
38
38
|
- readme.md
|
39
|
-
- test/fixtures/
|
40
|
-
- test/fixtures/variables.json
|
39
|
+
- test/fixtures/lists/style.scss
|
40
|
+
- test/fixtures/lists/variables.json
|
41
|
+
- test/fixtures/maps/style.scss
|
42
|
+
- test/fixtures/maps/variables.json
|
43
|
+
- test/fixtures/strings/style.scss
|
44
|
+
- test/fixtures/strings/variables.json
|
41
45
|
- test/sass-json-vars_test.rb
|
42
46
|
homepage: https://github.com/vigetlabs/sass-json-vars
|
43
47
|
licenses:
|
@@ -64,6 +68,10 @@ signing_key:
|
|
64
68
|
specification_version: 4
|
65
69
|
summary: Allows the use of JSON to declare variables with @import 'file.json'.
|
66
70
|
test_files:
|
67
|
-
- test/fixtures/
|
68
|
-
- test/fixtures/variables.json
|
71
|
+
- test/fixtures/lists/style.scss
|
72
|
+
- test/fixtures/lists/variables.json
|
73
|
+
- test/fixtures/maps/style.scss
|
74
|
+
- test/fixtures/maps/variables.json
|
75
|
+
- test/fixtures/strings/style.scss
|
76
|
+
- test/fixtures/strings/variables.json
|
69
77
|
- test/sass-json-vars_test.rb
|