lolize 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - rbx
5
+ - rbx-2.0
6
+ - ree
7
+ - jruby
8
+ - ruby-head
9
+
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lolize (0.0.1)
4
+ lolize (0.0.3)
5
5
  paint (~> 0.8.3)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
10
  paint (0.8.3)
11
+ rake (0.9.2)
11
12
 
12
13
  PLATFORMS
13
14
  ruby
@@ -15,3 +16,4 @@ PLATFORMS
15
16
  DEPENDENCIES
16
17
  lolize!
17
18
  paint (~> 0.8.3)
19
+ rake
data/README.md CHANGED
@@ -4,16 +4,43 @@ Colorize your ruby output with rainbow :)
4
4
 
5
5
  The colorize algorithm is based on [lolcat](https://github.com/busyloop/lolcat).
6
6
 
7
+ ## Installation
8
+
9
+ gem install lolize
10
+
11
+ You need 256-color terminal for best experience.
12
+
7
13
  ## How to lolize
8
14
 
9
- In your ruby code/irb:
15
+ Just require `lolize/auto`. it will automatically hook your `$stdout` and `$stderr`.
16
+
17
+ ### Bundler Gemfile
18
+
19
+ For example, you can do this in your rails project:
20
+
21
+ # Gemfile
22
+ gem 'lolize', :require => 'lolize/auto'
23
+
24
+ ![Rails with lolize](http://miaout17.github.com/lolize/lolize-rails.png)
25
+
26
+ ### Any Ruby, anywhere
27
+
28
+ Here is the snippet:
10
29
 
11
30
  gem 'lolize'
12
31
  require 'lolize/auto'
13
32
 
14
- Bundler Gemfile:
33
+ You can even do this in your compass `config.rb`:
15
34
 
16
- gem 'lolize', :require => 'lolize/auto'
35
+ ![Compass watch with lolize](http://miaout17.github.com/lolize/lolize-compass.png)
36
+
37
+ ## Don't colorize everything please
38
+
39
+ gem 'lolize'
40
+ require 'lolize'
41
+ colorizer = Lolize::Colorizer.new
42
+ colorizer.write "Hello, World\n"*5
43
+ puts "I AM WHITE" # This is clean
17
44
 
18
45
  ## Why lolize
19
46
 
@@ -26,15 +53,16 @@ If you try this:
26
53
  rails c 2>&1 | lolcat
27
54
 
28
55
  You will find that the last line won't be displayed forever.
29
-
30
- After some googling, I think it need
56
+ It seems hard to solve this problem, some platform-dependent C-extension is needed.
31
57
 
32
58
  ## Caution
33
59
 
34
60
  * This is just a fun project
35
- * If something gets wrong within output hook, the program might crash silently
36
61
  * Never use this in your production project!!!!
62
+ * It will slow your console output
63
+ * If something gets wrong within output hook, the program might crash silently
37
64
 
38
65
  ## License
39
66
 
40
67
  MIT License
68
+
data/Rakefile CHANGED
@@ -1,2 +1,13 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ task :default do
5
+ # A very simple "DONT CRASH TEST", I just want to ensure this won't crash the program
6
+ require 'lolize'
7
+ colorizer = Lolize::Colorizer.new
8
+ colorizer.write "*****\n"*5
9
+
10
+ 5.times { puts "*"*5 }
11
+ require 'lolize/auto'
12
+ 5.times { puts "*"*5 }
13
+ end
@@ -1,2 +1,7 @@
1
1
  require 'lolize/version'
2
2
  require 'lolize/colorizer'
3
+ require 'lolize/hooker'
4
+
5
+ module Lolize
6
+ extend Lolize::Hooker
7
+ end
@@ -1,5 +1,5 @@
1
1
  require 'lolize'
2
2
 
3
- Lolize::Colorizer.lolize($stdout)
4
- Lolize::Colorizer.lolize($stderr)
3
+ Lolize.lolize! $stdout
4
+ Lolize.lolize! $stderr
5
5
 
@@ -1,17 +1,12 @@
1
1
  require 'paint'
2
- require 'singleton'
3
2
 
4
3
  module Lolize
5
4
  class Colorizer
6
- include Singleton
7
5
 
8
- def self.lolize(output)
9
- class << output
10
- alias :raw_write :write
11
- def write(s)
12
- ::Lolize::Colorizer.instance.write(s)
13
- end
14
- end
6
+ RAW_WRITE_METHOD = :write_without_lolize
7
+
8
+ def self.instance
9
+ @instance ||= Lolize::Colorizer.new
15
10
  end
16
11
 
17
12
  def initialize
@@ -23,6 +18,8 @@ module Lolize
23
18
  @state = :normal
24
19
  end
25
20
 
21
+ # The algorithm is from lolcat (https://github.com/busyloop/lolcat)
22
+ # lolcat is released with WTFPL
26
23
  def rainbow
27
24
  red = Math.sin(@freq*@color + 0) * 127 + 128
28
25
  green = Math.sin(@freq*@color + 2*Math::PI/3) * 127 + 128
@@ -51,7 +48,13 @@ module Lolize
51
48
  end
52
49
 
53
50
  def raw_write(s)
54
- $stdout.raw_write(s)
51
+ if $stdout.respond_to?(RAW_WRITE_METHOD)
52
+ # if $stdout is hook
53
+ $stdout.send(RAW_WRITE_METHOD, s)
54
+ else
55
+ # $stdout is not hooked
56
+ $stdout.write(s)
57
+ end
55
58
  end
56
59
  end
57
60
  end
@@ -0,0 +1,12 @@
1
+ module Lolize
2
+ module Hooker
3
+ def lolize!(output)
4
+ class << output
5
+ alias_method (::Lolize::Colorizer::RAW_WRITE_METHOD), :write
6
+ def write(s)
7
+ ::Lolize::Colorizer.instance.write(s)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Lolize
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.add_dependency 'paint', '~> 0.8.3'
23
+ s.add_development_dependency 'rake'
23
24
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lolize
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - miaout17
@@ -34,6 +34,20 @@ dependencies:
34
34
  version: 0.8.3
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :development
50
+ version_requirements: *id002
37
51
  description: Colorize your ruby stdout with Lolcat
38
52
  email:
39
53
  - miaout17@gmail.com
@@ -45,6 +59,7 @@ extra_rdoc_files: []
45
59
 
46
60
  files:
47
61
  - .gitignore
62
+ - .travis.yml
48
63
  - Gemfile
49
64
  - Gemfile.lock
50
65
  - MIT-LICENSE
@@ -53,6 +68,7 @@ files:
53
68
  - lib/lolize.rb
54
69
  - lib/lolize/auto.rb
55
70
  - lib/lolize/colorizer.rb
71
+ - lib/lolize/hooker.rb
56
72
  - lib/lolize/version.rb
57
73
  - lolize.gemspec
58
74
  has_rdoc: true