colorly 0.1.2 → 0.1.4
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/bin/colorly +4 -7
- data/lib/colorly/cli.rb +1 -1
- data/lib/colorly/command.rb +25 -25
- data/lib/colorly/dsl.rb +2 -2
- data/lib/colorly/exceptions.rb +0 -2
- data/lib/colorly/extensions/chroma_color.rb +13 -13
- data/lib/colorly/refinements/string.rb +9 -9
- data/lib/colorly/script.rb +6 -5
- data/lib/colorly/version.rb +1 -1
- data/lib/colorly.rb +9 -9
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d060e9b777f5060b1223717a5434390dadf403391882bf5a64b83ab2fb98e67
|
4
|
+
data.tar.gz: a9cb9f6a76f3cae702e6ec7d21b574e4904b3a6fd4ccc629765721c47874aa94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e233a4edcef61f4077ddba54ee9c09c5c8d29657c35e69e26c54a2a91f962f1258e7b03bfc4e9f558ed3967140f5479d8f7a3f881f2298f7ab8efe8a244752dc
|
7
|
+
data.tar.gz: 99b83717e0b23aa4fba35bddc8062bb0474f78f35fd7c9c6ebc8e37b8bc8053fbe56ab3fdbb94a58c8d8e3fa412676a1ef0b894a6abc48bb98a6d3112aa23ac4
|
data/bin/colorly
CHANGED
@@ -7,18 +7,15 @@ router = Colorly::CLI.router
|
|
7
7
|
|
8
8
|
begin
|
9
9
|
exit router.run ARGV
|
10
|
-
|
11
10
|
rescue Interrupt
|
12
11
|
say "\nGoodbye"
|
13
|
-
exit 1
|
14
|
-
|
12
|
+
exit 1
|
15
13
|
rescue => e
|
16
14
|
if ENV['DEBUG']
|
17
|
-
puts e.backtrace.reverse
|
18
|
-
say
|
15
|
+
puts e.backtrace.reverse
|
16
|
+
say ''
|
19
17
|
end
|
20
18
|
say "!undred!ERROR: #{e.class}"
|
21
19
|
say e.message
|
22
20
|
exit 1
|
23
|
-
|
24
|
-
end
|
21
|
+
end
|
data/lib/colorly/cli.rb
CHANGED
data/lib/colorly/command.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'colsole'
|
2
|
+
require 'mister_bin'
|
3
3
|
require 'erb'
|
4
4
|
require 'filewatcher'
|
5
5
|
require 'json'
|
@@ -9,24 +9,24 @@ require 'yaml'
|
|
9
9
|
module Colorly
|
10
10
|
class Command < MisterBin::Command
|
11
11
|
include Colsole
|
12
|
-
summary
|
12
|
+
summary 'Run a colorly script'
|
13
13
|
version Colorly::VERSION
|
14
14
|
|
15
|
-
help
|
15
|
+
help 'Execute a colorly script and save or print its output'
|
16
16
|
|
17
|
-
usage
|
18
|
-
usage
|
17
|
+
usage 'colorly SCRIPT [OUTPUT_PATH] [--watch --names]'
|
18
|
+
usage 'colorly --help | --version'
|
19
19
|
|
20
|
-
option
|
21
|
-
option
|
20
|
+
option '-w --watch', 'Watch the script file and regenerate on change'
|
21
|
+
option '-n --names', 'Also show color names and shades (slower)'
|
22
22
|
|
23
|
-
param
|
24
|
-
param
|
23
|
+
param 'SCRIPT', 'Path to script file'
|
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."
|
25
25
|
|
26
|
-
example
|
27
|
-
example
|
28
|
-
example
|
29
|
-
example
|
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'
|
30
30
|
|
31
31
|
attr_reader :script_path, :script, :out_path, :use_names
|
32
32
|
|
@@ -35,21 +35,21 @@ module Colorly
|
|
35
35
|
@out_path = args['OUTPUT_PATH']
|
36
36
|
@use_names = args['--names']
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
generate
|
43
|
-
end
|
38
|
+
generate
|
39
|
+
return unless args['--watch']
|
40
|
+
|
41
|
+
watch_and_generate
|
44
42
|
end
|
45
43
|
|
46
44
|
private
|
47
45
|
|
46
|
+
def filewatcher
|
47
|
+
@filewatcher ||= Filewatcher.new(script_path)
|
48
|
+
end
|
49
|
+
|
48
50
|
def watch_and_generate
|
49
51
|
say "Watching !txtpur!#{script_path}"
|
50
|
-
|
51
|
-
generate
|
52
|
-
end
|
52
|
+
filewatcher.watch { generate }
|
53
53
|
end
|
54
54
|
|
55
55
|
def generate
|
@@ -78,7 +78,7 @@ module Colorly
|
|
78
78
|
else
|
79
79
|
raise Colorly::ArgumentError, "Unknown output format for #{out_path}"
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
File.write out_path, out_string
|
83
83
|
say "Saved !txtpur!#{out_path}"
|
84
84
|
end
|
@@ -88,7 +88,7 @@ module Colorly
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def html_template_file
|
91
|
-
File.expand_path
|
91
|
+
File.expand_path 'templates/html.erb', __dir__
|
92
92
|
end
|
93
93
|
|
94
94
|
def erb(template, vars)
|
data/lib/colorly/dsl.rb
CHANGED
@@ -4,7 +4,7 @@ module Colorly
|
|
4
4
|
@current_title = title
|
5
5
|
end
|
6
6
|
|
7
|
-
def add(color)
|
7
|
+
def add(color)
|
8
8
|
if color.is_a? Array
|
9
9
|
color.each { |c| add c }
|
10
10
|
else
|
@@ -19,7 +19,7 @@ module Colorly
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def random
|
22
|
-
|
22
|
+
'#%06x' % (rand * 0xffffff)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/lib/colorly/exceptions.rb
CHANGED
@@ -23,42 +23,42 @@ protected
|
|
23
23
|
this_hex = "##{this_hex}"
|
24
24
|
if to_hex == this_hex
|
25
25
|
return {
|
26
|
-
name:
|
26
|
+
name: this_name,
|
27
27
|
shade: this_shade,
|
28
28
|
}
|
29
29
|
end
|
30
30
|
|
31
31
|
candidate_distance = color_distance this_hex.paint
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
next unless !distance || (distance > candidate_distance)
|
34
|
+
|
35
|
+
distance = candidate_distance
|
36
|
+
result = {
|
37
|
+
name: this_name,
|
38
|
+
shade: this_shade,
|
39
|
+
}
|
40
40
|
end
|
41
41
|
|
42
42
|
result
|
43
43
|
end
|
44
44
|
|
45
45
|
def color_distance(other)
|
46
|
-
rgb_distance(other) + hsl_distance(other) * 2
|
46
|
+
rgb_distance(other) + (hsl_distance(other) * 2)
|
47
47
|
end
|
48
48
|
|
49
49
|
def rgb_distance(other)
|
50
50
|
r1, g1, b1 = rgb
|
51
51
|
r2, g2, b2 = other.rgb
|
52
52
|
|
53
|
-
(r1 - r2)
|
53
|
+
((r1 - r2)**2) + ((g1 - g2)**2) + ((b1 - b2)**2)
|
54
54
|
end
|
55
55
|
|
56
56
|
def hsl_distance(other)
|
57
57
|
h1, s1, l1 = hsl
|
58
58
|
h2, s2, l2 = other.hsl
|
59
59
|
|
60
|
-
(((h1 - h2)
|
61
|
-
((s1 - s2)
|
62
|
-
((l1 - l2)
|
60
|
+
(((h1 - h2)**2).abs / 360.0) +
|
61
|
+
((s1 - s2)**2).abs +
|
62
|
+
((l1 - l2)**2).abs
|
63
63
|
end
|
64
64
|
end
|
@@ -3,36 +3,36 @@ require 'chroma'
|
|
3
3
|
module StringRefinements
|
4
4
|
refine String do
|
5
5
|
def spin(*args)
|
6
|
-
paint.spin
|
6
|
+
paint.spin(*args)
|
7
7
|
end
|
8
8
|
|
9
9
|
def brighten(*args)
|
10
|
-
paint.brighten
|
10
|
+
paint.brighten(*args)
|
11
11
|
end
|
12
12
|
|
13
13
|
def lighten(*args)
|
14
|
-
paint.lighten
|
14
|
+
paint.lighten(*args)
|
15
15
|
end
|
16
16
|
|
17
17
|
def darken(*args)
|
18
|
-
paint.darken
|
18
|
+
paint.darken(*args)
|
19
19
|
end
|
20
20
|
|
21
21
|
def saturate(*args)
|
22
|
-
paint.saturate
|
22
|
+
paint.saturate(*args)
|
23
23
|
end
|
24
24
|
|
25
25
|
def desaturate(*args)
|
26
|
-
paint.desaturate
|
26
|
+
paint.desaturate(*args)
|
27
27
|
end
|
28
28
|
|
29
29
|
def greyscale
|
30
30
|
paint.greyscale
|
31
31
|
end
|
32
|
-
|
32
|
+
alias_method :grayscale, :greyscale
|
33
33
|
|
34
34
|
def palette(*args)
|
35
|
-
paint.palette
|
35
|
+
paint.palette(*args)
|
36
36
|
end
|
37
37
|
end
|
38
|
-
end
|
38
|
+
end
|
data/lib/colorly/script.rb
CHANGED
@@ -7,19 +7,21 @@ module Colorly
|
|
7
7
|
|
8
8
|
def self.load(script_file)
|
9
9
|
raise ScriptNotFound, "Unable to load #{script_file}" unless File.exist? script_file
|
10
|
+
|
10
11
|
new File.read(script_file), filename: script_file
|
11
12
|
end
|
12
13
|
|
13
14
|
def initialize(script, filename: nil)
|
14
|
-
@script
|
15
|
+
@script = script
|
16
|
+
@filename = filename
|
15
17
|
end
|
16
18
|
|
17
19
|
def run
|
18
20
|
run!
|
19
21
|
rescue SyntaxError => e
|
20
|
-
raise ScriptSyntaxError
|
22
|
+
raise ScriptSyntaxError, e
|
21
23
|
rescue => e
|
22
|
-
raise ScriptError
|
24
|
+
raise ScriptError, e
|
23
25
|
end
|
24
26
|
|
25
27
|
def output
|
@@ -58,8 +60,7 @@ module Colorly
|
|
58
60
|
end
|
59
61
|
|
60
62
|
def current_title
|
61
|
-
@current_title ||=
|
63
|
+
@current_title ||= 'Colors'
|
62
64
|
end
|
63
|
-
|
64
65
|
end
|
65
66
|
end
|
data/lib/colorly/version.rb
CHANGED
data/lib/colorly.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
require 'yaml'
|
2
|
+
require 'requires'
|
3
|
+
require 'byebug' if ENV['BYEBUG']
|
4
|
+
|
5
|
+
requires 'colorly/exceptions'
|
6
|
+
requires 'colorly/version'
|
7
|
+
requires 'colorly'
|
8
8
|
|
9
9
|
module Colorly
|
10
10
|
class << self
|
11
11
|
def color_names
|
12
|
-
@color_names ||= YAML.load_file(File.expand_path
|
12
|
+
@color_names ||= YAML.load_file(File.expand_path 'colorly/data/color-names.yml', __dir__)['colors']
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colorly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chroma
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0
|
75
|
+
version: '1.0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0
|
82
|
+
version: '1.0'
|
83
83
|
description: Command line for generating color palettes
|
84
84
|
email: db@dannyben.com
|
85
85
|
executables:
|
@@ -106,6 +106,7 @@ licenses:
|
|
106
106
|
metadata:
|
107
107
|
bug_tracker_uri: https://github.com/DannyBen/colorly/issues
|
108
108
|
source_code_uri: https://github.com/dannyben/colorly
|
109
|
+
rubygems_mfa_required: 'true'
|
109
110
|
post_install_message:
|
110
111
|
rdoc_options: []
|
111
112
|
require_paths:
|
@@ -114,14 +115,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
115
|
requirements:
|
115
116
|
- - ">="
|
116
117
|
- !ruby/object:Gem::Version
|
117
|
-
version: 2.
|
118
|
+
version: '2.7'
|
118
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
120
|
requirements:
|
120
121
|
- - ">="
|
121
122
|
- !ruby/object:Gem::Version
|
122
123
|
version: '0'
|
123
124
|
requirements: []
|
124
|
-
rubygems_version: 3.3
|
125
|
+
rubygems_version: 3.4.3
|
125
126
|
signing_key:
|
126
127
|
specification_version: 4
|
127
128
|
summary: Colorly color palette CLI
|