gg 0.9.7 → 0.9.8
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.
- data/README.md +8 -5
- data/gg.gemspec +0 -1
- data/lib/gg.rb +2 -1
- data/lib/gg/core.rb +24 -18
- data/lib/gg/stack.rb +78 -0
- data/lib/gg/stack_line.rb +48 -0
- data/lib/gg/version.rb +1 -1
- metadata +28 -17
data/README.md
CHANGED
@@ -9,11 +9,13 @@ bug will disappear.
|
|
9
9
|
|
10
10
|
## Overview
|
11
11
|
|
12
|
-
GG is a debugging tool like FireBug for Ruby Rack applications
|
12
|
+
GG is a debugging tool like FireBug but for Ruby Rack applications
|
13
13
|
like Rails and Sinatra. It lets you log variables/values to the browser while
|
14
14
|
you work on and debug your web application.
|
15
15
|
|
16
|
-
To use it,
|
16
|
+
To use it, call "gg" from anywhere in your application followed by the
|
17
|
+
objects that you wish to log to the browser.
|
18
|
+
|
17
19
|
gg stands for the "gg" in "logger" but was also chosen because it is easy to
|
18
20
|
type, even when your right hand is on the mouse.
|
19
21
|
|
@@ -31,7 +33,7 @@ gg msg
|
|
31
33
|
GG will output to the screen the "gg msg" call, the call position and
|
32
34
|
the data.
|
33
35
|
|
34
|
-
It
|
36
|
+
It works with Hash and Array values as well as objects from custom classes.
|
35
37
|
|
36
38
|
```ruby
|
37
39
|
gg [ 1, 2, 3]
|
@@ -42,7 +44,8 @@ gg MyObject.new( 'cool object' )
|
|
42
44
|
## Choosing Injection Points
|
43
45
|
|
44
46
|
GG always adds the required CSS file at the top of the <head> tag.
|
45
|
-
If there is no <head> tag then it adds it to the top of the content
|
47
|
+
If there is no <head> tag then it adds it to the top of the content sent to
|
48
|
+
the browser.
|
46
49
|
|
47
50
|
GG tries to add the logging information in the HTML where it finds
|
48
51
|
<!--gg-->.
|
@@ -51,7 +54,7 @@ If it cannot find <!--gg--> then it adds the HTML to the top of the
|
|
51
54
|
page after the css link.
|
52
55
|
|
53
56
|
|
54
|
-
## Non-HTML requests
|
57
|
+
## Non-HTML requests (JSON, Images, etc.)
|
55
58
|
|
56
59
|
If you call gg during a non-HTML request like a txt, js or css file, GG
|
57
60
|
does not return the value to the screen since this would mess up your
|
data/gg.gemspec
CHANGED
data/lib/gg.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'rack'
|
2
2
|
require 'awesome_print'
|
3
3
|
require 'slim'
|
4
|
-
require 'hi_caller'
|
5
4
|
require 'gg/version'
|
6
5
|
require 'gg/rack_plugin'
|
7
6
|
require 'gg/demo_app'
|
8
7
|
require 'gg/core'
|
9
8
|
require 'gg/logger'
|
9
|
+
require 'gg/stack'
|
10
|
+
require 'gg/stack_line'
|
10
11
|
|
11
12
|
class GG
|
12
13
|
|
data/lib/gg/core.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
|
2
2
|
module Kernel
|
3
3
|
|
4
|
-
def
|
4
|
+
def gg_caller(start=1)
|
5
|
+
# we add another +1 because we have to remove the current #hi_caller call
|
6
|
+
# from the stack.
|
7
|
+
GG::Stack.new(caller(start+1))
|
8
|
+
end
|
9
|
+
|
10
|
+
def gg(*args)
|
5
11
|
#ap args
|
6
12
|
#ap caller
|
7
13
|
#$gg << "<h1>JFKLDJSKLFSDJKL</h1>"
|
8
14
|
#ap '======================'
|
9
15
|
#ap args.size
|
10
|
-
stack =
|
16
|
+
stack = gg_caller
|
11
17
|
history = {}
|
12
18
|
# case args.size
|
13
19
|
# when 1
|
@@ -39,16 +45,16 @@ end
|
|
39
45
|
|
40
46
|
class Object
|
41
47
|
|
42
|
-
def to_hi_html(
|
43
|
-
history[
|
48
|
+
def to_hi_html(history)
|
49
|
+
history[self] = true
|
44
50
|
if self.instance_variables.size == 0
|
45
|
-
GG.render(
|
51
|
+
GG.render('slim/object.slim',
|
46
52
|
object: self,
|
47
53
|
classname: "hi-#{ self.class }",
|
48
54
|
history: history
|
49
55
|
)
|
50
56
|
else
|
51
|
-
GG.render(
|
57
|
+
GG.render('slim/object_with_instance_variables.slim',
|
52
58
|
object: self,
|
53
59
|
classname: "hi-#{ self.class }",
|
54
60
|
history: history
|
@@ -61,16 +67,16 @@ end
|
|
61
67
|
|
62
68
|
class Numeric
|
63
69
|
|
64
|
-
def to_hi_html(
|
65
|
-
GG.render(
|
70
|
+
def to_hi_html(history)
|
71
|
+
GG.render('slim/object.slim', object: self, classname: "hi-Numeric")
|
66
72
|
end
|
67
73
|
|
68
74
|
end
|
69
75
|
|
70
76
|
class String
|
71
77
|
|
72
|
-
def to_hi_html(
|
73
|
-
GG.render(
|
78
|
+
def to_hi_html(history)
|
79
|
+
GG.render('slim/string.slim', self)
|
74
80
|
#Tilt.new( GG.path( 'string.slim' ) ).render( self )
|
75
81
|
end
|
76
82
|
|
@@ -78,19 +84,19 @@ end
|
|
78
84
|
|
79
85
|
class Array
|
80
86
|
|
81
|
-
def to_hi_html(
|
82
|
-
return "...recursive..." if history[
|
83
|
-
history[
|
84
|
-
GG.render(
|
87
|
+
def to_hi_html(history)
|
88
|
+
return "...recursive..." if history[self]
|
89
|
+
history[self] = true
|
90
|
+
GG.render('slim/array.slim', object: self, history: history)
|
85
91
|
end
|
86
92
|
|
87
93
|
end
|
88
94
|
|
89
95
|
class Hash
|
90
96
|
|
91
|
-
def to_hi_html(
|
92
|
-
return "...recursive..." if history[
|
93
|
-
history[
|
94
|
-
GG.render(
|
97
|
+
def to_hi_html(history)
|
98
|
+
return "...recursive..." if history[self]
|
99
|
+
history[self] = true
|
100
|
+
GG.render('slim/hash.slim', object: self, history: history)
|
95
101
|
end
|
96
102
|
end
|
data/lib/gg/stack.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# stakk.rb
|
2
|
+
#==Instantiate a Go::CallStack object
|
3
|
+
#
|
4
|
+
# This is the way to create a Stakk object that contains a full stack trace
|
5
|
+
# that is easy to get data out of.
|
6
|
+
#
|
7
|
+
# stack = get_stakk # stack starting from one up the caller stack
|
8
|
+
# stack = get_stakk(1) # stack starting from one up the caller stack
|
9
|
+
# stack = get_stakk(0) # stack starting from this line
|
10
|
+
#
|
11
|
+
# The traditional way to instantiate a Stakk
|
12
|
+
#
|
13
|
+
# stack = Stakk.new( caller ) # look one up the caller stack
|
14
|
+
# stack = Stakk.new( caller(1) ) # Same as above
|
15
|
+
# stack = Stakk.new( caller(0) ) # get callstack at this line in code
|
16
|
+
#
|
17
|
+
#== Methods
|
18
|
+
#
|
19
|
+
# Get one item in the stack
|
20
|
+
#
|
21
|
+
# item = stack[0]
|
22
|
+
# item.line -> 5
|
23
|
+
# item.value -> "./go/util/caller/caller.test.rb:6:in `test_caller'"
|
24
|
+
# item.to_s -> same as above
|
25
|
+
# item.path -> path to stack item
|
26
|
+
# item.path( 'file.html' ) -> path to other file in same dir as stack item
|
27
|
+
# item.dir -> dir of stack item
|
28
|
+
# item.join( subpath ) -> join subpath to item.dir
|
29
|
+
# item.method_name -> name of method. Didn't use #method because of conflict
|
30
|
+
#
|
31
|
+
# Stakk methods
|
32
|
+
#
|
33
|
+
# stack.to_a
|
34
|
+
# stack.each
|
35
|
+
# stack[0]
|
36
|
+
# stack[0..3]
|
37
|
+
|
38
|
+
class GG::Stack
|
39
|
+
|
40
|
+
include Enumerable
|
41
|
+
|
42
|
+
# CallStack takes an array that is returned by the method Kernel#caller.
|
43
|
+
def initialize( array )
|
44
|
+
@array = array
|
45
|
+
@items = []
|
46
|
+
end
|
47
|
+
|
48
|
+
attr_reader :array, :items
|
49
|
+
|
50
|
+
# Returns the CallStack::Item at the nth position up the stack or if given
|
51
|
+
# a range, returns a new GoCallStack object with that portion of the array
|
52
|
+
# of initial caller items.
|
53
|
+
def []( arg )
|
54
|
+
if arg.is_a?( Range )
|
55
|
+
GG::Stack.new( array[ arg ] )
|
56
|
+
else
|
57
|
+
items[ arg ] ||= GG::StackLine.new( array[ arg ] )
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Iterates over each item in the CallStack
|
62
|
+
def each
|
63
|
+
array.each_with_index do |item,i|
|
64
|
+
yield self[i]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns all CallStack::Item objects as an array
|
69
|
+
def to_a
|
70
|
+
i = 0
|
71
|
+
@array.map do |stack_line_value|
|
72
|
+
item = self[i]
|
73
|
+
i += 1
|
74
|
+
item
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Represents one item in the callstack returned by the Kernel#caller method.
|
2
|
+
# This is a better representation because it parses out the #dir, #path, #code
|
3
|
+
# and other pieces of the callstack item.
|
4
|
+
|
5
|
+
class GG::StackLine
|
6
|
+
|
7
|
+
# Takes a string from the array of strings returned from Ruby's method
|
8
|
+
# Kernel#caller.
|
9
|
+
def initialize( s )
|
10
|
+
matchdata = /^(.*)[:]([0-9]+)(?:[:]in `(.*)')?$/.match( s )
|
11
|
+
# If the line in caller can be parsed, then set the correct instance vars
|
12
|
+
if matchdata
|
13
|
+
@path = File.expand_path( matchdata[1] )
|
14
|
+
@line_number = matchdata[2].to_i
|
15
|
+
@method_name = matchdata[3] ? matchdata[3].to_sym : nil
|
16
|
+
# If there is no proper match, we just set all the values to nil.
|
17
|
+
# Technically this isn't required but it makes for clearer intent here. :)
|
18
|
+
else
|
19
|
+
@path = nil
|
20
|
+
@line = nil
|
21
|
+
@method_name = nil
|
22
|
+
end
|
23
|
+
@value = s
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_reader :path, :method_name, :value, :line_number
|
27
|
+
|
28
|
+
def code_lines
|
29
|
+
@code_lines ||= File.readlines( path )
|
30
|
+
end
|
31
|
+
|
32
|
+
def code_line
|
33
|
+
code_lines[ line_number-1 ]
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the directory of the StackLine
|
37
|
+
def dir
|
38
|
+
File.dirname( path )
|
39
|
+
end
|
40
|
+
|
41
|
+
# Joins the directory of the stakk item with the given subpath
|
42
|
+
def join( subpath )
|
43
|
+
File.join( dir, subpath )
|
44
|
+
end
|
45
|
+
|
46
|
+
alias :to_s :value
|
47
|
+
|
48
|
+
end
|
data/lib/gg/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: awesome_print
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rack
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: slim
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,18 +69,12 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :runtime
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
58
|
-
- !ruby/object:Gem::Dependency
|
59
|
-
name: hi_caller
|
60
|
-
requirement: &16681908 !ruby/object:Gem::Requirement
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
61
73
|
none: false
|
62
74
|
requirements:
|
63
75
|
- - ! '>='
|
64
76
|
- !ruby/object:Gem::Version
|
65
77
|
version: '0'
|
66
|
-
type: :runtime
|
67
|
-
prerelease: false
|
68
|
-
version_requirements: *16681908
|
69
78
|
description: Log to the Browser
|
70
79
|
email:
|
71
80
|
- thesunny@gmail.com
|
@@ -95,6 +104,8 @@ files:
|
|
95
104
|
- lib/gg/slim/object_with_instance_variables.slim
|
96
105
|
- lib/gg/slim/section.slim
|
97
106
|
- lib/gg/slim/string.slim
|
107
|
+
- lib/gg/stack.rb
|
108
|
+
- lib/gg/stack_line.rb
|
98
109
|
- lib/gg/version.rb
|
99
110
|
- public/images/accept.png
|
100
111
|
homepage: ''
|
@@ -117,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
128
|
version: '0'
|
118
129
|
requirements: []
|
119
130
|
rubyforge_project: gg
|
120
|
-
rubygems_version: 1.8.
|
131
|
+
rubygems_version: 1.8.24
|
121
132
|
signing_key:
|
122
133
|
specification_version: 3
|
123
134
|
summary: Log to the Browser
|