pastel 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/README.md +7 -5
- data/lib/pastel/detached.rb +14 -0
- data/lib/pastel/version.rb +1 -1
- data/spec/unit/detach_spec.rb +20 -0
- metadata +24 -25
- checksums.yaml +0 -7
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -124,8 +124,8 @@ You can also predefine needed styles and reuse them:
|
|
124
124
|
error = pastel.red.on_bold.detach
|
125
125
|
warning = pastel.yellow.detach
|
126
126
|
|
127
|
-
puts error('Error!')
|
128
|
-
puts warning('Warning')
|
127
|
+
puts error.('Error!')
|
128
|
+
puts warning.('Warning')
|
129
129
|
```
|
130
130
|
|
131
131
|
## 2 Interface
|
@@ -154,12 +154,14 @@ This method will be useful in situations where colors are provided as a list of
|
|
154
154
|
|
155
155
|
### 2.3 Detach
|
156
156
|
|
157
|
-
The `detach` method allows to keep all the
|
157
|
+
The `detach` method allows to keep all the associated colors with the detached instance for later reference. This method is useful when detached colors are being reused frequently and thus shorthand version is preferred. The detached object can be invoked using `call` method or it's shorthand `.()`, as well as array like access `[]`. For example, the following are equivalent examples of detaching colors:
|
158
158
|
|
159
159
|
```ruby
|
160
160
|
notice = pastel.blue.bold.detach
|
161
|
-
|
162
|
-
|
161
|
+
|
162
|
+
notice.call('Unicorns running')
|
163
|
+
notice.('Unicorns running')
|
164
|
+
notice['Unicorns running']
|
163
165
|
```
|
164
166
|
|
165
167
|
### 2.4 Strip
|
data/lib/pastel/detached.rb
CHANGED
@@ -5,6 +5,14 @@ module Pastel
|
|
5
5
|
class Detached
|
6
6
|
include Equatable
|
7
7
|
|
8
|
+
# Initialize a detached object
|
9
|
+
#
|
10
|
+
# @param [Pastel::Color] color
|
11
|
+
# the color instance
|
12
|
+
# @param [Array[Symbol]] styles
|
13
|
+
# the styles to be applied
|
14
|
+
#
|
15
|
+
# @api private
|
8
16
|
def initialize(color, *styles)
|
9
17
|
@color = color
|
10
18
|
@styles = styles.dup
|
@@ -25,6 +33,12 @@ module Pastel
|
|
25
33
|
value = args.join
|
26
34
|
@color.decorate(value, *styles)
|
27
35
|
end
|
36
|
+
alias_method :[], :call
|
37
|
+
|
38
|
+
# @api public
|
39
|
+
def to_proc
|
40
|
+
self
|
41
|
+
end
|
28
42
|
|
29
43
|
private
|
30
44
|
|
data/lib/pastel/version.rb
CHANGED
data/spec/unit/detach_spec.rb
CHANGED
@@ -6,12 +6,32 @@ RSpec.describe Pastel, '.detach' do
|
|
6
6
|
|
7
7
|
subject(:pastel) { described_class.new(enabled: true) }
|
8
8
|
|
9
|
+
it "creates detached instance" do
|
10
|
+
error = pastel.red.bold.detach
|
11
|
+
expect(error).to be_a(Pastel::Detached)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "ensures instance is immutable" do
|
15
|
+
error = pastel.red.detach
|
16
|
+
expect(error.frozen?).to be(true)
|
17
|
+
end
|
18
|
+
|
9
19
|
it "detaches colors combination" do
|
10
20
|
error = pastel.red.bold.detach
|
11
21
|
expect(error.call('unicorn')).to eq("\e[31;1municorn\e[0m")
|
12
22
|
expect(error.call('error')).to eq("\e[31;1merror\e[0m")
|
13
23
|
end
|
14
24
|
|
25
|
+
it "allows array like access" do
|
26
|
+
error = pastel.red.bold.detach
|
27
|
+
expect(error['unicorn']).to eq("\e[31;1municorn\e[0m")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "allows alternative call invocation" do
|
31
|
+
error = pastel.red.bold.detach
|
32
|
+
expect(error.('unicorn')).to eq("\e[31;1municorn\e[0m")
|
33
|
+
end
|
34
|
+
|
15
35
|
it "calls detached colors with no arguments" do
|
16
36
|
warning = pastel.yellow.detach
|
17
37
|
expect(warning.call('')).to eq('')
|
metadata
CHANGED
@@ -1,57 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pastel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Piotr Murach
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
12
|
+
date: 2015-09-18 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: equatable
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2161192500 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '0.5'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
|
-
version_requirements:
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.5'
|
24
|
+
version_requirements: *2161192500
|
27
25
|
- !ruby/object:Gem::Dependency
|
28
26
|
name: tty-screen
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &2161206200 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
30
29
|
requirements:
|
31
30
|
- - ~>
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: '0.4'
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
|
-
version_requirements:
|
37
|
-
requirements:
|
38
|
-
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.4'
|
35
|
+
version_requirements: *2161206200
|
41
36
|
- !ruby/object:Gem::Dependency
|
42
37
|
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &2161203120 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
44
40
|
requirements:
|
45
41
|
- - ~>
|
46
42
|
- !ruby/object:Gem::Version
|
47
43
|
version: '1.6'
|
48
44
|
type: :development
|
49
45
|
prerelease: false
|
50
|
-
version_requirements:
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.6'
|
46
|
+
version_requirements: *2161203120
|
55
47
|
description: Terminal strings styling with intuitive and clean API.
|
56
48
|
email:
|
57
49
|
- ''
|
@@ -107,26 +99,33 @@ files:
|
|
107
99
|
homepage: https://github.com/peter-murach/pastel
|
108
100
|
licenses:
|
109
101
|
- MIT
|
110
|
-
metadata: {}
|
111
102
|
post_install_message:
|
112
103
|
rdoc_options: []
|
113
104
|
require_paths:
|
114
105
|
- lib
|
115
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
116
108
|
requirements:
|
117
|
-
- - '>='
|
109
|
+
- - ! '>='
|
118
110
|
- !ruby/object:Gem::Version
|
119
111
|
version: '0'
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
hash: -249921942179958499
|
120
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
121
117
|
requirements:
|
122
|
-
- - '>='
|
118
|
+
- - ! '>='
|
123
119
|
- !ruby/object:Gem::Version
|
124
120
|
version: '0'
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
hash: -249921942179958499
|
125
124
|
requirements: []
|
126
125
|
rubyforge_project:
|
127
|
-
rubygems_version:
|
126
|
+
rubygems_version: 1.8.10
|
128
127
|
signing_key:
|
129
|
-
specification_version:
|
128
|
+
specification_version: 3
|
130
129
|
summary: Terminal strings styling with intuitive and clean API.
|
131
130
|
test_files:
|
132
131
|
- spec/spec_helper.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: ad29856f8ce21205b25f4318d1f26833d14ef771
|
4
|
-
data.tar.gz: efeb5f5eb350302edb488269972623ba7e92bfaa
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 35ee51a33ca2d5dd17d187304ae98e447cb91fbf2e0df607bb4cc13aa2b23eb7bbe0ceeec6c3823c0b588b4e753a23e422f0342f563cfb403ce7c6e1d75dd72e
|
7
|
-
data.tar.gz: 389f85a431b62154d914a42f68ed13526ef4c172b1c4da2ab2123cedd932e349b2aa9e223948349ad4145c504df94f97191027acef23f7fdf868d6bdd25c91cd
|