sass-json-vars 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 64106623ea0e4f551ffd3fe0e2abb0452ae3f03a
4
+ data.tar.gz: d94659199cde5cdf68cd31a3ff22a61d7bb882a5
5
+ SHA512:
6
+ metadata.gz: 89e4ba7d494b4255e2ce4281c694cbb2a48eda9a91ea6cd4683a5af802821847d182750554e9d87b77ba93f641cb33ed9ae2d0700476329d6e2535e760a709ec
7
+ data.tar.gz: 04ac9cd7836a11c36d670a14b3097f730badb865c6a169b04c5e112a7d904ed7aa9519a74fbb6e19d17cad9ee288c4b54fdcd6220ff5c31887f05ed91f8b8258
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'lib'
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
@@ -0,0 +1,5 @@
1
+ module SassJSONVars; end
2
+
3
+ require 'sass-json-vars/importer';
4
+
5
+ Sass.load_paths << SassJSONVars::Importer.new()
@@ -0,0 +1,46 @@
1
+ require 'sass'
2
+ require 'json'
3
+
4
+ class SassJSONVars::Importer < Sass::Importers::Base
5
+
6
+ def find(uri, options)
7
+ if File.extname(uri) == '.json'
8
+ self.class.sass_engine(uri, self, options)
9
+ else
10
+ nil
11
+ end
12
+ end
13
+
14
+ def find_relative(uri, base, options)
15
+ nil
16
+ end
17
+
18
+ def to_s
19
+ self.class.name
20
+ end
21
+
22
+ def hash
23
+ self.class.name.hash
24
+ end
25
+
26
+ def eql?(other)
27
+ other.class == self.class
28
+ end
29
+
30
+ def self.flat_hash(h, f=[], g={})
31
+ return g.update({ f.join('-') => h }) unless h.is_a? Hash
32
+ h.each { |k,r| flat_hash(r,f+[k],g) }
33
+ g
34
+ end
35
+
36
+ # Returns a Sass::Engine for this sprite object
37
+ def self.sass_engine(uri, importer, options)
38
+ flattened = self.flat_hash JSON.parse(IO.read(uri))
39
+
40
+ variables = flattened.map do |name, value|
41
+ "$#{name}: #{value}"
42
+ end
43
+
44
+ Sass::Engine.new(variables.join("\n"))
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module SassJSONVars
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # Sass JSON Vars
2
+
3
+ A work in progress.
4
+
5
+ ### Eventual Usage
6
+
7
+ Place variables in a JSON file:
8
+
9
+ ```javascript
10
+ {
11
+ color: {
12
+ red: "#c33"
13
+ }
14
+ }
15
+ ```
16
+
17
+ Import the file in Sass to expose variable names:
18
+
19
+ ```scss
20
+ @import "variables.json"
21
+
22
+ body {
23
+ color: $color-red;
24
+ }
25
+ ```
@@ -0,0 +1,5 @@
1
+ @import 'test/fixtures/variables.json';
2
+
3
+ body {
4
+ color: $color-red;
5
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "color" : {
3
+ "red" : "#c33",
4
+ "blue" : "#33c"
5
+ }
6
+ }
@@ -0,0 +1,19 @@
1
+ require 'test/unit'
2
+ require 'sass'
3
+ require 'sass-json-vars'
4
+
5
+ class SassJSONVarsTest < Test::Unit::TestCase
6
+
7
+ def test_can_flatten_hashes
8
+ flattened = SassJSONVars::Importer.flat_hash({
9
+ :color => { :red => "#c33" }
10
+ })
11
+ assert_match '#c33', flattened['color-red']
12
+ end
13
+
14
+ def test_importability
15
+ scss = Sass.compile_file("test/fixtures/full_path.scss")
16
+ assert_equal "body {\n color: #cc3333; }\n", scss
17
+ end
18
+
19
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sass-json-vars
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nate Hunzaker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sass
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ description: Allows the use of JSON to declare variables with @import 'file.json'.
28
+ email:
29
+ - nate.hunzaker@viget.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Rakefile
35
+ - lib/sass-json-vars.rb
36
+ - lib/sass-json-vars/importer.rb
37
+ - lib/sass-json-vars/version.rb
38
+ - readme.md
39
+ - test/fixtures/full_path.scss
40
+ - test/fixtures/variables.json
41
+ - test/sass-json-vars_test.rb
42
+ homepage: https://github.com/vigetlabs/sass-json-vars
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.2.2
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Allows the use of JSON to declare variables with @import 'file.json'.
66
+ test_files:
67
+ - test/fixtures/full_path.scss
68
+ - test/fixtures/variables.json
69
+ - test/sass-json-vars_test.rb