motion_print 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 97e1ca3fb34edcf770c4d9334466ab98271511c1
4
+ data.tar.gz: b1c07b5a2498aa65cdb642b12aea016a51df9964
5
+ SHA512:
6
+ metadata.gz: 78759107cf3af66eada2b0c1d10e7d1d3fcadca99b79de255d8b1ac1ea7169c22cf779d0a548e80c67babd151a120f4a85d3df114e682b87999a07a0429babfc
7
+ data.tar.gz: a50d1371e9627c548e44ba0aab986d564ffb3daf2634c87650a62f3364575ca694fddfa1312ac8a68b00e85ca31edc17a6ae7a2d386fdb8b204bc0bef9fe2753
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Mohawk Apps, LLC (http://mohawkapps.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # motion_print
2
+
3
+ A RubyMotion pretty printer.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/motion_print.svg)](http://badge.fury.io/rb/motion_print) [![Build Status](https://travis-ci.org/MohawkApps/motion_print.svg)](https://travis-ci.org/MohawkApps/motion_print) [![Code Climate](https://codeclimate.com/github/MohawkApps/motion_print.png)](https://codeclimate.com/github/MohawkApps/motion_print)
6
+
7
+ instead of using `p` or `puts`, use `mp` to log your debug values to the RubyMotion REPL.
8
+
9
+ ## Examples:
10
+
11
+ <small>Colors don't show up correctly on github, so these are just examples of what you can do with `motion_print`. Try it out for yourself to see the more colorful output!</small>
12
+
13
+ ```ruby
14
+ mp "a string"
15
+
16
+ "a string"
17
+ ```
18
+
19
+ ```ruby
20
+ mp :some_symbol
21
+
22
+ :some_symbol
23
+ ```
24
+
25
+ ```
26
+ mp [1, 'two', :three, 4.0]
27
+
28
+ [
29
+ 1,
30
+ 'two',
31
+ :three,
32
+ 4.0
33
+ ]
34
+ ```
35
+
36
+ ```ruby
37
+ mp({b: "bee", a: 'a', see: 4})
38
+
39
+ {
40
+ a => a,
41
+ b => bee,
42
+ see => 4
43
+ }
44
+ ```
45
+
46
+ ## Installation
47
+
48
+ Add this line to your application's Gemfile:
49
+
50
+ Stable:
51
+ ```ruby
52
+ gem 'motion_print'
53
+ ```
54
+
55
+ Bleeding Edge:
56
+ ```ruby
57
+ gem 'motion_print', github: 'MohawkApps/motion_print'
58
+ ```
59
+
60
+ And then execute:
61
+
62
+ ```bash
63
+ bundle
64
+ ```
65
+ ## Roadmap
66
+
67
+ 1. Add more core objects people want to output: `UIView`, `Struct`, etc. Please open an issue to make suggestions or just implement it yourself and send me a pull request!
68
+ 2. ~~Test suite.~~
69
+
70
+ ## What about awesome_print_motion?
71
+
72
+ I used to be a big fan of [awesome_print_motion](https://github.com/michaeldv/awesome_print_motion). Then I ran the Instruments allocations profiler on an app that had a big loop with lots of `ap` statements. You should have seen the graph increase exponentially over a few seconds. Then I took a look at the actual `awesome_print_motion` source code. It's basically a direct port of the `awesome_print` gem and just modified to "work" with RubyMotion. There's all kinds of core class extensions and crazy threading things going on... way too complex for my needs to output a pretty version of an object or hash or array.
73
+
74
+ That, coupled with the fact that the developer of awesome_print_motion doesn't seem responsive to [issues](https://github.com/michaeldv/awesome_print_motion/issues) or [pull requests](https://github.com/michaeldv/awesome_print_motion/pulls), I decided to roll my own debugging tool specifically written for RubyMotion development.
75
+
76
+ ## Contributing
77
+
78
+ 1. Fork it
79
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
80
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
81
+ 4. Push to the branch (`git push origin my-new-feature`)
82
+ 5. Create new Pull Request
@@ -0,0 +1,13 @@
1
+ unless defined?(Motion::Project::App)
2
+ raise "This must be required from within a RubyMotion Rakefile"
3
+ end
4
+
5
+ Motion::Project::App.setup do |app|
6
+ parent = File.join(File.dirname(__FILE__), '..')
7
+ files = [File.join(parent, 'motion/motion_print/version.rb')]
8
+ files << File.join(parent, 'motion/motion_print/core_ext/kernel.rb')
9
+ files << File.join(parent, 'motion/motion_print/core_ext/string.rb')
10
+ files << Dir.glob(File.join(parent, "motion/**/*.rb"))
11
+ files.flatten!.uniq!
12
+ app.files.unshift files
13
+ end
@@ -0,0 +1,17 @@
1
+ module MotionPrint
2
+ module Colorizer
3
+ extend self
4
+ %w(gray red green yellow blue purple cyan white).each_with_index do |color, i|
5
+ define_method color do |str|
6
+ "\e[1;#{30+i}m#{str}\e[0m"
7
+ end
8
+
9
+ define_method "#{color}ish" do |str|
10
+ "\e[0;#{30+i}m#{str}\e[0m"
11
+ end
12
+ end
13
+
14
+ alias :black :grayish
15
+ alias :pale :whiteish
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ module Kernel
2
+ def mp(object, options = {})
3
+ puts MotionPrint.logger(object)
4
+ object unless MotionPrint.console?
5
+ end
6
+
7
+ module_function :mp
8
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def shellescape
3
+ "'" << self.gsub("'", "'\"'\"'") << "'"
4
+ end
5
+ end
@@ -0,0 +1,119 @@
1
+ module MotionPrint
2
+
3
+ class << self
4
+ def console?
5
+ !!defined?(MotionRepl)
6
+ end
7
+
8
+ def logger(object, indent_level = 1)
9
+ case object
10
+ when Symbol
11
+ l_symbol object
12
+ when Array
13
+ l_array object, indent_level
14
+ when Dir
15
+ l_dir object
16
+ when Hash
17
+ l_hash object, indent_level
18
+ # when File
19
+ # l_file object
20
+ # when Struct
21
+ # l_struct object
22
+ else
23
+ colorize(object)
24
+ end
25
+ end
26
+
27
+ def l_array(a, indent_level = 1)
28
+ return "[]" if a.empty?
29
+ out = []
30
+
31
+ a.each do |arr|
32
+
33
+ if arr.is_a?(Array) || arr.is_a?(Hash)
34
+ v = logger(arr, indent_level + 1)
35
+ else
36
+ v = logger(arr)
37
+ end
38
+ out << (indent_by(indent_level) << v)
39
+ end
40
+
41
+ "[\n" << out.join(",\n") << "\n#{indent_by(indent_level-1)}]"
42
+ end
43
+
44
+ def l_hash(h, indent_level = 1)
45
+ return "{}" if h.empty?
46
+ data, out = [], []
47
+
48
+ keys = h.keys.sort { |a, b| a.to_s <=> b.to_s }
49
+ keys.each do |key|
50
+ data << [logger(key), h[key]]
51
+ end
52
+
53
+ width = data.map { |key, | key.size }.max || 0
54
+ width += indent_by(indent_level).length
55
+
56
+ data.each do |key, value|
57
+ if value.is_a?(Array) || value.is_a?(Hash)
58
+ v = logger(value, indent_level + 1)
59
+ else
60
+ v = logger(value)
61
+ end
62
+ out << (align(key, width, indent_level) << colorize(" => ", :hash) << v)
63
+ end
64
+
65
+ "{\n" << out.join(",\n") << "\n#{indent_by(indent_level-1)}}"
66
+ end
67
+
68
+ def l_dir(d)
69
+ ls = `ls -alF #{d.path.shellescape}`
70
+ colorize(ls.empty? ? d.inspect : "#{d.inspect}\n#{ls.chop}")
71
+ end
72
+
73
+ def l_symbol(object)
74
+ colorize(':' << object.to_s, object)
75
+ end
76
+
77
+ def colorize(object, type = nil)
78
+ type = object if type.nil?
79
+ Colorizer.send(decide_color(type), object)
80
+ end
81
+
82
+ def decide_color(object)
83
+ colors[object.class.to_s.downcase.to_sym] || :white
84
+ end
85
+
86
+ def colors
87
+ {
88
+ args: :pale,
89
+ array: :white,
90
+ bigdecimal: :blue,
91
+ class: :yellow,
92
+ date: :greenish,
93
+ falseclass: :red,
94
+ fixnum: :blue,
95
+ float: :blue,
96
+ hash: :pale,
97
+ keyword: :cyan,
98
+ method: :purpleish,
99
+ nilclass: :red,
100
+ rational: :blue,
101
+ string: :yellowish,
102
+ struct: :pale,
103
+ symbol: :cyanish,
104
+ time: :greenish,
105
+ trueclass: :green,
106
+ variable: :cyanish,
107
+ dir: :white
108
+ }
109
+ end
110
+
111
+ def indent_by(n)
112
+ ' ' * n
113
+ end
114
+
115
+ def align(value, width, indent = 1)
116
+ (indent_by(indent) + value.ljust(width)).chomp
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,3 @@
1
+ module MotionPrint
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion_print
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mark Rickert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bacon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: motion_print is a RubyMotion friendly console logger and debigging tool.
42
+ email:
43
+ - mjar81@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE
49
+ - README.md
50
+ - lib/motion_print.rb
51
+ - motion/motion_print/colorizer.rb
52
+ - motion/motion_print/core_ext/kernel.rb
53
+ - motion/motion_print/core_ext/string.rb
54
+ - motion/motion_print/motion_print.rb
55
+ - motion/motion_print/version.rb
56
+ homepage: https://github.com/MohawkApps/motion_print
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.3.0
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: A RubyMotion pretty printer.
80
+ test_files: []