sass-color-extractor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +2 -0
- data/lib/sass_color_extractor.rb +5 -0
- data/lib/sass_color_extractor/base.rb +20 -0
- data/lib/sass_color_extractor/variable_evaluator.rb +15 -0
- data/lib/sass_color_extractor/version.rb +3 -0
- data/sass_color_extractor.gemspec +26 -0
- data/spec/fixtures/test_colors.sass +14 -0
- data/spec/fixtures/test_colors.scss +14 -0
- data/spec/sass_color_extractor_base_spec.rb +38 -0
- data/spec/sass_color_extractor_spec.rb +10 -0
- data/spec/spec_helper.rb +2 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1ae7876428c5d2897a0c21f5b1f37cf6d38f3490
|
4
|
+
data.tar.gz: 97f934a0f414ee53a57147b7f0991ef9a6b9bbfd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4171c3fa02c80048691c2f78eca6fae93a2e38cbdfdb723efd7c5bcda22a7794a05dbb4139a3fd2ae0f8996183ff7d1f47e2c8ba1701ffe857b35f8d47a41865
|
7
|
+
data.tar.gz: cbfce2cc399e3c1fee7bb9164f281a1b6de4e370918d660dfcb28234cc08db06d9991b494c02209cec5865f83ae992e6936335c58d323cbde336a16a8dcfc990
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2017 Mr Rogers
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# SassColorExtractor
|
2
|
+
|
3
|
+
This dirt simple Gem uses the Sass ruby library to read your `colors.scss` file and give you back
|
4
|
+
a list of color names and their actual colors which can be used to generate a nice color palette page in a
|
5
|
+
Rails app.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'sass_color_extractor'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install sass_color_extractor
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
You should extract your color variables into their own file (which you would then `@import` as necessary
|
26
|
+
in your scss/sass files. Once you have that, you can get a map of color names to their hex color like so:
|
27
|
+
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
scss_file = "/path/to/my/colors.scss"
|
32
|
+
pp SassColorExtractor.parse_colors(scss_file)
|
33
|
+
|
34
|
+
```
|
35
|
+
|
36
|
+
For a more concrete example, given this `colors.scss` file
|
37
|
+
|
38
|
+
```
|
39
|
+
/* My Colors File */
|
40
|
+
$black: #000;
|
41
|
+
$white: #ffffff;
|
42
|
+
$light_gray: darken($white, 20%);
|
43
|
+
$dark_gray: lighten($black, 20%);
|
44
|
+
```
|
45
|
+
|
46
|
+
You'd get a hash in ruby like this:
|
47
|
+
```
|
48
|
+
{
|
49
|
+
"black"=>"000",
|
50
|
+
"white"=>"ffffff",
|
51
|
+
"light_gray"=>"cccccc",
|
52
|
+
"dark_gray"=>"333333"
|
53
|
+
}
|
54
|
+
```
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it ( https://github.com/rcode5/sass_color_extractor/fork )
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module SassColorExtractor
|
2
|
+
class Base
|
3
|
+
DEFAULT_SYNTAX = :scss
|
4
|
+
|
5
|
+
def self.parse_colors(sass_file)
|
6
|
+
syntax = guess_syntax(sass_file)
|
7
|
+
engine = Sass::Engine.for_file(sass_file, syntax: syntax)
|
8
|
+
colors = VariableEvaluator.visit(engine.to_tree).compact.reject{|entry| entry.flatten.empty?}
|
9
|
+
Hash[colors.map{|name, color| [ name, color.to_s.gsub(/^#/,'') ]}]
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
private
|
14
|
+
def guess_syntax(file)
|
15
|
+
guess = File.extname(file)[-1..1].to_sym
|
16
|
+
[:sass, :scss].include?(guess) ? guess : DEFAULT_SYNTAX
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'sass'
|
2
|
+
module SassColorExtractor
|
3
|
+
class VariableEvaluator < Sass::Tree::Visitors::Base
|
4
|
+
def visit_variable(node)
|
5
|
+
@environment ||= Sass::Environment.new
|
6
|
+
begin
|
7
|
+
val = node.expr.perform(@environment)
|
8
|
+
rescue Sass::SyntaxError
|
9
|
+
val = node.expr
|
10
|
+
end
|
11
|
+
@environment.set_local_var(node.name, val)
|
12
|
+
[node.name, node.expr.perform(@environment)]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sass_color_extractor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sass-color-extractor"
|
8
|
+
spec.version = SassColorExtractor::VERSION
|
9
|
+
spec.authors = ["Mr Rogers"]
|
10
|
+
spec.email = ["jon@rcode5.com"]
|
11
|
+
spec.summary = %q{Extract colors from Sass/Scss in ruby - can be used to generate a nice palette for a Rails app.}
|
12
|
+
#spec.description = ""
|
13
|
+
spec.homepage = "https://github.com/rcode5/sass_color_extractor"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "sass", "~> 3.4"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/* whatever */
|
2
|
+
$black: #000;
|
3
|
+
$white: #ffffff;
|
4
|
+
$red: #ff0000;
|
5
|
+
$yellr: #fc2;
|
6
|
+
|
7
|
+
|
8
|
+
$light_yellr: lighten($yellr, 20%);
|
9
|
+
$dark_yellr: darken($yellr, 10%);
|
10
|
+
|
11
|
+
@mixin this { color: whatever; }
|
12
|
+
.style { overflow:hidden; }
|
13
|
+
|
14
|
+
// empty line and comment line
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SassColorExtractor::Base do
|
4
|
+
FIXTURE_PATH = "spec/fixtures"
|
5
|
+
describe ".parse_colors" do
|
6
|
+
|
7
|
+
context "given a Sass file" do
|
8
|
+
let(:file) { File.expand_path( File.join(FIXTURE_PATH, "test_colors.sass") ) }
|
9
|
+
it 'returns a list of the parsed colors' do
|
10
|
+
colors = described_class.parse_colors(file)
|
11
|
+
expect(colors).to eql({
|
12
|
+
"black" => "000",
|
13
|
+
"white" => "ffffff",
|
14
|
+
"red" => "ff0000",
|
15
|
+
"yellr" => "fc2",
|
16
|
+
"light_yellr" => "ffe488",
|
17
|
+
"dark_yellr" => "eeb700"
|
18
|
+
})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "given an Scss file" do
|
23
|
+
let(:file) { File.expand_path( File.join(FIXTURE_PATH, "test_colors.scss") ) }
|
24
|
+
it "returns a list of the parsed colors" do
|
25
|
+
colors = described_class.parse_colors(file)
|
26
|
+
expect(colors).to eql({
|
27
|
+
"black" => "000",
|
28
|
+
"white" => "ffffff",
|
29
|
+
"red" => "ff0000",
|
30
|
+
"yellr" => "fc2",
|
31
|
+
"light_yellr" => "ffe488",
|
32
|
+
"dark_yellr" => "eeb700"
|
33
|
+
})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sass-color-extractor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mr Rogers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-03 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.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.5'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- jon@rcode5.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/sass_color_extractor.rb
|
82
|
+
- lib/sass_color_extractor/base.rb
|
83
|
+
- lib/sass_color_extractor/variable_evaluator.rb
|
84
|
+
- lib/sass_color_extractor/version.rb
|
85
|
+
- sass_color_extractor.gemspec
|
86
|
+
- spec/fixtures/test_colors.sass
|
87
|
+
- spec/fixtures/test_colors.scss
|
88
|
+
- spec/sass_color_extractor_base_spec.rb
|
89
|
+
- spec/sass_color_extractor_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: https://github.com/rcode5/sass_color_extractor
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Extract colors from Sass/Scss in ruby - can be used to generate a nice palette
|
115
|
+
for a Rails app.
|
116
|
+
test_files:
|
117
|
+
- spec/fixtures/test_colors.sass
|
118
|
+
- spec/fixtures/test_colors.scss
|
119
|
+
- spec/sass_color_extractor_base_spec.rb
|
120
|
+
- spec/sass_color_extractor_spec.rb
|
121
|
+
- spec/spec_helper.rb
|