pastel 0.5.1 → 0.5.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f489baf63bb3422b41a6dff231f1bd59556a1c5d
4
+ data.tar.gz: 290539d1c3890f153db3d2b73b2722ef6d8bdaa8
5
+ SHA512:
6
+ metadata.gz: 77918f9fa7ab61f765cd8b2c09ae54a07726c46fb65c8e70dfa4436ede42f42547b66ec061e38cf424ea27329c49369c7621e84f8477747121e8de9523e8137e
7
+ data.tar.gz: bbd817e0ae0a384a2f53568544d4abba97c9f1dcb17b92e4d5956f31109d3ff735348f5042c719790d6416a0e8bfdb36c170d1c95cbb395e93f62f47bc4616cd
data/.travis.yml CHANGED
@@ -12,13 +12,12 @@ matrix:
12
12
  - rvm: jruby-19mode
13
13
  - rvm: jruby-20mode
14
14
  - rvm: jruby-21mode
15
+ - rvm: jruby-9000
15
16
  - rvm: jruby-head
16
17
  - rvm: rbx-2
17
18
  allow_failures:
18
19
  - rvm: ruby-head
19
20
  - rvm: jruby-head
20
- - rvm: jruby-20mode
21
- - rvm: jruby-21mode
22
21
  fast_finish: true
23
22
  branches:
24
23
  only: master
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.5.2 (Nov 27, 2015)
2
+
3
+ * Change Color#decorate to accept non-string values and immediately return
4
+
1
5
  0.5.1 (Sept 18, 2015)
2
6
 
3
7
  * Add ability to call detached instance with array access
data/Gemfile CHANGED
@@ -4,13 +4,13 @@ gemspec
4
4
 
5
5
  group :development do
6
6
  gem 'rake', '~> 10.4.2'
7
- gem 'rspec', '~> 3.3.0'
7
+ gem 'rspec', '~> 3.4.0'
8
8
  gem 'yard', '~> 0.8.7'
9
9
  gem 'benchmark-ips', '~> 2.0.0'
10
10
  end
11
11
 
12
12
  group :metrics do
13
- gem 'coveralls', '~> 0.8.2'
13
+ gem 'coveralls', '~> 0.8.9'
14
14
  gem 'simplecov', '~> 0.10.0'
15
15
  gem 'yardstick', '~> 0.9.9'
16
16
  end
data/README.md CHANGED
@@ -69,9 +69,11 @@ Or install it yourself as:
69
69
  ```ruby
70
70
  pastel = Pastel.new
71
71
 
72
- pastel.red('Unicorns!')
72
+ puts pastel.red('Unicorns!')
73
73
  ```
74
74
 
75
+ **Pastel** doesn't print the colored string out, just returns it, you'll have to print it yourself.
76
+
75
77
  You can compose multiple styles through chainable API:
76
78
 
77
79
  ```ruby
@@ -121,7 +123,7 @@ pastel = Pastel.new(eachline: "\n")
121
123
  You can also predefine needed styles and reuse them:
122
124
 
123
125
  ```ruby
124
- error = pastel.red.on_bold.detach
126
+ error = pastel.red.bold.detach
125
127
  warning = pastel.yellow.detach
126
128
 
127
129
  puts error.('Error!')
@@ -209,7 +211,7 @@ In cases when the color support is not provided no styling will be applied to th
209
211
 
210
212
  ```ruby
211
213
  pastel = Pastel.new(enabled: true)
212
- pastel.enabled? # => false
214
+ pastel.enabled? # => true
213
215
  ```
214
216
 
215
217
  ### 2.9 Eachline
data/lib/pastel/color.rb CHANGED
@@ -8,7 +8,9 @@ module Pastel
8
8
 
9
9
  ALIASES = {}
10
10
 
11
- ANSI_REGEX = /(\[)?\033(\[)?[:;?\d]*[\dA-Za-z](\])?/.freeze
11
+ ANSI_REGEX = /(\[)?\033(\[)?[:;?\d]*[\dA-Za-z](\])?/o.freeze
12
+
13
+ BLANK_REGEX = /\A[[:space:]]*\z/o.freeze
12
14
 
13
15
  attr_reader :enabled
14
16
  alias_method :enabled?, :enabled
@@ -19,7 +21,7 @@ module Pastel
19
21
  #
20
22
  # @api public
21
23
  def initialize(options = {})
22
- @enabled = options.fetch(:enabled) { TTY::Screen.color? }
24
+ @enabled = options.fetch(:enabled) { TTY::Screen.color? }
23
25
  @eachline = options.fetch(:eachline) { false }
24
26
  freeze
25
27
  end
@@ -47,7 +49,7 @@ module Pastel
47
49
  #
48
50
  # @api public
49
51
  def decorate(string, *colors)
50
- return string if string.empty? || !enabled
52
+ return string if blank?(string) || !enabled
51
53
 
52
54
  ansi_colors = lookup(*colors)
53
55
  ansi_string = wrap_eachline(string, ansi_colors)
@@ -246,6 +248,17 @@ module Pastel
246
248
 
247
249
  private
248
250
 
251
+ # Check if value contains anything to style
252
+ #
253
+ # @return [Boolean]
254
+ #
255
+ # @api private
256
+ def blank?(value)
257
+ value.nil? ||
258
+ value.respond_to?(:empty?) && value.empty? ||
259
+ BLANK_REGEX =~ value
260
+ end
261
+
249
262
  # @api private
250
263
  def validate(*colors)
251
264
  return if valid?(*colors)
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Pastel
4
- VERSION = "0.5.1"
4
+ VERSION = "0.5.2"
5
5
  end
@@ -58,4 +58,16 @@ RSpec.describe Pastel::Color, '.decorate' do
58
58
  color.decorate(string, :crimson)
59
59
  }.to raise_error(Pastel::InvalidAttributeNameError)
60
60
  end
61
+
62
+ it "doesn't decorate non-string instance" do
63
+ expect(color.decorate({}, :red)).to eq({})
64
+ end
65
+
66
+ it "doesn't decorate nil" do
67
+ expect(color.decorate(nil, :red)).to eq(nil)
68
+ end
69
+
70
+ it "doesn't decorate empty string" do
71
+ expect(color.decorate(" ", :red)).to eq(" ")
72
+ end
61
73
  end
metadata CHANGED
@@ -1,49 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pastel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
5
- prerelease:
4
+ version: 0.5.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Piotr Murach
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-09-18 00:00:00.000000000 Z
11
+ date: 2015-11-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: equatable
16
- requirement: &2161192500 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0.5'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *2161192500
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: tty-screen
27
- requirement: &2161206200 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ~>
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0.4'
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *2161206200
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: bundler
38
- requirement: &2161203120 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
45
  - - ~>
42
46
  - !ruby/object:Gem::Version
43
47
  version: '1.6'
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *2161203120
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
47
55
  description: Terminal strings styling with intuitive and clean API.
48
56
  email:
49
57
  - ''
@@ -99,33 +107,26 @@ files:
99
107
  homepage: https://github.com/peter-murach/pastel
100
108
  licenses:
101
109
  - MIT
110
+ metadata: {}
102
111
  post_install_message:
103
112
  rdoc_options: []
104
113
  require_paths:
105
114
  - lib
106
115
  required_ruby_version: !ruby/object:Gem::Requirement
107
- none: false
108
116
  requirements:
109
- - - ! '>='
117
+ - - '>='
110
118
  - !ruby/object:Gem::Version
111
119
  version: '0'
112
- segments:
113
- - 0
114
- hash: -249921942179958499
115
120
  required_rubygems_version: !ruby/object:Gem::Requirement
116
- none: false
117
121
  requirements:
118
- - - ! '>='
122
+ - - '>='
119
123
  - !ruby/object:Gem::Version
120
124
  version: '0'
121
- segments:
122
- - 0
123
- hash: -249921942179958499
124
125
  requirements: []
125
126
  rubyforge_project:
126
- rubygems_version: 1.8.10
127
+ rubygems_version: 2.0.3
127
128
  signing_key:
128
- specification_version: 3
129
+ specification_version: 4
129
130
  summary: Terminal strings styling with intuitive and clean API.
130
131
  test_files:
131
132
  - spec/spec_helper.rb