apohllo-colors 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,79 @@
1
+ = colors
2
+
3
+ * http://github.com/apohllo/colors
4
+
5
+ == DESCRIPTION:
6
+
7
+ Colorful string in Ruby!
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * whole/partial string colorization is possible
12
+
13
+ == SYNOPSIS:
14
+
15
+ Colors is an extension for Ruby String class, which provides colorful strings.
16
+ It uses ANSI control sequences, thus is available in any ANSI-compliant
17
+ terminal.
18
+
19
+ == INSTALL:
20
+
21
+ You need RubyGems v. 1.2
22
+
23
+ * gem -v
24
+ * 1.2.0 #=> ok
25
+
26
+ You need the github.com repository to be added to your sources list:
27
+
28
+ * gem sources -a http://gems.github.com
29
+
30
+ Then you can type:
31
+
32
+ * sudo gem install apohllo-colors
33
+
34
+ == BASIC USAGE:
35
+
36
+ Require the gem:
37
+
38
+ require 'colors'
39
+
40
+ Get the string bold with +hl+:
41
+
42
+ "abc".hl #=> *abc*
43
+
44
+ Get the string colored:
45
+
46
+ "abc".hl(:red) #=> *abc* (it is red, no kidding :)
47
+
48
+ Get some words within the string colored (only whole words are colored):
49
+
50
+ "abc abcde abc".hl(:blue, "abc") #=> *abc* abcde *abc*
51
+
52
+ == LICENSE:
53
+
54
+ (The MIT License)
55
+
56
+ Copyright (c) 2009 Aleksander Pohl
57
+
58
+ Permission is hereby granted, free of charge, to any person obtaining
59
+ a copy of this software and associated documentation files (the
60
+ 'Software'), to deal in the Software without restriction, including
61
+ without limitation the rights to use, copy, modify, merge, publish,
62
+ distribute, sublicense, and/or sell copies of the Software, and to
63
+ permit persons to whom the Software is furnished to do so, subject to
64
+ the following conditions:
65
+
66
+ The above copyright notice and this permission notice shall be
67
+ included in all copies or substantial portions of the Software.
68
+
69
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
70
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
71
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
72
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
73
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
74
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
75
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
76
+
77
+ == FEEDBACK
78
+
79
+ * mailto:apohllo@o2.pl
@@ -0,0 +1,23 @@
1
+ task :default => [:install]
2
+
3
+ $gem_name = "colors"
4
+
5
+ desc "Build the gem"
6
+ task :build do
7
+ sh "gem build #$gem_name.gemspec"
8
+ end
9
+
10
+ desc "Install the library at local machnie"
11
+ task :install => :build do
12
+ sh "sudo gem install #$gem_name -l"
13
+ end
14
+
15
+ desc "Uninstall the library from local machnie"
16
+ task :uninstall do
17
+ sh "sudo gem uninstall #$gem_name"
18
+ end
19
+
20
+ desc "Clean"
21
+ task :clean do
22
+ sh "rm #$gem_name*.gem"
23
+ end
@@ -0,0 +1,9 @@
1
+ 0.0.4
2
+ - fix: missing changelog.txt added
3
+ 0.0.3
4
+ - more documentation
5
+ - constant name changed, when releasing to public
6
+ 0.0.2
7
+ - character trancoding calls removed
8
+ 0.0.1
9
+ - initial implementation with additional calls to_utf, to_iso
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "colors"
3
+ s.version = "0.0.4"
4
+ s.date = "2009-07-15"
5
+ s.summary = "Ruby String extesion for colored strings"
6
+ s.email = "apohllo@o2.pl"
7
+ s.homepage = "http://apohllo.pl"
8
+ s.description = "Extensions for String highliting"
9
+ s.has_rdoc = false
10
+ s.authors = ['Aleksander Pohl']
11
+ s.files = ["Rakefile",
12
+ "colors.gemspec",
13
+ 'lib/colors.rb',
14
+ 'lib/colors/string.rb',
15
+ 'features/color.feature',
16
+ 'README.txt',
17
+ 'changelog.txt'
18
+ ]
19
+ #s.autorequire = 'lib/colors.rb'
20
+ s.test_files = [
21
+ 'features/color.feature'
22
+ ]
23
+ s.rdoc_options = ["--main", "README.txt"]
24
+ s.has_rdoc = true
25
+ s.extra_rdoc_files = ["README.txt"]
26
+ end
27
+
@@ -0,0 +1,13 @@
1
+ Feature: String extensions
2
+ Scenario: colorizing
3
+ Given I have a string "abc a b"
4
+ When I highlight it
5
+ Then I should receive "abc a b"
6
+ When I highlight "a"
7
+ Then I should receive "abc a b"
8
+ When I highlight "abc"
9
+ Then I should receive "abc a b"
10
+ When I highlight it with :red
11
+ Then I should receive "abc a b"
12
+ When I highlight "abc" with :red
13
+ Then I should receive "abc a b"
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ Dir.glob(File.join(File.dirname(__FILE__), 'colors/**.rb')).sort.each { |f| require f }
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ class String
4
+ HIGHLIGHT = {
5
+ :end => "",
6
+ :gray => "",
7
+ :red => "",
8
+ :green => "",
9
+ :yellow => "",
10
+ :blue => "",
11
+ :purple => "",
12
+ :lightblue => "",
13
+ :white => "",
14
+ :red_bg => "",
15
+ :green_bg => "",
16
+ :yellow_bg => "",
17
+ :blue_bg => "",
18
+ :purple_bg => "",
19
+ :lightblue_bg => "",
20
+ :white_bg => "",
21
+ :bold => "",
22
+ :default => ""
23
+ }
24
+
25
+
26
+ # Allow string highlighting with Unix terminal codes.
27
+ # The +type+ of highlighting might be :bold, a color, e.g. :red, :blue
28
+ # or a background color, e.g. :red_bg, blue_bg, etc.
29
+ #
30
+ # If the +word+ is given, only the word will be highlighted.
31
+ # It is directly expanded in the Regexp, so you may use meta-characters,
32
+ # e.g. (John|Frank|Bill). It is also surrounded by anchors, so only
33
+ # whole words will be highlighted, e.g. "abc abcd".hl(:bold,"abc")
34
+ # => *abc* abcd
35
+ def hl(type=:bold,word=nil)
36
+ if word
37
+ self.gsub(/(\s|\A|[[:punct:]])#{word}(\s|\Z|[[:punct:]])/,
38
+ "\\1" + HIGHLIGHT[type] + word.to_s + HIGHLIGHT[:end] + "\\2")
39
+ else
40
+ HIGHLIGHT[type] + self.to_s + HIGHLIGHT[:end]
41
+ end
42
+ end
43
+ end
44
+
45
+
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apohllo-colors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Aleksander Pohl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-15 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Extensions for String highliting
17
+ email: apohllo@o2.pl
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.txt
24
+ files:
25
+ - Rakefile
26
+ - colors.gemspec
27
+ - lib/colors.rb
28
+ - lib/colors/string.rb
29
+ - features/color.feature
30
+ - README.txt
31
+ - changelog.txt
32
+ has_rdoc: true
33
+ homepage: http://apohllo.pl
34
+ post_install_message:
35
+ rdoc_options:
36
+ - --main
37
+ - README.txt
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.2.0
56
+ signing_key:
57
+ specification_version: 2
58
+ summary: Ruby String extesion for colored strings
59
+ test_files:
60
+ - features/color.feature