chroma 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/CHANGELOG.md +22 -4
- data/README.md +14 -0
- data/lib/chroma.rb +5 -1
- data/lib/chroma/color.rb +16 -0
- data/lib/chroma/palette_builder.rb +30 -21
- data/lib/chroma/version.rb +1 -1
- data/spec/color/custom_palette_spec.rb +19 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba59f54923418c9d94c2c434673428053bb71d71
|
4
|
+
data.tar.gz: 83e5c63353336387b402b9afd78533f6d0439e04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c72995a317f6f18237dcdd0abb1023610895a777407d41a96df667ad56a306949ab3b36cc131c7e6412d5895387e53904dc3de6e03a1d50db40e74e3ced4ab74
|
7
|
+
data.tar.gz: d3bdef0aca890fc72a95f5d1eacfb527f92c4d42c07adbcaad01c376fb63a9c321f7093b7a7ae58aaa7cc6a0b7ea5cd4453b38740fe069a19fe7cca97d9ff3ff
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,22 @@
|
|
1
|
-
|
1
|
+
## v0.1.0 - 2016-05-26
|
2
|
+
|
3
|
+
### Dynamic Custom Palettes
|
4
|
+
|
5
|
+
You can generate custom palettes on the fly without predefining them now. The
|
6
|
+
old way of defining them with a name via `Chroma.define_palette` still works
|
7
|
+
too.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
# New dynamic way
|
11
|
+
'red'.paint.custom_palette do
|
12
|
+
spin 60
|
13
|
+
spin 180
|
14
|
+
end
|
15
|
+
|
16
|
+
#=> [red, yellow, cyan]
|
17
|
+
```
|
18
|
+
|
19
|
+
## v0.0.1 - 2015-01-14
|
2
20
|
|
3
21
|
**Method Changes:**
|
4
22
|
|
@@ -15,7 +33,7 @@
|
|
15
33
|
* Minor API doc example fixes.
|
16
34
|
* Add public API usage examples to README.
|
17
35
|
|
18
|
-
|
36
|
+
## [v0.0.1.alpha.3] - 2015-01-13
|
19
37
|
|
20
38
|
**Bug Fixes:**
|
21
39
|
|
@@ -41,7 +59,7 @@
|
|
41
59
|
* Introduced custom errors and replaced `raise` calls with them.
|
42
60
|
* Added API doc headers. (#4)
|
43
61
|
|
44
|
-
|
62
|
+
## [v0.0.1.alpha.2] - 2015-01-13
|
45
63
|
|
46
64
|
**Bug Fixes:**
|
47
65
|
|
@@ -82,6 +100,6 @@
|
|
82
100
|
* `to_rgb_s` -> `to_rgb`
|
83
101
|
* Removed `to_name_s` alias
|
84
102
|
|
85
|
-
|
103
|
+
## [v0.0.1.alpha.1] - 2015-01-11
|
86
104
|
|
87
105
|
* Initial release
|
data/README.md
CHANGED
@@ -270,6 +270,20 @@ red.palette.respond_to? :my_palette #=> true
|
|
270
270
|
red.palette.my_palette #=> [#ff0000 #ffff00 #00ffff #ffff33 #808080]
|
271
271
|
```
|
272
272
|
|
273
|
+
## Dynamic Custom Palettes
|
274
|
+
|
275
|
+
You can generate custom palettes on the fly too with
|
276
|
+
`Chroma::Color#custom_palette`.
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
'red'.paint.custom_palette do
|
280
|
+
spin 60
|
281
|
+
spin 180
|
282
|
+
end
|
283
|
+
|
284
|
+
#=> [red, yellow, cyan]
|
285
|
+
```
|
286
|
+
|
273
287
|
## Serializing Colors
|
274
288
|
|
275
289
|
Colors offer several methods to output to different string color [formats](#available-formats).
|
data/lib/chroma.rb
CHANGED
@@ -112,7 +112,11 @@ module Chroma
|
|
112
112
|
raise Errors::PaletteDefinedError, "Palette `#{name}' already exists"
|
113
113
|
end
|
114
114
|
|
115
|
-
PaletteBuilder.build(
|
115
|
+
palette_evaluator = PaletteBuilder.build(&block)
|
116
|
+
|
117
|
+
Harmonies.send(:define_method, name) do
|
118
|
+
palette_evaluator.evaluate(@color)
|
119
|
+
end
|
116
120
|
end
|
117
121
|
|
118
122
|
private
|
data/lib/chroma/color.rb
CHANGED
@@ -82,6 +82,22 @@ module Chroma
|
|
82
82
|
Harmonies.new(self)
|
83
83
|
end
|
84
84
|
|
85
|
+
# Defines a custom palette and immediately returns it. Uses a DSL inside
|
86
|
+
# `block` that mirrors the methods in {Color::Modifiers}.
|
87
|
+
#
|
88
|
+
# @example
|
89
|
+
# 'red'.paint.custom_palette do
|
90
|
+
# spin 60
|
91
|
+
# spin 180
|
92
|
+
# end
|
93
|
+
# #=> [red, yellow, cyan]
|
94
|
+
#
|
95
|
+
# @param block [Proc] the palette definition block
|
96
|
+
# @return [Array<Color>] palette array of colors
|
97
|
+
def custom_palette(&block)
|
98
|
+
PaletteBuilder.build(&block).evaluate(self)
|
99
|
+
end
|
100
|
+
|
85
101
|
private
|
86
102
|
|
87
103
|
def to_2char_hex(n)
|
@@ -4,47 +4,56 @@ module Chroma
|
|
4
4
|
# Wrapper to instantiate a new instance of {PaletteBuilder} and call its
|
5
5
|
# {PaletteBuilder#build} method.
|
6
6
|
#
|
7
|
-
# @param
|
8
|
-
# @
|
9
|
-
|
10
|
-
|
11
|
-
new(name, &block).build
|
7
|
+
# @param block [Proc] the palette definition block
|
8
|
+
# @return [PaletteBuilder::PaletteEvaluator] lazy palette generator
|
9
|
+
def self.build(&block)
|
10
|
+
new(&block).build
|
12
11
|
end
|
13
12
|
|
14
|
-
# @param
|
15
|
-
|
16
|
-
def initialize(name, &block)
|
17
|
-
@name = name
|
13
|
+
# @param block [Proc] the palette definition block
|
14
|
+
def initialize(&block)
|
18
15
|
@block = block
|
19
16
|
end
|
20
17
|
|
21
|
-
# Build the custom palette
|
22
|
-
# @return [
|
18
|
+
# Build the custom palette
|
19
|
+
# @return [PaletteBuilder::PaletteEvaluator] lazy palette generator
|
23
20
|
def build
|
24
21
|
dsl = PaletteBuilderDsl.new
|
25
22
|
dsl.instance_eval(&@block)
|
26
|
-
|
27
|
-
|
28
|
-
Harmonies.send(:define_method, @name) do
|
29
|
-
conversions.map do |color_calls|
|
30
|
-
color_calls.evaluate(@color)
|
31
|
-
end.unshift(@color)
|
32
|
-
end
|
23
|
+
dsl.evaluator
|
33
24
|
end
|
34
25
|
|
35
26
|
private
|
36
27
|
|
28
|
+
# Internal class for delaying evaluating a color to generate a
|
29
|
+
# final palette
|
30
|
+
class PaletteEvaluator
|
31
|
+
def initialize
|
32
|
+
@conversions = []
|
33
|
+
end
|
34
|
+
|
35
|
+
def <<(conversion)
|
36
|
+
@conversions << conversion
|
37
|
+
end
|
38
|
+
|
39
|
+
def evaluate(color)
|
40
|
+
@conversions.map do |color_calls|
|
41
|
+
color_calls.evaluate(color)
|
42
|
+
end.unshift(color)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
37
46
|
# Internal class for palette building DSL syntax.
|
38
47
|
class PaletteBuilderDsl
|
39
|
-
attr_reader :
|
48
|
+
attr_reader :evaluator
|
40
49
|
|
41
50
|
def initialize
|
42
|
-
@
|
51
|
+
@evaluator = PaletteEvaluator.new
|
43
52
|
end
|
44
53
|
|
45
54
|
def method_missing(name, *args)
|
46
55
|
ColorCalls.new(name, args).tap do |color_calls|
|
47
|
-
@
|
56
|
+
@evaluator << color_calls
|
48
57
|
end
|
49
58
|
end
|
50
59
|
|
data/lib/chroma/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
describe Chroma::Color, '#custom_palette' do
|
2
|
+
let(:subject) do
|
3
|
+
'red'.paint.custom_palette do
|
4
|
+
spin 60
|
5
|
+
spin 180
|
6
|
+
spin(60).brighten(20)
|
7
|
+
greyscale
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'generates the correct colors' do
|
12
|
+
expect(subject).
|
13
|
+
to generate_palette %w(#ff0000 #ffff00 #00ffff #ffff33 #808080)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'keeps the same format' do
|
17
|
+
expect(subject).to all have_format :name
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chroma
|
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
|
- Jeremy Fairbank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- spec/chroma/paint_spec.rb
|
101
101
|
- spec/chroma_spec.rb
|
102
102
|
- spec/color/attributes_spec.rb
|
103
|
+
- spec/color/custom_palette_spec.rb
|
103
104
|
- spec/color/modifiers_spec.rb
|
104
105
|
- spec/color/palette_spec.rb
|
105
106
|
- spec/color/serializers_spec.rb
|
@@ -135,6 +136,7 @@ test_files:
|
|
135
136
|
- spec/chroma/paint_spec.rb
|
136
137
|
- spec/chroma_spec.rb
|
137
138
|
- spec/color/attributes_spec.rb
|
139
|
+
- spec/color/custom_palette_spec.rb
|
138
140
|
- spec/color/modifiers_spec.rb
|
139
141
|
- spec/color/palette_spec.rb
|
140
142
|
- spec/color/serializers_spec.rb
|