colorator 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Parker Moore
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # colorator
2
+
3
+ Colorize your text for the terminal
4
+
5
+ ## Example
6
+
7
+ ```ruby
8
+ "this string".red
9
+ # => \e[31mthis string\e[0m
10
+ "my string".blue
11
+ # => \e[34mthis string\e[0m
12
+ # etc...
13
+ ```
14
+
15
+ ## Supported Colors
16
+
17
+ - black
18
+ - red
19
+ - green
20
+ - yellow
21
+ - blue
22
+ - magenta
23
+ - cyan
24
+ - white
25
+ - bold
26
+
27
+ ## Why
28
+
29
+ There are a bunch of gems that provide functionality like this, but none have
30
+ as simple an API as this. Just call `"string".color` and your text will be
31
+ colorized.
32
+
33
+ ## License
34
+
35
+ MIT. Written as a single Ruby file by Brandon Mathis, converted into a gem by
36
+ Parker Moore.
@@ -0,0 +1,146 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ task :default => :spec
47
+
48
+ require 'rspec/core/rake_task'
49
+ RSpec::Core::RakeTask.new(:spec)
50
+
51
+ desc "Generate RCov test coverage and open in your browser"
52
+ task :coverage do
53
+ require 'rcov'
54
+ sh "rm -fr coverage"
55
+ sh "rcov test/test_*.rb"
56
+ sh "open coverage/index.html"
57
+ end
58
+
59
+ require 'rdoc/task'
60
+ Rake::RDocTask.new do |rdoc|
61
+ rdoc.rdoc_dir = 'rdoc'
62
+ rdoc.title = "#{name} #{version}"
63
+ rdoc.rdoc_files.include('README*')
64
+ rdoc.rdoc_files.include('lib/**/*.rb')
65
+ end
66
+
67
+ desc "Open an irb session preloaded with this library"
68
+ task :console do
69
+ sh "irb -rubygems -r ./lib/#{name}.rb"
70
+ end
71
+
72
+ #############################################################################
73
+ #
74
+ # Custom tasks (add your own tasks here)
75
+ #
76
+ #############################################################################
77
+
78
+
79
+
80
+ #############################################################################
81
+ #
82
+ # Packaging tasks
83
+ #
84
+ #############################################################################
85
+
86
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
87
+ task :release => :build do
88
+ unless `git branch` =~ /^\* master$/
89
+ puts "You must be on the master branch to release!"
90
+ exit!
91
+ end
92
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
93
+ sh "git tag v#{version}"
94
+ sh "git push origin master"
95
+ sh "git push origin v#{version}"
96
+ sh "gem push pkg/#{name}-#{version}.gem"
97
+ end
98
+
99
+ desc "Build #{gem_file} into the pkg directory"
100
+ task :build => :gemspec do
101
+ sh "mkdir -p pkg"
102
+ sh "gem build #{gemspec_file}"
103
+ sh "mv #{gem_file} pkg"
104
+ end
105
+
106
+ desc "Generate #{gemspec_file}"
107
+ task :gemspec => :validate do
108
+ # read spec file and split out manifest section
109
+ spec = File.read(gemspec_file)
110
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
111
+
112
+ # replace name version and date
113
+ replace_header(head, :name)
114
+ replace_header(head, :version)
115
+ replace_header(head, :date)
116
+ #comment this out if your rubyforge_project has a different name
117
+ replace_header(head, :rubyforge_project)
118
+
119
+ # determine file list from git ls-files
120
+ files = `git ls-files`.
121
+ split("\n").
122
+ sort.
123
+ reject { |file| file =~ /^\./ }.
124
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
125
+ map { |file| " #{file}" }.
126
+ join("\n")
127
+
128
+ # piece file back together and write
129
+ manifest = " s.files = %w[\n#{files}\n ]\n"
130
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
131
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
132
+ puts "Updated #{gemspec_file}"
133
+ end
134
+
135
+ desc "Validate #{gemspec_file}"
136
+ task :validate do
137
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
138
+ unless libfiles.empty?
139
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
140
+ exit!
141
+ end
142
+ unless Dir['VERSION*'].empty?
143
+ puts "A `VERSION` file at root level violates Gem best practices."
144
+ exit!
145
+ end
146
+ end
@@ -0,0 +1,66 @@
1
+ ## This is the rakegem gemspec template. Make sure you read and understand
2
+ ## all of the comments. Some sections require modification, and others can
3
+ ## be deleted if you don't need them. Once you understand the contents of
4
+ ## this file, feel free to delete any comments that begin with two hash marks.
5
+ ## You can find comprehensive Gem::Specification documentation, at
6
+ ## http://docs.rubygems.org/read/chapter/20
7
+ Gem::Specification.new do |s|
8
+ s.specification_version = 2 if s.respond_to? :specification_version=
9
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.rubygems_version = '1.3.5'
11
+
12
+ ## Leave these as is they will be modified for you by the rake gemspec task.
13
+ ## If your rubyforge_project name is different, then edit it and comment out
14
+ ## the sub! line in the Rakefile
15
+ s.name = 'colorator'
16
+ s.version = '0.1'
17
+ s.date = '2013-04-13'
18
+ s.license = 'MIT'
19
+
20
+ ## Make sure your summary is short. The description may be as long
21
+ ## as you like.
22
+ s.summary = "String core extensions for terminal coloring."
23
+ s.description = "Colorize your text in the terminal."
24
+
25
+ ## List the primary authors. If there are a bunch of authors, it's probably
26
+ ## better to set the email to an email list or something. If you don't have
27
+ ## a custom homepage, consider using your GitHub URL or the like.
28
+ s.authors = ["Parker Moore", "Brandon Mathis"]
29
+ s.email = ["parkrmoore@gmail.com", "brandon@imathis.com"]
30
+ s.homepage = 'https://github.com/octopress/colorator'
31
+
32
+ ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
33
+ ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
34
+ s.require_paths = %w[lib]
35
+
36
+ ## Specify any RDoc options here. You'll want to add your README and
37
+ ## LICENSE files to the extra_rdoc_files list.
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.extra_rdoc_files = %w[README.markdown LICENSE]
40
+
41
+ ## List your development dependencies here. Development dependencies are
42
+ ## those that are only needed during development
43
+ s.add_development_dependency('rake', '~> 10.0')
44
+ s.add_development_dependency('rspec', '~> 2.13.0')
45
+
46
+ ## Leave this section as-is. It will be automatically generated from the
47
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
48
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
49
+ # = MANIFEST =
50
+ s.files = %w[
51
+ Gemfile
52
+ LICENSE
53
+ README.markdown
54
+ Rakefile
55
+ colorator.gemspec
56
+ lib/colorator.rb
57
+ lib/colorator/core_ext.rb
58
+ spec/colorator/core_ext_spec.rb
59
+ spec/spec_helper.rb
60
+ ]
61
+ # = MANIFEST =
62
+
63
+ ## Test files will be grabbed from the file list. Make sure the path glob
64
+ ## matches what you actually use.
65
+ s.test_files = s.files.select { |path| path =~ /^spec\/.*_spec\.rb/ }
66
+ end
@@ -0,0 +1,18 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ module Colorator
4
+ VERSION = "0.1"
5
+ ANSI_COLORS = {
6
+ :black => 30,
7
+ :red => 31,
8
+ :green => 32,
9
+ :yellow => 33,
10
+ :blue => 34,
11
+ :magenta => 35,
12
+ :cyan => 36,
13
+ :white => 37,
14
+ :bold => 1
15
+ }
16
+ end
17
+
18
+ require "colorator/core_ext"
@@ -0,0 +1,10 @@
1
+ class String
2
+ # colorization
3
+ def colorize(color_code)
4
+ "\e[#{color_code}m#{self}\e[0m"
5
+ end
6
+
7
+ Colorator::ANSI_COLORS.each do |key, value|
8
+ define_method(key) { colorize(value) }
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe String do
4
+ let(:string) { "i am a test string, y'know?" }
5
+
6
+ it "contains all the methods from Colorator::ANSI_COLORS" do
7
+ Colorator::ANSI_COLORS.keys.each do |color|
8
+ string.methods.should include(color)
9
+ end
10
+ end
11
+
12
+ it "colors the text properly" do
13
+ Colorator::ANSI_COLORS.each do |color, code|
14
+ string.send(color.to_sym).should include(code.to_s)
15
+ string.send(color.to_sym).should eq("\e[#{code}m#{string}\e[0m")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib })
2
+
3
+ require 'rspec/autorun'
4
+ require 'colorator'
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.order = 'random'
9
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colorator
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Parker Moore
9
+ - Brandon Mathis
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-04-13 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '10.0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '10.0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rspec
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 2.13.0
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 2.13.0
47
+ description: Colorize your text in the terminal.
48
+ email:
49
+ - parkrmoore@gmail.com
50
+ - brandon@imathis.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files:
54
+ - README.markdown
55
+ - LICENSE
56
+ files:
57
+ - Gemfile
58
+ - LICENSE
59
+ - README.markdown
60
+ - Rakefile
61
+ - colorator.gemspec
62
+ - lib/colorator.rb
63
+ - lib/colorator/core_ext.rb
64
+ - spec/colorator/core_ext_spec.rb
65
+ - spec/spec_helper.rb
66
+ homepage: https://github.com/octopress/colorator
67
+ licenses:
68
+ - MIT
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.23
89
+ signing_key:
90
+ specification_version: 2
91
+ summary: String core extensions for terminal coloring.
92
+ test_files:
93
+ - spec/colorator/core_ext_spec.rb