prettypretty 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +26 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +10 -0
- data/LICENSE +22 -0
- data/README.md +37 -0
- data/Rakefile +2 -0
- data/lib/ppp.rb +10 -0
- data/lib/ppp/ppp.rb +90 -0
- data/lib/ppp/version.rb +3 -0
- data/ppp.gemspec +20 -0
- data/test/test.rb +41 -0
- metadata +73 -0
data/.gitignore
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Vim
|
2
|
+
|
3
|
+
.*.sw[a-z]
|
4
|
+
*.un~
|
5
|
+
Session.vim
|
6
|
+
|
7
|
+
# Ruby
|
8
|
+
|
9
|
+
*.gem
|
10
|
+
*.rbc
|
11
|
+
.bundle
|
12
|
+
.config
|
13
|
+
coverage
|
14
|
+
InstalledFiles
|
15
|
+
lib/bundler/man
|
16
|
+
pkg
|
17
|
+
rdoc
|
18
|
+
spec/reports
|
19
|
+
test/tmp
|
20
|
+
test/version_tmp
|
21
|
+
tmp
|
22
|
+
|
23
|
+
# YARD artifacts
|
24
|
+
.yardoc
|
25
|
+
_yardoc
|
26
|
+
doc/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Wuffers Lightwolf
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# ppp
|
2
|
+
|
3
|
+
ppp. Pretty pp. Basically, pp. But with pretty colors.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ppp'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ppp
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'ppp'
|
23
|
+
|
24
|
+
ppp "string"
|
25
|
+
ppp [1, 2, 3]
|
26
|
+
ppp 123
|
27
|
+
```
|
28
|
+
|
29
|
+
It's not rocket surgery.
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/ppp.rb
ADDED
data/lib/ppp/ppp.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
module PPP
|
2
|
+
def ppp(object)
|
3
|
+
str = prettify(object)
|
4
|
+
puts str
|
5
|
+
end
|
6
|
+
|
7
|
+
def prettify(object)
|
8
|
+
pretty = send("colorize_#{object.class.to_s.downcase}".to_sym, object)
|
9
|
+
pretty
|
10
|
+
end
|
11
|
+
|
12
|
+
def colorize_string(s)
|
13
|
+
"#{'"'.red.bold}#{s.red}#{'"'.red.bold}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def colorize_fixnum(num)
|
17
|
+
num.to_s.blue
|
18
|
+
end
|
19
|
+
|
20
|
+
def colorize_float(f)
|
21
|
+
f.to_s.magenta
|
22
|
+
end
|
23
|
+
|
24
|
+
def colorize_boolean(b)
|
25
|
+
b.to_s.cyan
|
26
|
+
end
|
27
|
+
|
28
|
+
def colorize_array(a)
|
29
|
+
out = "[ "
|
30
|
+
|
31
|
+
a.each do |i|
|
32
|
+
str = prettify(i)
|
33
|
+
out << "#{str}, "
|
34
|
+
end
|
35
|
+
|
36
|
+
out << " ]"
|
37
|
+
out.sub!(/, \]/, " ]")
|
38
|
+
out
|
39
|
+
end
|
40
|
+
|
41
|
+
def colorize_symbol(sym)
|
42
|
+
":#{sym}".yellow
|
43
|
+
end
|
44
|
+
|
45
|
+
def colorize_hash(h)
|
46
|
+
str = "{ "
|
47
|
+
h.each do |k,v|
|
48
|
+
key = prettify(k)
|
49
|
+
value = prettify(v)
|
50
|
+
str << "#{key} => #{value}, "
|
51
|
+
end
|
52
|
+
str << " }"
|
53
|
+
str.sub!(/, \}/, " }")
|
54
|
+
str
|
55
|
+
end
|
56
|
+
|
57
|
+
def colorize_class(c)
|
58
|
+
c.to_s.underline.magenta
|
59
|
+
end
|
60
|
+
|
61
|
+
def method_missing(m, *args)
|
62
|
+
obj = *args[0]
|
63
|
+
obj = obj.to_s
|
64
|
+
obj = obj.split(':')
|
65
|
+
obj.map! {|x| x.split('<') }
|
66
|
+
|
67
|
+
obj[0][1] = obj[0][1].underline.magenta
|
68
|
+
obj[0] = obj[0].join("<")
|
69
|
+
|
70
|
+
obj.flatten!
|
71
|
+
|
72
|
+
obj[1] = obj[1].split
|
73
|
+
|
74
|
+
obj[1][0] = obj[1][0].underline
|
75
|
+
|
76
|
+
obj[1][1] = obj[1][1].split("=")
|
77
|
+
obj[1][1][0] = obj[1][1][0].green
|
78
|
+
|
79
|
+
obj[1][1][1] = (prettify(eval(obj[1][1][1].sub(">]", ""))) + ">]")
|
80
|
+
obj[1][1] = obj[1][1].join("=")
|
81
|
+
obj[1] = obj[1].join " "
|
82
|
+
obj = obj.join ":"
|
83
|
+
|
84
|
+
obj
|
85
|
+
end
|
86
|
+
|
87
|
+
alias_method :colorize_trueclass, :colorize_boolean
|
88
|
+
alias_method :colorize_falseclass, :colorize_boolean
|
89
|
+
alias_method :colorize_module, :colorize_class
|
90
|
+
end
|
data/lib/ppp/version.rb
ADDED
data/ppp.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH << File.expand_path('../lib/', __FILE__)
|
3
|
+
|
4
|
+
require 'ppp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.authors = ["Wuffers Lightwolf"]
|
8
|
+
gem.email = ["wuffers.lightwolf@me.com"]
|
9
|
+
gem.description = %q{pretty pretty print. Like pp, but with colors.}
|
10
|
+
gem.summary = %q{pretty pp}
|
11
|
+
gem.homepage = "http://w-x-l.github.com/ppp"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($\)
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "prettypretty"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = PPP::VERSION
|
18
|
+
|
19
|
+
gem.add_dependency "colored"
|
20
|
+
end
|
data/test/test.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'ppp'
|
4
|
+
|
5
|
+
puts "test"
|
6
|
+
ppp "test"
|
7
|
+
puts "-"*8
|
8
|
+
puts 1
|
9
|
+
ppp 1
|
10
|
+
puts "-"*8
|
11
|
+
puts 1.2
|
12
|
+
ppp 1.2
|
13
|
+
puts "-"*8
|
14
|
+
puts true
|
15
|
+
ppp true
|
16
|
+
puts "-"*8
|
17
|
+
ppp [1, 2, 3, 4, "five", [6, 7, 8, "nine"], true]
|
18
|
+
puts "-"*8
|
19
|
+
puts :sym
|
20
|
+
ppp :sym
|
21
|
+
puts "-"*8
|
22
|
+
puts({ :a => "b", :c => 1 })
|
23
|
+
ppp({ :a => "b", :c => 1 })
|
24
|
+
puts "-"*8
|
25
|
+
puts Class
|
26
|
+
ppp Class
|
27
|
+
puts "-"*8
|
28
|
+
puts Module
|
29
|
+
ppp Module
|
30
|
+
|
31
|
+
class MyClass
|
32
|
+
def initialize(x = 1)
|
33
|
+
@x = x
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
obj = MyClass.new(5)
|
38
|
+
|
39
|
+
puts "-"*8
|
40
|
+
puts(obj.to_s)
|
41
|
+
ppp obj
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prettypretty
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Wuffers Lightwolf
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: colored
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: pretty pretty print. Like pp, but with colors.
|
31
|
+
email:
|
32
|
+
- wuffers.lightwolf@me.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- Gemfile.lock
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/ppp.rb
|
44
|
+
- lib/ppp/ppp.rb
|
45
|
+
- lib/ppp/version.rb
|
46
|
+
- ppp.gemspec
|
47
|
+
- test/test.rb
|
48
|
+
homepage: http://w-x-l.github.com/ppp
|
49
|
+
licenses: []
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.8.23
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: pretty pp
|
72
|
+
test_files:
|
73
|
+
- test/test.rb
|