colorly 0.0.1 → 0.1.2
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 +4 -4
- data/README.md +129 -3
- data/lib/colorly/command.rb +21 -13
- data/lib/colorly/data/color-names.yml +1640 -0
- data/lib/colorly/dsl.rb +25 -0
- data/lib/colorly/exceptions.rb +19 -0
- data/lib/colorly/extensions/chroma_color.rb +25 -1662
- data/lib/colorly/refinements/string.rb +38 -0
- data/lib/colorly/script.rb +27 -23
- data/lib/colorly/templates/html.erb +18 -11
- data/lib/colorly/version.rb +1 -1
- data/lib/colorly.rb +10 -0
- metadata +9 -7
- data/lib/colorly/extensions/string.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7535f4f4f8e3bfddf9fd52b898c9d9462cadff128268a6be84d8f36dc701f58
|
4
|
+
data.tar.gz: 58066978fcee8cbfaac56e8f4be3e11550756083e3e490af10e29245d19a82f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a66ca24e08128a4922e3b0249b4b577fb9cebc6ecbe1fe65a4d877e05d18a67d3499309c819a0c0d67f24afef4640c6b8ec5e0e5a79bc92185907bbc1ce05132
|
7
|
+
data.tar.gz: 702180db6d13a1a8da042257c06f51983791234d4113591552cc8e33def5c007ad2ff1cd0d2c3f2fbfa4126c9c3d8fdd62c9ba855e8cf44bb49c90045d77fa42
|
data/README.md
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/colorly)
|
4
4
|
[](https://github.com/DannyBen/colorly/actions?query=workflow%3ATest)
|
5
|
+
[](https://codeclimate.com/github/DannyBen/colorly/maintainability)
|
5
6
|
|
6
7
|
---
|
7
8
|
|
8
|
-
Colorly is a command line
|
9
|
+
Colorly is a command line utility and a Ruby library for generating color
|
9
10
|
palettes using a simple DSL.
|
10
11
|
|
11
12
|
It is a thin wrapper around the [chroma] gem.
|
@@ -20,11 +21,136 @@ The colorly command line outputs the palette as JSON, YAML or HTML.
|
|
20
21
|
$ gem install colorly
|
21
22
|
```
|
22
23
|
|
24
|
+
## Example
|
25
|
+
|
26
|
+
Colorly provides you with a simple ruby-based DSL for generating a color palette.
|
27
|
+
|
28
|
+
Start by creating this file:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# sample.rb
|
32
|
+
title "Set 1"
|
33
|
+
add 'red'.lighten 20
|
34
|
+
add last.spin 60
|
35
|
+
add last.spin 60
|
36
|
+
```
|
37
|
+
|
38
|
+
then run it by calling:
|
39
|
+
|
40
|
+
```
|
41
|
+
$ colorly sample.rb output.html
|
42
|
+
```
|
43
|
+
|
44
|
+
output:
|
45
|
+
|
46
|
+

|
47
|
+
|
48
|
+
For more detailed examples, view the [examples folder](examples).
|
49
|
+
|
50
|
+
|
51
|
+
## Usage
|
52
|
+
|
53
|
+
Colorly scripts are built with a minimalist set of Ruby commands (DSL):
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# Start a new color set
|
57
|
+
title "Any unique name for this set"
|
58
|
+
|
59
|
+
# Add colors to this set
|
60
|
+
add 'yellow'.darken(10).desaturate(10)
|
61
|
+
add last.spin 20
|
62
|
+
|
63
|
+
# Start another set
|
64
|
+
title "New set"
|
65
|
+
add '#ff3344'
|
66
|
+
# ...
|
67
|
+
```
|
68
|
+
|
69
|
+
The colors provided to the `add` command can be
|
70
|
+
[anything that is supported by `Chroma`](https://github.com/jfairbank/chroma#creating-colors),
|
71
|
+
or an array of the same.
|
72
|
+
|
73
|
+
In addition, you can call the below `Chroma` methods directly on any color.
|
74
|
+
They will be forwarded to `Chroma`:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
'red'.spin # same as 'red'.paint.spin
|
78
|
+
'red'.brighten # same as 'red'.paint.brighten
|
79
|
+
'red'.darken # same as 'red'.paint.darken
|
80
|
+
'red'.lighten # same as 'red'.paint.lighten
|
81
|
+
'red'.saturate # same as 'red'.paint.saturate
|
82
|
+
'red'.desaturate # same as 'red'.paint.desaturate
|
83
|
+
'red'.greyscale # same as 'red'.paint.greyscale (also grayscale)
|
84
|
+
'red'.palette # same as 'red'.paint.palette
|
85
|
+
```
|
86
|
+
|
87
|
+
You can use the last added color with the variable `last`, and generate a
|
88
|
+
random color by calling `random`:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
title "Example"
|
92
|
+
add 'red'.spin 10
|
93
|
+
add last.spin 30
|
94
|
+
add last.spin 30
|
95
|
+
add random.desaturate 10
|
96
|
+
```
|
97
|
+
|
98
|
+
## Using from Ruby code
|
99
|
+
|
100
|
+
If you wish to use Colorly from your own Ruby code, simply load a script to
|
101
|
+
the Script class:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
require 'colorly'
|
105
|
+
|
106
|
+
# Load from a file
|
107
|
+
script = Colorly::Script.load 'script_file.rb'
|
108
|
+
|
109
|
+
# ... or from a string
|
110
|
+
script_string = "title 'Hello'; add params[:base_color] ; add last.spin 90"
|
111
|
+
script = Colorly::Script.new script_string
|
112
|
+
|
113
|
+
# Optionally, pass parameters to the script, which you can use in the script
|
114
|
+
# by accessing the `params` hash.
|
115
|
+
script.params = { base_color: '#cdc' }
|
116
|
+
# or
|
117
|
+
script.params[:base_color] = '#cdc'
|
118
|
+
|
119
|
+
# Run it
|
120
|
+
script.run
|
121
|
+
|
122
|
+
# Get its output - each color is a Chroma::Color object
|
123
|
+
p script.output
|
124
|
+
p script.output["Hello"].first.class
|
125
|
+
#=> {"Hello"=>[#ff2b00, #ff5500]}
|
126
|
+
#=> Chroma::Color
|
127
|
+
|
128
|
+
# Get a simplified output where each color is just its hex string
|
129
|
+
p script.simple_output
|
130
|
+
#=> {"Hello"=>["#ff2b00", "#ff5500"]}
|
131
|
+
|
132
|
+
# Get a simplified output, including color names (slower)
|
133
|
+
# Get a simplified output, including color names (slower)
|
134
|
+
pp script.simple_output names: true
|
135
|
+
#=> {"Hello"=>
|
136
|
+
#=> [{:hex=>"#ff2b00", :name=>["Scarlet", "Red"]},
|
137
|
+
#=> {:hex=>"#ff5500", :name=>["International Orange", "Orange"]}]}
|
138
|
+
```
|
139
|
+
|
140
|
+
## Contributing / Support
|
141
|
+
|
142
|
+
If you experience any issue, have a question or a suggestion, or if you wish
|
143
|
+
to contribute, feel free to [open an issue][issues].
|
144
|
+
|
145
|
+
## Credits
|
146
|
+
|
147
|
+
- [Jeremy Fairbank](https://github.com/jfairbank) for the [chroma] gem.
|
148
|
+
- [Chirag Mehta](https://chir.ag/) for the original Javascript [color naming functions](https://chir.ag/projects/name-that-color).
|
149
|
+
- [Colblindor](https://www.color-blindness.com/color-name-hue/) for the additional base color (shade) work.
|
23
150
|
|
24
|
-
## Usage
|
25
151
|
|
26
|
-
SOON
|
27
152
|
|
28
153
|
---
|
29
154
|
|
30
155
|
[chroma]: https://github.com/jfairbank/chroma
|
156
|
+
[issues]: https://github.com/DannyBen/colorly/issues
|
data/lib/colorly/command.rb
CHANGED
@@ -10,28 +10,33 @@ module Colorly
|
|
10
10
|
class Command < MisterBin::Command
|
11
11
|
include Colsole
|
12
12
|
summary "Run a colorly script"
|
13
|
+
version Colorly::VERSION
|
13
14
|
|
14
15
|
help "Execute a colorly script and save or print its output"
|
15
16
|
|
16
|
-
usage "colorly SCRIPT [OUTPUT_PATH] [--watch]"
|
17
|
-
usage "colorly --help"
|
17
|
+
usage "colorly SCRIPT [OUTPUT_PATH] [--watch --names]"
|
18
|
+
usage "colorly --help | --version"
|
18
19
|
|
19
|
-
option "-w
|
20
|
+
option "-w --watch", "Watch the script file and regenerate on change"
|
21
|
+
option "-n --names", "Also show color names and shades (slower)"
|
20
22
|
|
21
23
|
param "SCRIPT", "Path to script file"
|
22
24
|
param "OUTPUT_PATH", "Path to output file. The output format is determined by the file extension. Supported formats:\n- YAML (.yaml or .yml)\n- JSON (.json)\n- HTML (.html)\nIf left empty, YAML format will be sent to STDOUT."
|
23
25
|
|
24
|
-
example "colorly examples/
|
25
|
-
example "colorly examples/
|
26
|
-
example "colorly examples/
|
26
|
+
example "colorly examples/example.rb"
|
27
|
+
example "colorly examples/example.rb --names"
|
28
|
+
example "colorly examples/example.rb out.json"
|
29
|
+
example "colorly examples/example.rb out.html --watch --names"
|
27
30
|
|
28
|
-
attr_reader :script_path, :script, :out_path
|
31
|
+
attr_reader :script_path, :script, :out_path, :use_names
|
29
32
|
|
30
33
|
def run
|
31
34
|
@script_path = args['SCRIPT']
|
32
35
|
@out_path = args['OUTPUT_PATH']
|
36
|
+
@use_names = args['--names']
|
33
37
|
|
34
38
|
if args['--watch']
|
39
|
+
generate
|
35
40
|
watch_and_generate
|
36
41
|
else
|
37
42
|
generate
|
@@ -55,17 +60,21 @@ module Colorly
|
|
55
60
|
end
|
56
61
|
|
57
62
|
def show_output
|
58
|
-
puts
|
63
|
+
puts simple_output.to_yaml
|
64
|
+
end
|
65
|
+
|
66
|
+
def simple_output
|
67
|
+
script.simple_output names: use_names
|
59
68
|
end
|
60
69
|
|
61
70
|
def save_file
|
62
71
|
out_string = case out_path
|
63
72
|
when /\.json$/
|
64
|
-
JSON.pretty_generate
|
73
|
+
JSON.pretty_generate simple_output
|
65
74
|
when /\.ya?ml$/
|
66
|
-
|
75
|
+
simple_output.to_yaml
|
67
76
|
when /\.html$/
|
68
|
-
erb html_template, { output: script.output }
|
77
|
+
erb html_template, { output: script.output, use_names: use_names }
|
69
78
|
else
|
70
79
|
raise Colorly::ArgumentError, "Unknown output format for #{out_path}"
|
71
80
|
end
|
@@ -83,8 +92,7 @@ module Colorly
|
|
83
92
|
end
|
84
93
|
|
85
94
|
def erb(template, vars)
|
86
|
-
ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
|
95
|
+
ERB.new(template, trim_mode: '%-').result(OpenStruct.new(vars).instance_eval { binding })
|
87
96
|
end
|
88
|
-
|
89
97
|
end
|
90
98
|
end
|