sass-json-vars 0.3.0 → 0.3.1
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.rb +3 -0
- data/lib/sass-json-vars/importer.rb +37 -34
- data/lib/sass-json-vars/version.rb +1 -1
- data/readme.md +4 -1
- data/test/sass-json-vars_importer_test.rb +35 -0
- data/test/sass-json-vars_test.rb +1 -0
- data/test/sass_test.rb +1 -0
- data/test/test_helper.rb +5 -0
- metadata +34 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04a057f4ee1cfa22a9d04208dbf70ac34fb37ad5
|
4
|
+
data.tar.gz: 34d30e1f2dc0a26a7e1155686f11d72dbe83a3b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f258552b4eb6bd8d2ec46c668cb6db8acca3f0ff9ed81bc151ebb9324c3044adab12462de53fd2517706d19b43bca8ac7f0b53231c148afb4bc9168759fce4dc
|
7
|
+
data.tar.gz: c720626ba8f4b6254fd14047e8a60d03cf41a84ef3196e39fa702d4127168c2261cec77e3eebd9443dc2993cb706b1ad44943f9145fcc5ba9b30d5ed7b0e1a5e
|
data/lib/sass-json-vars.rb
CHANGED
@@ -1,52 +1,55 @@
|
|
1
1
|
require 'sass'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
|
4
|
+
module SassJSONVars
|
5
|
+
class Importer < Sass::Importers::Filesystem
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def watched_file?(uri)
|
8
|
+
!!(uri =~ /\.json$/ &&
|
9
|
+
uri.start_with?(root + File::SEPARATOR))
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
+
protected
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
def extensions
|
15
|
+
{'json' => :scss}
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def json?(name)
|
19
|
+
File.extname(name) == '.json'
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
+
private
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
def _find(dir, name, options)
|
25
|
+
return unless json? name
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name, options))
|
28
|
+
return unless full_filename && File.readable?(full_filename)
|
28
29
|
|
29
|
-
|
30
|
-
|
30
|
+
json = JSON.parse(IO.read(full_filename))
|
31
|
+
variables = json.map { |key, value| "$#{key}: #{_convert_to_sass(value)}" }.join("\n")
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
Sass::Engine.new(variables)
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
def _convert_to_sass(item)
|
37
|
+
if item.is_a? Array
|
38
|
+
_make_list(item)
|
39
|
+
elsif item.is_a? Hash
|
40
|
+
_make_map(item)
|
41
|
+
else
|
42
|
+
item
|
43
|
+
end
|
42
44
|
end
|
43
|
-
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
def _make_list(item)
|
47
|
+
'(' + item.map { |i| _convert_to_sass(i) }.join(',') + ')'
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
50
|
+
def _make_map(item)
|
51
|
+
'(' + item.map {|key, value| key.to_s + ':' + _convert_to_sass(value) }.join(',') + ')'
|
52
|
+
end
|
51
53
|
end
|
54
|
+
|
52
55
|
end
|
data/readme.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Sass JSON Vars
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/vigetlabs/sass-json-vars.png?branch=master)](https://travis-ci.org/vigetlabs/sass-json-vars)
|
3
|
+
[![Build Status](https://travis-ci.org/vigetlabs/sass-json-vars.png?branch=master)](https://travis-ci.org/vigetlabs/sass-json-vars)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/vigetlabs/sass-json-vars/badge.png)](https://coveralls.io/r/vigetlabs/sass-json-vars)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/vigetlabs/sass-json-vars.png)](https://codeclimate.com/github/vigetlabs/sass-json-vars)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/sass-json-vars.png)](http://badge.fury.io/rb/sass-json-vars)
|
4
7
|
|
5
8
|
`@import` json data into Sass `$variables`.
|
6
9
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'sass'
|
4
|
+
require 'sass-json-vars'
|
5
|
+
|
6
|
+
class SassJSONVarsImporterTest < Test::Unit::TestCase
|
7
|
+
def test_unwatched_non_json_file
|
8
|
+
unwatched_file = make_path(root, 'style.scss')
|
9
|
+
assert_equal false, importer.watched_file?(unwatched_file)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_unwatched_non_root_file
|
13
|
+
unwatched_file = make_path([File.dirname(__FILE__)], 'fixtures', 'maps', 'variables.json')
|
14
|
+
assert_equal false, importer.watched_file?(unwatched_file)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_watched_file
|
18
|
+
watched_file = make_path(root, 'variables.json')
|
19
|
+
assert_equal true, importer.watched_file?(watched_file)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def importer
|
25
|
+
@importer ||= SassJSONVars::Importer.new(root)
|
26
|
+
end
|
27
|
+
|
28
|
+
def root
|
29
|
+
make_path [File.dirname(__FILE__)], 'fixtures', 'strings'
|
30
|
+
end
|
31
|
+
|
32
|
+
def make_path(*path_components)
|
33
|
+
path_components.join(File::SEPARATOR)
|
34
|
+
end
|
35
|
+
end
|
data/test/sass-json-vars_test.rb
CHANGED
data/test/sass_test.rb
CHANGED
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sass-json-vars
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Hunzaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sass
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: simplecov
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.7.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.7.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coveralls
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
description: Allows the use of JSON to declare variables with @import 'file.json'.
|
28
56
|
email:
|
29
57
|
- nate.hunzaker@viget.com
|
@@ -45,8 +73,10 @@ files:
|
|
45
73
|
- test/fixtures/sass/variables.json
|
46
74
|
- test/fixtures/strings/style.scss
|
47
75
|
- test/fixtures/strings/variables.json
|
76
|
+
- test/sass-json-vars_importer_test.rb
|
48
77
|
- test/sass-json-vars_test.rb
|
49
78
|
- test/sass_test.rb
|
79
|
+
- test/test_helper.rb
|
50
80
|
homepage: https://github.com/vigetlabs/sass-json-vars
|
51
81
|
licenses:
|
52
82
|
- MIT
|
@@ -80,5 +110,7 @@ test_files:
|
|
80
110
|
- test/fixtures/sass/variables.json
|
81
111
|
- test/fixtures/strings/style.scss
|
82
112
|
- test/fixtures/strings/variables.json
|
113
|
+
- test/sass-json-vars_importer_test.rb
|
83
114
|
- test/sass-json-vars_test.rb
|
84
115
|
- test/sass_test.rb
|
116
|
+
- test/test_helper.rb
|