tone 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +44 -2
- data/lib/tone/aliaser.rb +2 -2
- data/lib/tone/rspec/matchers/have_color.rb +20 -0
- data/lib/tone.rb +4 -1
- data/tone.gemspec +3 -3
- data.tar.gz.sig +0 -0
- metadata +7 -6
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0598688304d0d6f067c4e234a89221866d6776e695f483a501e0b36ae53dc45
|
4
|
+
data.tar.gz: 2948824aa08f7b1c07d5bce6cfd99610a660ac23ceef2ad10af03417824c362b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c8847234b60d61ec895cf183eabc244111168622c68a579929e433b120ec12b346d062daf84f2731366c01ba0b6bb8bebccd13ec57472b29a341ec1ed1e7feb
|
7
|
+
data.tar.gz: e40439af7f32b56103819a09a2fd8fb762e4fc6fb73ce34ff98772d493b2e78c81a6b1d506b2c980eb44c17fc02e7d62b24e9cee6a03e44166eec9e4b595a1ee
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
:amazing_print_link: link:https://github.com/amazing-print/amazing_print[Amazing Print]
|
6
6
|
:pattern_matching_link: link:https://alchemists.io/articles/ruby_pattern_matching[pattern matching]
|
7
|
+
:rspec_link: link:https://rspec.info[RSpec]
|
7
8
|
|
8
9
|
= Tone
|
9
10
|
|
@@ -383,6 +384,47 @@ tone.get_alias :bogus
|
|
383
384
|
# Invalid alias or default: :bogus. (Tone::Error)
|
384
385
|
----
|
385
386
|
|
387
|
+
=== Testing
|
388
|
+
|
389
|
+
When using this gem in your project, you might find it convenient to use the `have_color` {rspec_link} matcher. This matcher is optional and _must be manually required_ for use in your spec helper:
|
390
|
+
|
391
|
+
[source,ruby]
|
392
|
+
----
|
393
|
+
# spec_helper.rb
|
394
|
+
require "tone/rspec/matchers/have_color"
|
395
|
+
----
|
396
|
+
|
397
|
+
Once required, you can leverage the matcher in any spec as follows:
|
398
|
+
|
399
|
+
[source,ruby]
|
400
|
+
----
|
401
|
+
RSpec.describe DemoPresenter do
|
402
|
+
subject(:presenter) { DemoPresenter.new color: }
|
403
|
+
|
404
|
+
let(:color) { Tone.new }
|
405
|
+
|
406
|
+
describe "#to_s" do
|
407
|
+
it "renders colored text" do
|
408
|
+
expect(presenter.to_s).to have_color(color, ["Test 0.0.0: A test.", :bold])
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
----
|
413
|
+
|
414
|
+
The first argument _must be an instanced of Tone_ because you might have custom aliases which must be known in order to validate your spec. All subsequent arguments (one to many) that follow after the first argument can be a list of decoded tuples as would normally be answered by `Tone#decode`.
|
415
|
+
|
416
|
+
In situations where the spec fails, you'll get a formatted error so you can quickly fix as necessary:
|
417
|
+
|
418
|
+
....
|
419
|
+
expected "\e[37mtest\e[0m\n" to have color decoded as:
|
420
|
+
["text", :blue],
|
421
|
+
["\n"]
|
422
|
+
|
423
|
+
but actually is:
|
424
|
+
["test", :white],
|
425
|
+
["\n"]
|
426
|
+
....
|
427
|
+
|
386
428
|
=== Guidelines
|
387
429
|
|
388
430
|
The following are worth considering, when using this gem, to help keep your implementation consistent.
|
@@ -426,14 +468,14 @@ cd tone
|
|
426
468
|
bin/setup
|
427
469
|
----
|
428
470
|
|
429
|
-
You use the IRB console for direct access to all objects:
|
471
|
+
You can use the IRB console for direct access to all objects:
|
430
472
|
|
431
473
|
[source,bash]
|
432
474
|
----
|
433
475
|
bin/console
|
434
476
|
----
|
435
477
|
|
436
|
-
Lastly, there is a `bin/show` script which
|
478
|
+
Lastly, there is a `bin/show` script which displays the default styles for quick visual reference. This is the same script used to generate the screenshots shown at the top of this document.
|
437
479
|
|
438
480
|
[source,bash]
|
439
481
|
----
|
data/lib/tone/aliaser.rb
CHANGED
@@ -20,7 +20,7 @@ module Tone
|
|
20
20
|
custom.fetch symbol do
|
21
21
|
return key if defaults.key? symbol
|
22
22
|
|
23
|
-
usage = defaults.keys.append(*custom.keys).
|
23
|
+
usage = defaults.keys.append(*custom.keys).to_usage "and/or"
|
24
24
|
|
25
25
|
fail Error, "Invalid alias or default: #{key.inspect}. Use: #{usage}."
|
26
26
|
end
|
@@ -51,7 +51,7 @@ module Tone
|
|
51
51
|
|
52
52
|
def check_style key, style
|
53
53
|
defaults.fetch style do
|
54
|
-
usage = defaults.keys.
|
54
|
+
usage = defaults.keys.to_usage "and/or"
|
55
55
|
|
56
56
|
fail Error, "Invalid style (#{style.inspect}) for key (#{key.inspect}). Use: #{usage}."
|
57
57
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec::Matchers.define :have_color do |color, *expected|
|
4
|
+
match do |actual|
|
5
|
+
fail ArgumentError, "First argument must be a color instance." unless color.respond_to? :decode
|
6
|
+
|
7
|
+
@decode = color.decode actual
|
8
|
+
@decode == expected
|
9
|
+
end
|
10
|
+
|
11
|
+
failure_message do |actual|
|
12
|
+
<<~MESSAGE
|
13
|
+
expected #{actual.inspect} to have color decoded as:
|
14
|
+
#{expected.map(&:inspect).join(",\n")}
|
15
|
+
|
16
|
+
but actually is:
|
17
|
+
#{@decode.map(&:inspect).join(",\n")}
|
18
|
+
MESSAGE
|
19
|
+
end
|
20
|
+
end
|
data/lib/tone.rb
CHANGED
data/tone.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "tone"
|
5
|
-
spec.version = "0.
|
5
|
+
spec.version = "0.3.0"
|
6
6
|
spec.authors = ["Brooke Kuhlmann"]
|
7
7
|
spec.email = ["brooke@alchemists.io"]
|
8
8
|
spec.homepage = "https://alchemists.io/projects/tone"
|
9
|
-
spec.summary = "A customizable ANSI text colorizer
|
9
|
+
spec.summary = "A customizable ANSI text terminal colorizer."
|
10
10
|
spec.license = "Hippocratic-2.1"
|
11
11
|
|
12
12
|
spec.metadata = {
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.cert_chain = [Gem.default_cert_path]
|
24
24
|
|
25
25
|
spec.required_ruby_version = "~> 3.2"
|
26
|
-
spec.add_dependency "refinements", "~>
|
26
|
+
spec.add_dependency "refinements", "~> 11.0"
|
27
27
|
spec.add_dependency "zeitwerk", "~> 2.6"
|
28
28
|
|
29
29
|
spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
|
36
36
|
gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2023-
|
38
|
+
date: 2023-06-13 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: refinements
|
@@ -43,14 +43,14 @@ dependencies:
|
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '11.0'
|
47
47
|
type: :runtime
|
48
48
|
prerelease: false
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '11.0'
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
55
|
name: zeitwerk
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/tone/decoder.rb
|
85
85
|
- lib/tone/encoder.rb
|
86
86
|
- lib/tone/error.rb
|
87
|
+
- lib/tone/rspec/matchers/have_color.rb
|
87
88
|
- tone.gemspec
|
88
89
|
homepage: https://alchemists.io/projects/tone
|
89
90
|
licenses:
|
@@ -111,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
112
|
- !ruby/object:Gem::Version
|
112
113
|
version: '0'
|
113
114
|
requirements: []
|
114
|
-
rubygems_version: 3.4.
|
115
|
+
rubygems_version: 3.4.14
|
115
116
|
signing_key:
|
116
117
|
specification_version: 4
|
117
|
-
summary: A customizable ANSI text colorizer
|
118
|
+
summary: A customizable ANSI text terminal colorizer.
|
118
119
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|