crayon 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,10 @@
1
+ # VIM
2
+ *.swp
3
+
4
+ ## PROJECT::GENERAL
5
+ coverage
6
+ diff
7
+ rdoc
8
+ pkg
9
+
10
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Michael Berkowitz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ = crayon
2
+
3
+ === current version : 0.0.2
4
+
5
+ http://github.com/mikowitz/crayon
6
+
7
+ == Description
8
+
9
+ A simple, flexible gem that provides an open-ended API to print colored and styled output to the terminal.
10
+
11
+ == Installation
12
+
13
+ Install the gemcutter gem
14
+ ~$ gem install gemcutter
15
+ Add gemcutter.org to your gem remote sources
16
+ ~$ gem tumble
17
+ Download and install this gem
18
+ ~$ gem install crayon
19
+
20
+ == Usage examples
21
+
22
+ To include this gem in a project
23
+ require 'crayon'
24
+
25
+ The following are all methods that <code>Crayon</code> understands, and should give you an idea of what is possible.
26
+
27
+ Crayon.blue("this will be printed as blue text")
28
+ Crayon.on_red("this will be printed on a red background")
29
+ Crayon.bold("this will be bold")
30
+ Crayon.underline_blue_on_yellow("this will be underlined blue text on a yellow background")
31
+
32
+ The order of elements in the method name is also unimportant. For example
33
+
34
+ Color.bold_underline_blue_on_yellow("sample text")
35
+
36
+ will look the same as
37
+
38
+ Color.on_yellow_bold_blue_underline("sample text")
39
+
40
+ Check out <code>test/proof.rb"</code> and <code>`rake proof`</code> if you don't believe me.
41
+
42
+ == Copyright
43
+
44
+ Copyright (c) 2010 Michael Berkowitz. See LICENSE for details.
45
+
@@ -0,0 +1,78 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "crayon"
8
+ gem.summary = %Q{a new version of 'color' with a less common name.}
9
+ gem.description = %Q{A simple, flexible gem that provides an open-ended API to print colored and styled output to the terminal.}
10
+ gem.email = "michael.berkowitz@gmail.com"
11
+ gem.homepage = "http://github.com/mikowitz/crayon"
12
+ gem.authors = ["Michael Berkowitz"]
13
+ gem.add_development_dependency "tinytest", ">= 0"
14
+ gem.add_development_dependency "yard", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ begin
45
+ require 'reek/adapters/rake_task'
46
+ Reek::RakeTask.new do |t|
47
+ t.fail_on_error = true
48
+ t.verbose = false
49
+ t.source_files = 'lib/**/*.rb'
50
+ end
51
+ rescue LoadError
52
+ task :reek do
53
+ abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
54
+ end
55
+ end
56
+
57
+ begin
58
+ require 'roodi'
59
+ require 'roodi_task'
60
+ RoodiTask.new do |t|
61
+ t.verbose = false
62
+ end
63
+ rescue LoadError
64
+ task :roodi do
65
+ abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
66
+ end
67
+ end
68
+
69
+ task :default => :test
70
+
71
+ begin
72
+ require 'yard'
73
+ YARD::Rake::YardocTask.new
74
+ rescue LoadError
75
+ task :yardoc do
76
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
77
+ end
78
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,75 @@
1
+ module Crayon
2
+ extend self
3
+
4
+ @@newline = true
5
+
6
+ COLORS = {
7
+ "black" => 0,
8
+ "red" => 1,
9
+ "green" => 2,
10
+ "yellow" => 3,
11
+ "blue" => 4,
12
+ "magenta" => 5,
13
+ "cyan" => 6,
14
+ "white" => 7
15
+ }
16
+
17
+ FORMATS = {
18
+ "bold" => 1,
19
+ "underline" => 4
20
+ }
21
+
22
+ TERMINATION_STRING = "\e[0m"
23
+
24
+ def newline?; @@newline; end
25
+ def io; $stderr; end
26
+
27
+ def self.print; @@newline = false; return Crayon; end
28
+
29
+ def self.puts; @@newline = true; return Crayon; end
30
+
31
+ def method_missing(method_name, string)
32
+ io.print prepare_string(string, *parse_method_name(method_name))
33
+ io.flush
34
+ end
35
+
36
+ def prepare_string(string, foreground=nil, background=nil, formatting=[])
37
+ [
38
+ prepare_foreground_color(foreground),
39
+ prepare_background_color(background),
40
+ prepare_formatting(*formatting),
41
+ string,
42
+ TERMINATION_STRING,
43
+ (newline? ? "\n" : "")
44
+ ].join("")
45
+ end
46
+
47
+ def parse_method_name(method_name)
48
+ _name = method_name.to_s.split("_")
49
+ if _idx = _name.index("on")
50
+ _name.delete("on")
51
+ _background_color = _name.delete_at(_idx)
52
+ end
53
+ _foreground_color = _name.find {|color| COLORS.keys.include?(color) }
54
+ _formatting = _name.select{|format| FORMATS.keys.include?(format) }
55
+ [_foreground_color, _background_color, _formatting]
56
+ end
57
+
58
+ def prepare_foreground_color(color=nil)
59
+ handle_color(3, color)
60
+ end
61
+
62
+ def prepare_background_color(color=nil)
63
+ handle_color(4, color)
64
+ end
65
+
66
+ def prepare_formatting(*formats)
67
+ return "" if formats.empty?
68
+ formats.map{|f| "\e[#{FORMATS[f]}m"}.join("")
69
+ end
70
+
71
+ def handle_color(lead, color=nil)
72
+ return "" unless color
73
+ "\e[#{lead}#{COLORS[color]}m"
74
+ end
75
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'tinytest'
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ require 'crayon'
7
+
@@ -0,0 +1,27 @@
1
+ require 'helper'
2
+
3
+ include TinyTest
4
+
5
+ is { Crayon.newline? } # by default?
6
+
7
+ is {
8
+ Crayon.print
9
+ not Crayon.newline?
10
+ }
11
+
12
+ is {
13
+ Crayon.puts
14
+ Crayon.newline?
15
+ }
16
+
17
+ # Crayon.parse_method_name
18
+ does { Crayon.parse_method_name(:red) == ["red", nil, []] }
19
+ does { Crayon.parse_method_name(:on_red) == [nil, "red", []] }
20
+ does { Crayon.parse_method_name(:bold) == [nil, nil, ["bold"]] }
21
+
22
+ does { Crayon.parse_method_name(:blue_on_green) == ["blue", "green", []] }
23
+ does { Crayon.parse_method_name(:bold_cyan_on_magenta) == ["cyan", "magenta", ["bold"]] }
24
+
25
+ does { Crayon.parse_method_name(:red_green) == ["red", nil, []] }
26
+ does { Crayon.parse_method_name(:red_bold_underline) == ["red", nil, ["bold", "underline"]] }
27
+ does { Crayon.parse_method_name(:underline_on_green_bold) == [nil, "green", ["underline", "bold"]] }
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crayon
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Michael Berkowitz
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-15 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: tinytest
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: yard
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :development
43
+ version_requirements: *id002
44
+ description: A simple, flexible gem that provides an open-ended API to print colored and styled output to the terminal.
45
+ email: michael.berkowitz@gmail.com
46
+ executables: []
47
+
48
+ extensions: []
49
+
50
+ extra_rdoc_files:
51
+ - LICENSE
52
+ - README.rdoc
53
+ files:
54
+ - .document
55
+ - .gitignore
56
+ - LICENSE
57
+ - README.rdoc
58
+ - Rakefile
59
+ - VERSION
60
+ - lib/crayon.rb
61
+ - test/helper.rb
62
+ - test/test_crayon.rb
63
+ has_rdoc: true
64
+ homepage: http://github.com/mikowitz/crayon
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --charset=UTF-8
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.6
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: a new version of 'color' with a less common name.
93
+ test_files:
94
+ - test/helper.rb
95
+ - test/test_crayon.rb