padrino-support 0.12.1 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc4d6db979b946264882e0875c6c03d2d44b2f0d
4
- data.tar.gz: 971d5c0af718f7203519dda9d16d8051f1b3ae39
3
+ metadata.gz: ac0fd7870851b895d6688bbb53181a50dc53f4ed
4
+ data.tar.gz: 98f3982588c071db926a14429c855f0a698818f6
5
5
  SHA512:
6
- metadata.gz: 368b385238ed28df21735451435432800a886e14e8e7b8cde6a01ed17723f2efd919033b241f9ef005f3a5bdff3798d46bf5404e949903dec2fbcd90145dca1a
7
- data.tar.gz: f502084320954430461904de2fbcf68294390eb59c692e6e911c93d5c12aa444416019e9575bd822a26930060f14801bbb55a4926a085e9b50b9c5beec99e3fa
6
+ metadata.gz: a01e7516d21ce28df4f4575229e7da1351d3db13b8ec76ee1cb380668b39568c10765193bee2ef058d1b19d6d298ba8870fec61890242fa93664d695ba0fb7b1
7
+ data.tar.gz: 3e6ee99b72115ac4db88144b78fbadc4bafba796210abbeabfad4a7f971557852580c044e22c20b74898d301b81613e322d7538c28caf9beb8fb039e08e6850f
@@ -5,8 +5,13 @@ require 'win32console' if RUBY_PLATFORM =~ /(win|m)32/ # ruby color support
5
5
  #
6
6
  class String
7
7
  # colorize(:red)
8
- def colorize(color)
9
- Colorizer.send(color, self)
8
+ def colorize(args)
9
+ case args
10
+ when Symbol
11
+ Colorizer.send(args, self)
12
+ when Hash
13
+ Colorizer.send(args[:color], self, args[:mode])
14
+ end
10
15
  end
11
16
 
12
17
  # Used to colorize strings for the shell
@@ -14,8 +19,7 @@ class String
14
19
  # Returns colors integer mapping
15
20
  def self.colors
16
21
  @_colors ||= {
17
- :clear => 0,
18
- :bold => 1,
22
+ :default => 9,
19
23
  :black => 30,
20
24
  :red => 31,
21
25
  :green => 32,
@@ -27,12 +31,21 @@ class String
27
31
  }
28
32
  end
29
33
 
34
+ # Returns modes integer mapping
35
+ def self.modes
36
+ @_modes ||= {
37
+ :default => 0,
38
+ :bold => 1
39
+ }
40
+ end
41
+
30
42
  # Defines class level color methods
31
43
  # i.e Colorizer.red("hello")
32
44
  class << self
33
45
  Colorizer.colors.each do |color, value|
34
- define_method(color) do |target|
35
- "\e[#{value}m" << target << "\e[0m"
46
+ define_method(color) do |target, mode_name = :default|
47
+ mode = modes[mode_name] || modes[:default]
48
+ "\e[#{mode};#{value}m" << target << "\e[0m"
36
49
  end
37
50
  end
38
51
  end
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ describe "String#colorize" do
4
+ it "should colorize text correctly" do
5
+ assert_equal "\e[0;34mHello world\e[0m", "Hello world".colorize(:blue)
6
+ assert_equal "\e[0;30mHello world\e[0m", "Hello world".colorize(:black)
7
+ assert_equal "\e[0;31mHello world\e[0m", "Hello world".colorize(:red)
8
+ assert_equal "\e[0;32mHello world\e[0m", "Hello world".colorize(:green)
9
+ assert_equal "\e[0;33mHello world\e[0m", "Hello world".colorize(:yellow)
10
+ assert_equal "\e[0;34mHello world\e[0m", "Hello world".colorize(:blue)
11
+ assert_equal "\e[0;35mHello world\e[0m", "Hello world".colorize(:magenta)
12
+ assert_equal "\e[0;36mHello world\e[0m", "Hello world".colorize(:cyan)
13
+ assert_equal "\e[0;37mHello world\e[0m", "Hello world".colorize(:white)
14
+ end
15
+
16
+ it "should colorize text when using color name method" do
17
+ assert_equal "\e[0;30mHello world\e[0m", String::Colorizer.black("Hello world")
18
+ assert_equal "\e[0;31mHello world\e[0m", String::Colorizer.red("Hello world")
19
+ assert_equal "\e[0;32mHello world\e[0m", String::Colorizer.green("Hello world")
20
+ assert_equal "\e[0;33mHello world\e[0m", String::Colorizer.yellow("Hello world")
21
+ assert_equal "\e[0;34mHello world\e[0m", String::Colorizer.blue("Hello world")
22
+ assert_equal "\e[0;35mHello world\e[0m", String::Colorizer.magenta("Hello world")
23
+ assert_equal "\e[0;36mHello world\e[0m", String::Colorizer.cyan("Hello world")
24
+ assert_equal "\e[0;37mHello world\e[0m", String::Colorizer.white("Hello world")
25
+ end
26
+
27
+ it "should be possible to set the mode" do
28
+ assert_equal "\e[1;34mHello world\e[0m", "Hello world".colorize(:color => :blue, :mode => :bold)
29
+ assert_equal "\e[1;34mHello world\e[0m", String::Colorizer.blue("Hello world", :bold)
30
+ end
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-04-04 00:00:00.000000000 Z
15
+ date: 2014-05-12 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
@@ -68,6 +68,7 @@ files:
68
68
  - lib/padrino-support/locale/zh_tw.yml
69
69
  - padrino-support.gemspec
70
70
  - test/helper.rb
71
+ - test/test_colorize.rb
71
72
  - test/test_support_lite.rb
72
73
  homepage: http://www.padrinorb.com
73
74
  licenses:
@@ -96,5 +97,6 @@ specification_version: 4
96
97
  summary: Support for padrino
97
98
  test_files:
98
99
  - test/helper.rb
100
+ - test/test_colorize.rb
99
101
  - test/test_support_lite.rb
100
102
  has_rdoc: