gg 0.9.12 → 0.9.13

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/lib/gg.rb CHANGED
@@ -6,7 +6,7 @@ require 'gg/rack_plugin'
6
6
  require 'gg/demo_app'
7
7
  require 'gg/core'
8
8
  require 'gg/logger'
9
- require 'gg/history'
9
+ require 'gg/state'
10
10
  require 'gg/stack'
11
11
  require 'gg/stack_line'
12
12
 
@@ -7,14 +7,15 @@ module Kernel
7
7
  GG::Stack.new(caller(start+1))
8
8
  end
9
9
 
10
- def gg(*args)
10
+ def gg(*args, &block)
11
11
  #ap args
12
12
  #ap caller
13
13
  #$gg << "<h1>JFKLDJSKLFSDJKL</h1>"
14
14
  #ap '======================'
15
15
  #ap args.size
16
16
  stack = gg_caller
17
- history = GG::History.new
17
+ history = GG::State.new
18
+ history.instance_eval(&block) if block
18
19
  # case args.size
19
20
  # when 1
20
21
  # $gg << GG.render( 'slim/logger.slim', { stack: stack } ) do
@@ -31,18 +32,23 @@ module Kernel
31
32
  )
32
33
 
33
34
  # RENDER CONSOLE
34
- $gg.console_array << <<-EOF
35
- #{'-'*79}
36
- #{caller[0]}
37
- #{stack[0].code_line.strip}
38
- #{'.'*79}
39
- #{args.ai({})}
40
- EOF
41
- # end
35
+ begin
36
+ $gg.console_array << '-'*79
37
+ $gg.console_array << caller[0]
38
+ $gg.console_array << stack[0].code_line.strip
39
+ $gg.console_array << '-'*79
40
+ $gg.console_array << args.ai({})
41
+ rescue => e
42
+ $gg.console_array << e.inspect
43
+ end
42
44
  end
43
45
 
44
46
  def gg_render_error(e)
45
- e.inspect
47
+ "<span class=\"gg-error\">error in gg: #{Rack::Utils.escape_html(e.inspect)}</span>"
48
+ end
49
+
50
+ def gg_render_recursive
51
+ "<span class=\"gg-recursive\">...recursive...</span>"
46
52
  end
47
53
 
48
54
  end
@@ -50,8 +56,7 @@ end
50
56
  class Object
51
57
 
52
58
  def to_hi_html(history)
53
- return "...recursive..." if history[self]
54
- history[self] = true
59
+ return gg_render_recursive if history.exists?(self)#[self]
55
60
  if self.instance_variables.size == 0
56
61
  GG.render('slim/object.slim',
57
62
  object: self,
@@ -59,6 +64,7 @@ class Object
59
64
  history: history
60
65
  )
61
66
  else
67
+ history.add(self)#[self] = true
62
68
  GG.render('slim/object_with_instance_variables.slim',
63
69
  object: self,
64
70
  classname: "hi-#{ self.class }",
@@ -96,8 +102,8 @@ end
96
102
  class Array
97
103
 
98
104
  def to_hi_html(history)
99
- return "...recursive..." if history[self]
100
- history[self] = true
105
+ return gg_render_recursive if history.exists?(self)#[self]
106
+ history.add(self)#[self] = true
101
107
  GG.render('slim/array.slim', object: self, history: history)
102
108
  rescue => e
103
109
  gg_render_error(e)
@@ -108,8 +114,8 @@ end
108
114
  class Hash
109
115
 
110
116
  def to_hi_html(history)
111
- return "...recursive..." if history[self]
112
- history[self] = true
117
+ return gg_render_recursive if history.exists?(self)#self
118
+ history.add(self) #[self] = true
113
119
  GG.render('slim/hash.slim', object: self, history: history)
114
120
  rescue => e
115
121
  gg_render_error(e)
@@ -12,6 +12,12 @@ class GG::DemoApp
12
12
 
13
13
  end
14
14
 
15
+ class CustomWithError
16
+ def class
17
+ throw "Class Call Error"
18
+ end
19
+ end
20
+
15
21
  def call(env)
16
22
  case env[ 'PATH_INFO' ]
17
23
  when '/'
@@ -78,8 +84,19 @@ class GG::DemoApp
78
84
  }
79
85
  }
80
86
  gg hash
87
+
81
88
  custom = Custom.new( 'cube', [ 5, 3 ], 'yellow' )
82
89
  gg custom
90
+
91
+ custom_with_error = CustomWithError.new
92
+ gg custom_with_error
93
+
94
+ hash_with_error = {
95
+ 'a' => 'alpha',
96
+ 'custom' => CustomWithError.new
97
+ }
98
+ gg hash_with_error
99
+
83
100
  recursive_hash = { a: 'alpha', b: 'bravo' }
84
101
  recursive_array = [ :a, :b, recursive_hash ]
85
102
  recursive_hash[ :array ] = recursive_array
@@ -89,6 +106,12 @@ class GG::DemoApp
89
106
  gg recursive_hash
90
107
  gg recursive_array
91
108
  gg recursive_object
109
+
110
+ non_recursive_hash = {
111
+ 'a' => {1 => true, 2 => true},
112
+ 'b' => {1 => true, 2 => true}
113
+ }
114
+ gg non_recursive_hash
92
115
  end
93
116
 
94
117
  end
@@ -64,7 +64,16 @@
64
64
 
65
65
  /* OBJECTS */
66
66
 
67
- .hi-string {
67
+ .gg-recursive {
68
+ font-style: italic;
69
+ }
70
+
71
+ .gg-error {
72
+ color: #C00;
73
+ font-style: italic;
74
+ }
75
+
76
+ .gg-String {
68
77
  color: #048;
69
78
  }
70
79
 
@@ -1,3 +1,3 @@
1
1
  - id = rand( 1000000000 )
2
- span.hi-string
2
+ span.gg-String
3
3
  = self.inspect
@@ -0,0 +1,44 @@
1
+ class GG::State
2
+
3
+ attr_reader :hash
4
+
5
+ def initialize
6
+ @hash = {}
7
+ @depth = 2
8
+ end
9
+
10
+ def exists?(value)
11
+ hash.key?(value.object_id)
12
+ end
13
+
14
+ def add(value)
15
+ hash[value.object_id] = true
16
+ end
17
+
18
+ def depth(value=nil)
19
+ if value.nil?
20
+ @depth
21
+ else
22
+ @depth = depth
23
+ end
24
+ end
25
+
26
+
27
+ # SHOW_LIMIT = 15
28
+ #
29
+ # def initialize
30
+ # @show_count = 0
31
+ # super
32
+ # end
33
+ #
34
+ # attr_accessor :show_count
35
+ #
36
+ # def inc
37
+ # @show_count += 1
38
+ # end
39
+ #
40
+ # def continue?
41
+ # @show_count <= SHOW_LIMIT
42
+ # end
43
+
44
+ end
@@ -1,3 +1,3 @@
1
1
  class GG
2
- VERSION = "0.9.12"
2
+ VERSION = "0.9.13"
3
3
  end
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.12
4
+ version: 0.9.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -91,7 +91,6 @@ files:
91
91
  - lib/gg.rb
92
92
  - lib/gg/core.rb
93
93
  - lib/gg/demo_app.rb
94
- - lib/gg/history.rb
95
94
  - lib/gg/logger.rb
96
95
  - lib/gg/public/gg.css
97
96
  - lib/gg/rack_plugin.rb
@@ -108,6 +107,7 @@ files:
108
107
  - lib/gg/slim/string.slim
109
108
  - lib/gg/stack.rb
110
109
  - lib/gg/stack_line.rb
110
+ - lib/gg/state.rb
111
111
  - lib/gg/version.rb
112
112
  - public/images/accept.png
113
113
  homepage: ''
@@ -1,20 +0,0 @@
1
- class GG::History < Hash
2
-
3
- # SHOW_LIMIT = 15
4
- #
5
- # def initialize
6
- # @show_count = 0
7
- # super
8
- # end
9
- #
10
- # attr_accessor :show_count
11
- #
12
- # def inc
13
- # @show_count += 1
14
- # end
15
- #
16
- # def continue?
17
- # @show_count <= SHOW_LIMIT
18
- # end
19
-
20
- end