crayon 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b30625ac82f77101da7a8a6a9cdc5b2dbd3f5cb
4
+ data.tar.gz: e70445e3e4900fbb6f2430407493bc51b0e2b607
5
+ SHA512:
6
+ metadata.gz: 039cb34deb386ca9d73624777bc7a581bb90cf5d23eb7b6e16a3f30ae62549fea49a87e6d0ff08dbbd55b5b1134dcd3dabc416ddaa8297fc0b24baa44ae3d0cf
7
+ data.tar.gz: ca7ea84bae10363fc1e735634441dbb98c41de627bc12641e861b3fc7ce73d87778d8e73d09b3c216eedb2f5c3024276bc2fcec5424d0c632b92102f83a1e46f
data/.gitignore CHANGED
@@ -1,2 +1,2 @@
1
- bench.rb
2
- *.html
1
+ .DS_Store
2
+ /pkg
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-2
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
- source "http://rubygems.org"
2
- gem "yard"
3
- gem "rspec"
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in crayon.gemspec
4
+ gemspec
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ crayon (1.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.3.2)
11
+ rspec (3.1.0)
12
+ rspec-core (~> 3.1.0)
13
+ rspec-expectations (~> 3.1.0)
14
+ rspec-mocks (~> 3.1.0)
15
+ rspec-core (3.1.7)
16
+ rspec-support (~> 3.1.0)
17
+ rspec-expectations (3.1.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.1.0)
20
+ rspec-mocks (3.1.3)
21
+ rspec-support (~> 3.1.0)
22
+ rspec-support (3.1.2)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.6)
29
+ crayon!
30
+ rake (~> 10.0)
31
+ rspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Michael Berkowitz
1
+ Copyright (c) 2014 Michael Berkowitz
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
- # crayon
2
-
3
- ### current version : 1.1.0
1
+ # crayon 1.2.0
4
2
 
5
3
  [http://github.com/mikowitz/crayon][github]
6
4
 
@@ -10,24 +8,16 @@ A simple, flexible gem that provides an open-ended API to print colored and styl
10
8
 
11
9
  ## Installation
12
10
 
13
- Install the gemcutter gem
14
-
15
- ~$ gem install gemcutter
16
-
17
- Add gemcutter.org to your gem remote sources
11
+ Add `Crayon` to your Gemfile
18
12
 
19
- ~$ gem tumble
13
+ gem "crayon"
20
14
 
21
- Download and install this gem
15
+ Or download and install this gem
22
16
 
23
17
  ~$ gem install crayon
24
18
 
25
19
  ## Usage examples
26
20
 
27
- To include this gem in a project
28
-
29
- require 'crayon'
30
-
31
21
  The following are all methods that `Crayon` understands, and should give you an idea of what is possible.
32
22
 
33
23
  Crayon.blue("this will be printed as blue text")
@@ -41,13 +31,19 @@ You can also chain color calls without having to call `Crayon` multiple times
41
31
 
42
32
  Crayon.red("red").blue("blue").green("green")
43
33
 
34
+ ### clearing
35
+
36
+ You can call `clear` to insert plain text in the middle of formatted content
37
+
38
+ Crayon.red("red").clear("plain").green("green")
39
+
44
40
  ### case flexibility
45
41
 
46
42
  `Crayon` will also handle mixed-case method calls
47
43
 
48
44
  Crayon.ReD_ON_gREEN("It's Christmas!")
49
45
 
50
- Of course, this is no different from calling
46
+ This is no different from calling
51
47
 
52
48
  Crayon.red_on_green("It's Christmas!")
53
49
 
@@ -61,11 +57,9 @@ will look the same as
61
57
 
62
58
  Color.on_yellow_bold_blue_underline("sample text")
63
59
 
64
- Check out `test/proof.rb` and `~$ rake proof` if you don't believe me.
65
-
66
60
  ## Return values
67
61
 
68
- Crayon simply returns a formatted string
62
+ Crayon returns a formatted string
69
63
 
70
64
  Color.red("red, ").blue("and blue") #=> "\e[31mred, \e[0m\e[34mand blue\e[0m"
71
65
 
@@ -73,6 +67,6 @@ So any call to `Crayon` must be `puts` or `print`-ed in order for the content to
73
67
 
74
68
  ## Copyright
75
69
 
76
- Copyright (c) 2010 Michael Berkowitz. See LICENSE for details.
70
+ Copyright (c) 2014 Michael Berkowitz. See LICENSE.txt for details.
77
71
 
78
72
  [github]: http://github.com/mikowitz/crayon "Crayon repository"
data/Rakefile CHANGED
@@ -1,48 +1,6 @@
1
- require 'rake'
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
2
3
 
3
- begin
4
- require 'jeweler'
5
- Jeweler::Tasks.new do |gem|
6
- gem.name = "crayon"
7
- gem.summary = %Q{a new version of 'color' with a less common name.}
8
- gem.description = %Q{A simple, flexible gem that provides an open-ended API to print colored and styled output to the terminal.}
9
- gem.email = "michael.berkowitz@gmail.com"
10
- gem.homepage = "http://github.com/mikowitz/crayon"
11
- gem.authors = ["Michael Berkowitz"]
12
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
- end
14
- Jeweler::GemcutterTasks.new
15
- rescue LoadError
16
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
17
- end
4
+ RSpec::Core::RakeTask.new('spec')
18
5
 
19
- require 'spec/rake/spectask'
20
- Spec::Rake::SpecTask.new(:spec) do |spec|
21
- spec.libs << "lib" << "spec"
22
- spec.spec_files = FileList["spec/**/*_spec.rb"]
23
- end
24
-
25
- Spec::Rake::SpecTask.new(:rcov) do |spec|
26
- spec.libs << "lib" << "spec"
27
- spec.pattern = "spec/**/*_spec.rb"
28
- spec.rcov = true
29
- end
30
-
31
- task :spec => :check_dependencies
32
- task :default => :spec
33
-
34
- desc "'Proof is the bottom line for everyone' -- Paul Simon"
35
- task :proof do
36
- system "ruby test/proof.rb"
37
- end
38
-
39
- begin
40
- require 'yard'
41
- YARD::Rake::YardocTask.new do |t|
42
- t.options = ['--no-private', '-mmarkdown']
43
- end
44
- rescue LoadError
45
- task :yardoc do
46
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
47
- end
48
- end
6
+ task default: :spec
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "crayon/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "crayon"
8
+ spec.version = Crayon::VERSION
9
+ spec.authors = ["Michael Berkowitz"]
10
+ spec.email = ["michael.berkowitz@gmail.com"]
11
+ spec.summary = %q{Colored terminal output}
12
+ spec.description = %Q{A simple, flexible gem that provides an open-ended API to print colored and styled output to the terminal.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -1,6 +1,5 @@
1
- $:.unshift File.dirname(__FILE__) + "/crayon"
2
-
3
- %w{ method_parser string_builder}.each {|file| require file }
1
+ require "crayon/method_parser"
2
+ require "crayon/string_builder"
4
3
 
5
4
  module Crayon
6
5
  include Crayon::MethodParser
@@ -8,30 +7,18 @@ module Crayon
8
7
  extend self
9
8
 
10
9
  class << self
11
- # @private
12
10
  attr_accessor :foreground, :background, :formatting, :method_name, :color
13
11
  end
14
12
 
15
- # @private
16
13
  COLORS = { "black" => 0, "red" => 1, "green" => 2, "yellow" => 3, "blue" => 4, "magenta" => 5, "cyan" => 6, "white" => 7 }
17
- # @private
18
14
  FORMATS = { "bold" => 1, "underline" => 4 }
19
- # @private
20
15
  TERMINATION_STRING = "\e[0m"
21
16
 
22
17
  def method_missing(method_name, string)
23
- nullify_variables
24
18
  @method_name = method_name
25
19
  parse_method_name
26
20
  CrayonString.new(prepare_string(string) || "")
27
21
  end
28
-
29
- # @private
30
- def nullify_variables
31
- @foreground, @background, @formatting = nil, nil, []
32
- @method_name, @color = nil, nil
33
- end
34
22
  end
35
23
 
36
- require 'crayon_string'
37
-
24
+ require "crayon/crayon_string"
@@ -1,8 +1,11 @@
1
1
  class CrayonString < String
2
2
  include Crayon
3
3
 
4
+ def clear(string)
5
+ CrayonString.new(self + string)
6
+ end
7
+
4
8
  def method_missing(method_name, string)
5
- nullify_variables
6
9
  @method_name = method_name
7
10
  parse_method_name
8
11
  CrayonString.new(self + prepare_string(string))
@@ -1,32 +1,25 @@
1
1
  module Crayon
2
2
  module MethodParser
3
- ##
4
- # Converts a method name into color and formatting parameters
5
- # @private
6
3
  def parse_method_name
7
- @method_name = @method_name.to_s.downcase.split("_")
4
+ @method_name_components = @method_name.to_s.downcase.split("_")
8
5
  @background = parse_background
9
6
  @foreground = parse_foreground
10
7
  @formatting = parse_formatting
11
8
  end
12
9
 
13
- # @private
14
10
  def parse_background
15
- _idx = @method_name.index("on")
16
- return nil unless _idx
17
- @method_name.delete("on")
18
- _background = @method_name.delete_at(_idx)
19
- _background if COLORS.keys.include?(_background)
11
+ on_index = @method_name_components.index("on")
12
+ return nil unless on_index
13
+ background = @method_name_components.delete_at(on_index + 1)
14
+ background if COLORS.include?(background)
20
15
  end
21
16
 
22
- # @private
23
17
  def parse_foreground
24
- @method_name.find {|color| COLORS.keys.include?(color) }
18
+ @method_name_components.find {|color| COLORS.include?(color) }
25
19
  end
26
20
 
27
- # @private
28
21
  def parse_formatting
29
- @method_name.select {|format| FORMATS.keys.include?(format) }
22
+ @method_name_components.select {|format| FORMATS.include?(format) }
30
23
  end
31
24
  end
32
25
  end
@@ -1,39 +1,34 @@
1
1
  module Crayon
2
2
  module StringBuilder
3
- ##
4
- # Builds output string with color escape characters.
5
- # @private
6
3
  def prepare_string(string)
7
- [ prepare_foreground_color,
8
- prepare_background_color,
9
- prepare_formatting,
4
+ [ foreground_string,
5
+ background_string,
6
+ formatting_string,
10
7
  string,
11
- (TERMINATION_STRING if @foreground || @background || !@formatting.empty?)
8
+ (TERMINATION_STRING if has_color?)
12
9
  ].compact.join("")
13
10
  end
14
11
 
15
- # @private
16
- def prepare_foreground_color
17
- @color = @foreground
18
- handle_color(3)
12
+ def has_color?
13
+ @foreground || @background || @formatting.any?
19
14
  end
20
15
 
21
- # @private
22
- def prepare_background_color
23
- @color = @background
24
- handle_color(4)
16
+ def foreground_string
17
+ handle_color(3, @foreground)
25
18
  end
26
19
 
27
- # @private
28
- def prepare_formatting
20
+ def background_string
21
+ handle_color(4, @background)
22
+ end
23
+
24
+ def formatting_string
29
25
  return "" if @formatting.empty?
30
26
  @formatting.map{|format| "\e[#{FORMATS[format]}m"}.join("")
31
27
  end
32
28
 
33
- # @private
34
- def handle_color(lead)
35
- return "" unless @color
36
- "\e[#{lead}#{COLORS[@color]}m"
29
+ def handle_color(lead, color)
30
+ return "" unless color
31
+ "\e[#{lead}#{COLORS[color]}m"
37
32
  end
38
33
  end
39
34
  end
@@ -0,0 +1,3 @@
1
+ module Crayon
2
+ VERSION = "1.2.0"
3
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/helper")
1
+ require "spec_helper"
2
2
 
3
3
  def test_parse_method_name(input, *output)
4
4
  describe "for input :#{input}" do
@@ -7,40 +7,42 @@ def test_parse_method_name(input, *output)
7
7
  Crayon.parse_method_name
8
8
  @fore, @back, @form = output
9
9
  end
10
- after { [:foreground, :background, :formatting].each {|method| Crayon.send(:"#{method}=", nil) } }
11
10
  it "should return #{@fore.inspect} for foreground" do
12
- Crayon.foreground.should == @fore
11
+ expect(Crayon.foreground).to eq @fore
13
12
  end
14
13
  it "should return #{@back.inspect} for background" do
15
- Crayon.background.should == @back
14
+ expect(Crayon.background).to eq @back
16
15
  end
17
16
  it "should return #{@form.inspect} for formatting" do
18
- Crayon.formatting.should == @form
17
+ expect(Crayon.formatting).to eq @form
19
18
  end
20
19
  end
21
20
  end
22
21
 
23
22
  def test_prepare_string(expected_output, *args)
24
23
  it "should return correctly for #{args.inspect}" do
25
- Crayon.foreground = args.fetch(1) { nil }
26
- Crayon.background = args.fetch(2) { nil }
27
- Crayon.formatting = args.fetch(3) { [] }
28
- Crayon.prepare_string(args.first).should == expected_output
24
+ Crayon.foreground = args.fetch(1, nil)
25
+ Crayon.background = args.fetch(2, nil)
26
+ Crayon.formatting = args.fetch(3, [])
27
+ expect(Crayon.prepare_string(args.first)).to eq expected_output
29
28
  end
30
29
  end
31
30
 
32
31
  describe "Crayon" do
33
32
  describe "chaining color calls" do
34
33
  it "should be allowed by returning a CrayonString from method_missing" do
35
- Crayon.red("OK").should be_a CrayonString
34
+ expect(Crayon.red("OK")).to be_a CrayonString
36
35
  end
37
36
  it "should return the full chained string" do
38
- Crayon.red("OK").blue("OK").underline("OK").should == "\e[31mOK\e[0m\e[34mOK\e[0m\e[4mOK\e[0m"
37
+ expect(Crayon.red("OK").blue("OK").underline("OK")).to eq "\e[31mOK\e[0m\e[34mOK\e[0m\e[4mOK\e[0m"
38
+ end
39
+ it "should allow plain text in the middle of formatted text via .clear" do
40
+ expect(Crayon.red("OK").clear(" OK ").underline("OK")).to eq "\e[31mOK\e[0m OK \e[4mOK\e[0m"
39
41
  end
40
42
  end
41
43
  describe "method_missing" do
42
44
  describe "should call :prepare string" do
43
- before { Crayon.should_receive(:prepare_string).with("hello") }
45
+ before { expect(Crayon).to receive(:prepare_string).with("hello") }
44
46
  it "when Crayon.red is called" do
45
47
  Crayon.red("hello")
46
48
  end
@@ -1,8 +1,7 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
3
3
  require 'crayon'
4
- require 'spec'
5
- require 'spec/autorun'
4
+ require 'rspec'
6
5
 
7
- Spec::Runner.configure do |config|
6
+ RSpec.configure do |config|
8
7
  end
metadata CHANGED
@@ -1,80 +1,105 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: crayon
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 1
8
- - 0
9
- version: 1.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Michael Berkowitz
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2010-04-22 00:00:00 -04:00
18
- default_executable:
19
- dependencies: []
20
-
21
- description: A simple, flexible gem that provides an open-ended API to print colored and styled output to the terminal.
22
- email: michael.berkowitz@gmail.com
11
+ date: 2014-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A simple, flexible gem that provides an open-ended API to print colored
56
+ and styled output to the terminal.
57
+ email:
58
+ - michael.berkowitz@gmail.com
23
59
  executables: []
24
-
25
60
  extensions: []
26
-
27
- extra_rdoc_files:
28
- - LICENSE
29
- - README.html
30
- - README.md
31
- files:
32
- - .document
33
- - .gitignore
34
- - CHANGELOG.md
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".document"
64
+ - ".gitignore"
65
+ - ".travis.yml"
35
66
  - Gemfile
36
- - LICENSE
67
+ - Gemfile.lock
68
+ - LICENSE.txt
37
69
  - README.md
38
70
  - Rakefile
39
- - VERSION
71
+ - crayon.gemspec
40
72
  - lib/crayon.rb
41
73
  - lib/crayon/crayon_string.rb
42
74
  - lib/crayon/method_parser.rb
43
75
  - lib/crayon/string_builder.rb
44
- - spec/crayon_spec.rb
45
- - spec/helper.rb
46
- - spec/spec.opts
47
- - README.html
48
- has_rdoc: true
49
- homepage: http://github.com/mikowitz/crayon
50
- licenses: []
51
-
76
+ - lib/crayon/version.rb
77
+ - spec/crayon/crayon_spec.rb
78
+ - spec/spec_helper.rb
79
+ homepage: ''
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
52
83
  post_install_message:
53
- rdoc_options:
54
- - --charset=UTF-8
55
- require_paths:
84
+ rdoc_options: []
85
+ require_paths:
56
86
  - lib
57
- required_ruby_version: !ruby/object:Gem::Requirement
58
- requirements:
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
59
89
  - - ">="
60
- - !ruby/object:Gem::Version
61
- segments:
62
- - 0
63
- version: "0"
64
- required_rubygems_version: !ruby/object:Gem::Requirement
65
- requirements:
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
66
94
  - - ">="
67
- - !ruby/object:Gem::Version
68
- segments:
69
- - 0
70
- version: "0"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
71
97
  requirements: []
72
-
73
98
  rubyforge_project:
74
- rubygems_version: 1.3.6
99
+ rubygems_version: 2.2.2
75
100
  signing_key:
76
- specification_version: 3
77
- summary: a new version of 'color' with a less common name.
78
- test_files:
79
- - spec/crayon_spec.rb
80
- - spec/helper.rb
101
+ specification_version: 4
102
+ summary: Colored terminal output
103
+ test_files:
104
+ - spec/crayon/crayon_spec.rb
105
+ - spec/spec_helper.rb
@@ -1,43 +0,0 @@
1
- ### 1.1.0 : 04/22/10
2
-
3
- * Removed `puts` and `print` methods
4
-
5
- ### 1.0.3 : 04/22/10
6
-
7
- * Broke Crayon functionality out into separate modules
8
- * Added CrayonString class to allow chaining methods
9
-
10
- ### 1.0.2 : 04/21/10
11
-
12
- * Removed last references to the `newline` and `io` methods.
13
-
14
- ### 1.0.1 : 04/21/10
15
-
16
- * Adds deprecation warnings for `puts` and `print`
17
-
18
- ### 1.0.0 : 04/21/10
19
-
20
- * Fixed bug where a method name which has `on_` followed by anything not an allowed color would return an underlined string.
21
- * Set `method_missing` to return `Crayon` so color methods can be chained.
22
- * Crayon can handle mixed-case method names.
23
-
24
- ### 0.0.5 : 04/21/10
25
-
26
- * Moved functionality from passing variables between methods to using instance variables.
27
-
28
- ### 0.0.4 : 04/21/10
29
-
30
- * Adds documentation and hides most helper methods from public documentation.
31
-
32
- ### 0.0.3 : 04/21/10
33
-
34
- * Switches documentation from RDoc to Markdown
35
- * Moves gem dependencies into Gemfile
36
- * Switches tests over to RSpec
37
-
38
-
39
- ### 0.0.2 : 03/15/10
40
-
41
- * Swtiches testing to Tinytest
42
- * Adds basic functionality
43
- * Adds sample output file and rake task
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.1.0
@@ -1,2 +0,0 @@
1
- -fs
2
- --color