colorly 0.0.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ require 'chroma'
2
+
3
+ module StringRefinements
4
+ refine String do
5
+ def spin(*args)
6
+ paint.spin *args
7
+ end
8
+
9
+ def brighten(*args)
10
+ paint.brighten *args
11
+ end
12
+
13
+ def lighten(*args)
14
+ paint.lighten *args
15
+ end
16
+
17
+ def darken(*args)
18
+ paint.darken *args
19
+ end
20
+
21
+ def saturate(*args)
22
+ paint.saturate *args
23
+ end
24
+
25
+ def desaturate(*args)
26
+ paint.desaturate *args
27
+ end
28
+
29
+ def greyscale
30
+ paint.greyscale
31
+ end
32
+ alias grayscale greyscale
33
+
34
+ def palette(*args)
35
+ paint.palette *args
36
+ end
37
+ end
38
+ end
@@ -1,6 +1,9 @@
1
1
  module Colorly
2
2
  class Script
3
+ include DSL
4
+ using StringRefinements
3
5
  attr_reader :script, :filename
6
+ attr_writer :params
4
7
 
5
8
  def self.load(script_file)
6
9
  raise ScriptNotFound, "Unable to load #{script_file}" unless File.exist? script_file
@@ -12,49 +15,50 @@ module Colorly
12
15
  end
13
16
 
14
17
  def run
15
- instance_eval script
18
+ run!
19
+ rescue SyntaxError => e
20
+ raise ScriptSyntaxError.new e
21
+ rescue => e
22
+ raise ScriptError.new e
16
23
  end
17
24
 
18
25
  def output
19
26
  @output ||= {}
20
27
  end
21
28
 
22
- def to_h
29
+ def params
30
+ @params ||= {}
31
+ end
32
+
33
+ def simple_output(names: false)
23
34
  output.transform_values do |chroma_array|
24
35
  chroma_array.map do |chroma|
25
- chroma.to_hex
36
+ if names
37
+ { hex: chroma.to_hex, name: [chroma.name, chroma.shade] }
38
+ else
39
+ chroma.to_hex
40
+ end
26
41
  end
27
42
  end
28
43
  end
44
+ alias to_h simple_output
29
45
 
30
- # DSL Methods
31
-
32
- def title(title)
33
- @current_title = title
34
- end
46
+ private
35
47
 
36
- def add(color)
37
- if color.is_a? Array
38
- color.each { |c| add c }
48
+ def run!
49
+ if filename
50
+ instance_eval script, filename
39
51
  else
40
- output[current_title] ||= []
41
- @last = color.is_a?(String) ? color.paint : color
42
- output[current_title] << last
52
+ instance_eval script
43
53
  end
44
54
  end
45
55
 
46
- def last
47
- @last ||= 'red'.paint
56
+ def register(color)
57
+ @last = color.is_a?(String) ? color.paint : color
48
58
  end
49
59
 
50
- def random
51
- "#%06x" % (rand * 0xffffff)
52
- end
53
-
54
- private
55
-
56
60
  def current_title
57
- @current_title ||= "Untitled"
61
+ @current_title ||= "Colors"
58
62
  end
59
63
 
60
64
  end
@@ -13,7 +13,7 @@
13
13
  .color {
14
14
  float: left;
15
15
  width: 120px;
16
- height: 120px;
16
+ height: 80px;
17
17
  padding: 10px 10px 10px 10px;
18
18
  border: 2px solid white;
19
19
  border-radius: 10px;
@@ -29,16 +29,23 @@
29
29
  }
30
30
  </style>
31
31
 
32
- <% output.each do |name, colors| %>
32
+ <%- output.each do |name, colors| -%>
33
+ <div class='colorset'>
33
34
  <h2><%= name %></h2>
34
- <% colors.each do |color| %>
35
- <% css_class = color.dark? ? 'dark color' : 'light color' %>
36
- <div class='<%= css_class %>' style='background-color:<%= color.to_hex %>'>
37
- <%= color.to_hex.upcase %><br>
38
- <%= color.shade %><br>
39
- <%= color.name %><br>
40
- </div>
41
- <% end %>
42
- <% end %>
35
+
36
+ <%- colors.each do |color| -%>
37
+ <%- css_class = color.dark? ? 'dark color' : 'light color' -%>
38
+ <div class='<%= css_class %>' style='background-color:<%= color.to_hex %>'>
39
+ <%= color.to_hex.upcase %>
40
+ <%- if use_names -%>
41
+ <br><%= color.shade %><br><%= color.name %>
42
+ <%- end -%>
43
+ </div>
44
+
45
+ <%- end -%>
46
+ </div>
47
+
48
+ <%- end -%>
49
+
43
50
  </body>
44
51
  </html>
@@ -1,3 +1,3 @@
1
1
  module Colorly
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/colorly.rb CHANGED
@@ -1,5 +1,15 @@
1
+ require "yaml"
1
2
  require "requires"
2
3
  require "byebug" if ENV["BYEBUG"]
3
4
  requires \
4
5
  "colorly/exceptions",
6
+ "colorly/version",
5
7
  "colorly"
8
+
9
+ module Colorly
10
+ class << self
11
+ def color_names
12
+ @color_names ||= YAML.load_file(File.expand_path "colorly/data/color-names.yml", __dir__)['colors']
13
+ end
14
+ 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.0.1
4
+ version: 0.1.2
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: 2021-06-17 00:00:00.000000000 Z
11
+ date: 2022-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chroma
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.1'
47
+ version: '2.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.1'
54
+ version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mister_bin
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -92,9 +92,11 @@ files:
92
92
  - lib/colorly.rb
93
93
  - lib/colorly/cli.rb
94
94
  - lib/colorly/command.rb
95
+ - lib/colorly/data/color-names.yml
96
+ - lib/colorly/dsl.rb
95
97
  - lib/colorly/exceptions.rb
96
98
  - lib/colorly/extensions/chroma_color.rb
97
- - lib/colorly/extensions/string.rb
99
+ - lib/colorly/refinements/string.rb
98
100
  - lib/colorly/script.rb
99
101
  - lib/colorly/templates/html.erb
100
102
  - lib/colorly/version.rb
@@ -112,14 +114,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
114
  requirements:
113
115
  - - ">="
114
116
  - !ruby/object:Gem::Version
115
- version: 2.4.0
117
+ version: 2.6.0
116
118
  required_rubygems_version: !ruby/object:Gem::Requirement
117
119
  requirements:
118
120
  - - ">="
119
121
  - !ruby/object:Gem::Version
120
122
  version: '0'
121
123
  requirements: []
122
- rubygems_version: 3.2.16
124
+ rubygems_version: 3.3.14
123
125
  signing_key:
124
126
  specification_version: 4
125
127
  summary: Colorly color palette CLI
@@ -1,27 +0,0 @@
1
- require 'chroma'
2
-
3
- class String
4
- def spin(*args)
5
- paint.spin *args
6
- end
7
-
8
- def darken(*args)
9
- paint.darken *args
10
- end
11
-
12
- def lighten(*args)
13
- paint.lighten *args
14
- end
15
-
16
- def saturate(*args)
17
- paint.saturate *args
18
- end
19
-
20
- def desaturate(*args)
21
- paint.desaturate *args
22
- end
23
-
24
- def palette(*args)
25
- paint.palette *args
26
- end
27
- end