colorly 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e226698701401f2d344fdb86c29a565a0f2f755a8f898ea2141212ea041d7f6
4
- data.tar.gz: e0ecfe18a06ec74643537bc12f1c47de586952818b34b261e16b4ac38cabaa54
3
+ metadata.gz: 572649998dd2a43148239699a5c95c418d38860f7a89bc15ccba507b1414acab
4
+ data.tar.gz: 062e72d51fe3fc1c61a1f4e3a8e2da95c5f4da8883a7ddd80c4a79639cb93ef0
5
5
  SHA512:
6
- metadata.gz: 1611fbb6413770476051200ab010fec0eb31cad171992862bb67ba217f95d3a75b48ecb86d2ce7a11689ef6d19ebfd5ae364279426b5c6f3c01a689679ab7d35
7
- data.tar.gz: affdfca2a14d43594223abc53bf3d51acd0bb26b0f0f740113c6b7ce2810db2614de8b7dd8cc45648725d1d12543bc74b6ef5658821f390a750dd259d3af4ac9
6
+ metadata.gz: 3e911bd401cf6459e7e24ed6396b2e4b0c0c6bad1e31e66e7204edbb568dcc2963f155f509c6638959f4f91dc2bbce5c4d7f2cd434e74609278f265a601e317c
7
+ data.tar.gz: f4755d5079887a84bf97acb6624a1917648c98ea35e00e05f0128a32f15556c7d0d25e9eb793c70d9dae7e11f1e25da2c65d5e84aa738137b12726158a6d0c00
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  ---
8
8
 
9
- Colorly is a command line urility and a Ruby library for generating color
9
+ Colorly is a command line utility and a Ruby library for generating color
10
10
  palettes using a simple DSL.
11
11
 
12
12
  It is a thin wrapper around the [chroma] gem.
@@ -107,9 +107,15 @@ require 'colorly'
107
107
  script = Colorly::Script.load 'script_file.rb'
108
108
 
109
109
  # ... or from a string
110
- script_string = "title 'Hello'; add 'red'.spin 10 ; add last.spin 10"
110
+ script_string = "title 'Hello'; add params[:base_color] ; add last.spin 90"
111
111
  script = Colorly::Script.new script_string
112
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
+
113
119
  # Run it
114
120
  script.run
115
121
 
@@ -10,14 +10,15 @@ 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
17
  usage "colorly SCRIPT [OUTPUT_PATH] [--watch --names]"
17
- usage "colorly --help"
18
+ usage "colorly --help | --version"
18
19
 
19
- option "-w, --watch", "Watch the script file and regenerate on change"
20
- option "-n, --names", "Also show color names and shades (slower)"
20
+ option "-w --watch", "Watch the script file and regenerate on change"
21
+ option "-n --names", "Also show color names and shades (slower)"
21
22
 
22
23
  param "SCRIPT", "Path to script file"
23
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."
@@ -0,0 +1,25 @@
1
+ module Colorly
2
+ module DSL
3
+ def title(title)
4
+ @current_title = title
5
+ end
6
+
7
+ def add(color)
8
+ if color.is_a? Array
9
+ color.each { |c| add c }
10
+ else
11
+ output[current_title] ||= []
12
+ register color
13
+ output[current_title] << last
14
+ end
15
+ end
16
+
17
+ def last
18
+ @last ||= 'red'.paint
19
+ end
20
+
21
+ def random
22
+ "#%06x" % (rand * 0xffffff)
23
+ end
24
+ end
25
+ end
@@ -1,7 +1,9 @@
1
1
  module Colorly
2
2
  class Script
3
+ include DSL
3
4
  using StringRefinements
4
5
  attr_reader :script, :filename
6
+ attr_writer :params
5
7
 
6
8
  def self.load(script_file)
7
9
  raise ScriptNotFound, "Unable to load #{script_file}" unless File.exist? script_file
@@ -24,6 +26,10 @@ module Colorly
24
26
  @output ||= {}
25
27
  end
26
28
 
29
+ def params
30
+ @params ||= {}
31
+ end
32
+
27
33
  def simple_output(names: false)
28
34
  output.transform_values do |chroma_array|
29
35
  chroma_array.map do |chroma|
@@ -37,34 +43,6 @@ module Colorly
37
43
  end
38
44
  alias to_h simple_output
39
45
 
40
- # DSL Methods
41
-
42
- def title(title)
43
- @current_title = title
44
- end
45
-
46
- def add(color)
47
- if color.is_a? Array
48
- color.each { |c| add c }
49
- else
50
- output[current_title] ||= []
51
- register color
52
- output[current_title] << last
53
- end
54
- end
55
-
56
- def register(color)
57
- @last = color.is_a?(String) ? color.paint : color
58
- end
59
-
60
- def last
61
- @last ||= 'red'.paint
62
- end
63
-
64
- def random
65
- "#%06x" % (rand * 0xffffff)
66
- end
67
-
68
46
  private
69
47
 
70
48
  def run!
@@ -75,8 +53,12 @@ module Colorly
75
53
  end
76
54
  end
77
55
 
56
+ def register(color)
57
+ @last = color.is_a?(String) ? color.paint : color
58
+ end
59
+
78
60
  def current_title
79
- @current_title ||= "Untitled"
61
+ @current_title ||= "Colors"
80
62
  end
81
63
 
82
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;
@@ -1,3 +1,3 @@
1
1
  module Colorly
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/colorly.rb CHANGED
@@ -3,6 +3,7 @@ require "requires"
3
3
  require "byebug" if ENV["BYEBUG"]
4
4
  requires \
5
5
  "colorly/exceptions",
6
+ "colorly/version",
6
7
  "colorly"
7
8
 
8
9
  module Colorly
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.0
4
+ version: 0.1.1
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-18 00:00:00.000000000 Z
11
+ date: 2021-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chroma
@@ -93,6 +93,7 @@ files:
93
93
  - lib/colorly/cli.rb
94
94
  - lib/colorly/command.rb
95
95
  - lib/colorly/data/color-names.yml
96
+ - lib/colorly/dsl.rb
96
97
  - lib/colorly/exceptions.rb
97
98
  - lib/colorly/extensions/chroma_color.rb
98
99
  - lib/colorly/refinements/string.rb
@@ -120,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  - !ruby/object:Gem::Version
121
122
  version: '0'
122
123
  requirements: []
123
- rubygems_version: 3.2.16
124
+ rubygems_version: 3.2.25
124
125
  signing_key:
125
126
  specification_version: 4
126
127
  summary: Colorly color palette CLI