gg 0.9.10 → 0.9.11

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.
@@ -1,86 +1,86 @@
1
- class GG
2
-
3
- def initialize( app )
4
- @app = app
5
- @history = []
6
- end
7
-
8
- MAX_HISTORY = 10
9
-
10
- attr_reader :app, :history
11
-
12
- def call( env )
13
- case env[ 'PATH_INFO' ]
14
- when '/gg/history'
15
- render_history( 0 )
16
- when %r{/gg/history/([0-9])}
17
- render_history( $~[1].to_i )
18
- when '/gg/main.css'
19
- [
20
- 200,
21
- { 'Content-Type' => 'text/css' },
22
- [ File.read(File.join(File.dirname(__FILE__),'public/gg.css'))]
23
- ]
24
- else
25
- render_app( env )
26
- end
27
- end
28
-
29
- private
30
-
31
- def render_app( env )
32
- #ap [ $0, *$LOADED_FEATURES ]
33
- env[ 'gg' ] = $gg = gg = GG::Logger.new( env )
34
- response = @app.call( env )
35
- # response = result.is_a?(Rack::Response) ? result : Rack::Response.new(result[2], result[0], result[1])
36
- # env[ 'gg' ].response = Rack::Response.new( result )
37
- # env[ 'gg' ].response = response
38
- # Logs to the HTML page only if the response type is text/html
39
- if !gg.empty?
40
- if response_is_html(response)
41
- add_logger_to_response( response, gg )
42
- add_logger_to_history( gg )
43
- else
44
- puts
45
- puts '='*79
46
- puts env['REQUEST_URI'] || env['PATH_INFO']
47
- $gg.console_array.each do |item|
48
- puts item
49
- end
50
- end
51
- end
52
- response
53
- end
54
-
55
- def render_history( i )
56
- logger = history[i]
57
- body = logger
58
- html = GG.render( 'slim/history.slim', body: body, history: history, logger: logger )
59
- [ 200, { 'Content-Type' => 'text/html' }, [ html ] ]
60
- end
61
-
62
- def response_is_html( response )
63
- return true if response.respond_to?( :content_type ) && response.content_type.match( %r{^text[/]html})
64
- return true if response.is_a?( Array ) && response[1][ 'Content-Type' ] && response[1][ 'Content-Type' ].match( %r{^text[/]html})
65
- false
66
- end
67
-
68
- def add_logger_to_history( logger )
69
- history.unshift logger.dup # pushes logger on beginning of Array
70
- history.slice!( MAX_HISTORY ) # removes item above MAX_HISTORY if there is one
71
- end
72
-
73
- def add_logger_to_response(response, gg )
74
- css_link = %q{<link href="/gg/main.css" type="text/css" rel="stylesheet">}
75
- body = ''
76
- response[2].each { |s| body << s }
77
- if body.sub!( /<!--\s*gg\s*-->/, gg.html ).nil?
78
- body.insert( 0, gg.html )
79
- end
80
- if body.sub!( /<head>/, "<head>#{ css_link }" ).nil?
81
- body.insert( 0, css_link )
82
- end
83
- response[2] = [ body ]
84
- end
85
-
1
+ class GG
2
+
3
+ def initialize( app )
4
+ @app = app
5
+ @history = []
6
+ end
7
+
8
+ MAX_HISTORY = 10
9
+
10
+ attr_reader :app, :history
11
+
12
+ def call( env )
13
+ case env[ 'PATH_INFO' ]
14
+ when '/gg/history'
15
+ render_history( 0 )
16
+ when %r{/gg/history/([0-9])}
17
+ render_history( $~[1].to_i )
18
+ when '/gg/main.css'
19
+ [
20
+ 200,
21
+ { 'Content-Type' => 'text/css' },
22
+ [ File.read(File.join(File.dirname(__FILE__),'public/gg.css'))]
23
+ ]
24
+ else
25
+ render_app( env )
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def render_app( env )
32
+ #ap [ $0, *$LOADED_FEATURES ]
33
+ env[ 'gg' ] = $gg = gg = GG::Logger.new( env )
34
+ response = @app.call( env )
35
+ # response = result.is_a?(Rack::Response) ? result : Rack::Response.new(result[2], result[0], result[1])
36
+ # env[ 'gg' ].response = Rack::Response.new( result )
37
+ # env[ 'gg' ].response = response
38
+ # Logs to the HTML page only if the response type is text/html
39
+ if !gg.empty?
40
+ if response_is_html(response)
41
+ add_logger_to_response( response, gg )
42
+ add_logger_to_history( gg )
43
+ else
44
+ puts
45
+ puts '='*79
46
+ puts env['REQUEST_URI'] || env['PATH_INFO']
47
+ $gg.console_array.each do |item|
48
+ puts item
49
+ end
50
+ end
51
+ end
52
+ response
53
+ end
54
+
55
+ def render_history( i )
56
+ logger = history[i]
57
+ body = logger
58
+ html = GG.render( 'slim/history.slim', body: body, history: history, logger: logger )
59
+ [ 200, { 'Content-Type' => 'text/html' }, [ html ] ]
60
+ end
61
+
62
+ def response_is_html( response )
63
+ return true if response.respond_to?( :content_type ) && response.content_type.match( %r{^text[/]html})
64
+ return true if response.is_a?( Array ) && response[1][ 'Content-Type' ] && response[1][ 'Content-Type' ].match( %r{^text[/]html})
65
+ false
66
+ end
67
+
68
+ def add_logger_to_history( logger )
69
+ history.unshift logger.dup # pushes logger on beginning of Array
70
+ history.slice!( MAX_HISTORY ) # removes item above MAX_HISTORY if there is one
71
+ end
72
+
73
+ def add_logger_to_response(response, gg )
74
+ css_link = %q{<link href="/gg/main.css" type="text/css" rel="stylesheet">}
75
+ body = ''
76
+ response[2].each { |s| body << s }
77
+ if body.sub!( /<!--\s*gg\s*-->/, gg.html ).nil?
78
+ body.insert( 0, gg.html )
79
+ end
80
+ if body.sub!( /<head>/, "<head>#{ css_link }" ).nil?
81
+ body.insert( 0, css_link )
82
+ end
83
+ response[2] = [ body ]
84
+ end
85
+
86
86
  end
@@ -1,8 +1,8 @@
1
- .hi-logger.hi-rounded-corners
2
- .hi-logger-header
3
- div.hi-code-info
4
- = self[ :stack ][0].to_s
5
- .hi-code-line
6
- = self[ :stack ][0].code_line
7
- .hi-logger-output
1
+ .hi-logger.hi-rounded-corners
2
+ .hi-logger-header
3
+ div.hi-code-info
4
+ = self[ :stack ][0].to_s
5
+ .hi-code-line
6
+ = self[ :stack ][0].code_line
7
+ .hi-logger-output
8
8
  == yield
@@ -1,9 +1,9 @@
1
- span.hi-Array
2
- '[
3
- .hi-indent
4
- - self[ :object ].each_with_index do |item,i|
5
- div
6
- == item.to_hi_html( self[ :history ] )
7
- - if i < self[ :object ].length-1
8
- ',
1
+ span.hi-Array
2
+ '[
3
+ .hi-indent
4
+ - self[ :object ].each_with_index do |item,i|
5
+ div
6
+ == item.to_hi_html( self[ :history ] )
7
+ - if i < self[ :object ].length-1
8
+ ',
9
9
  ']
@@ -1,12 +1,12 @@
1
- span.hi-Hash
2
- '{
3
- .hi-indent
4
- - self[ :object ].each_with_index do |key_value,i|
5
- - key, value = *key_value
6
- div
7
- ==' key.to_hi_html( self[ :history ] )
8
- '=&gt;
9
- == value.to_hi_html( self[ :history ] )
10
- - if i < self[ :object ].keys.size-1
11
- ',
1
+ span.hi-Hash
2
+ '{
3
+ .hi-indent
4
+ - self[ :object ].each_with_index do |key_value,i|
5
+ - key, value = *key_value
6
+ div
7
+ ==' key.to_hi_html( self[ :history ] )
8
+ '=&gt;
9
+ == value.to_hi_html( self[ :history ] )
10
+ - if i < self[ :object ].keys.size-1
11
+ ',
12
12
  '}
@@ -1,12 +1,12 @@
1
- link href="/gg/main.css" type="text/css" rel="stylesheet"
2
- div style="margin:10px auto;width:940px;"
3
- .hi-history-pagination
4
- - (0..[self[:history].size-1,9].min).each do |i|
5
- a href="/gg/history/#{ i }"
6
- =i
7
- -if self[ :logger ].nil?
8
- h1.hi-history-heading No Log At This Position in History
9
- -else
10
- h1.hi-history-heading= self[ :logger ].request.path_info
11
- p.hi-history-subheading= self[ :logger ].time
1
+ link href="/gg/main.css" type="text/css" rel="stylesheet"
2
+ div style="margin:10px auto;width:940px;"
3
+ .hi-history-pagination
4
+ - (0..[self[:history].size-1,9].min).each do |i|
5
+ a href="/gg/history/#{ i }"
6
+ =i
7
+ -if self[ :logger ].nil?
8
+ h1.hi-history-heading No Log At This Position in History
9
+ -else
10
+ h1.hi-history-heading= self[ :logger ].request.path_info
11
+ p.hi-history-subheading= self[ :logger ].time
12
12
  == self[ :logger ].html
@@ -1,12 +1,18 @@
1
- h1 GG Demo
2
-
3
- ul
4
- li
5
- a href="/demo"
6
- 'Demonstration
7
- li
8
- a href="/inline_demo"
9
- 'Inline Demonstration
10
- li
11
- a href="/demo.txt"
12
- 'Text Demonstration
1
+ h1 GG Demo
2
+
3
+ ul
4
+ li
5
+ a href="/demo"
6
+ 'Demonstration
7
+ li
8
+ a href="/inline_demo"
9
+ 'Inline Demonstration
10
+ li
11
+ a href="/demo.txt"
12
+ 'Text Demonstration
13
+ li
14
+ a href="/env"
15
+ 'Request Environment
16
+ li
17
+ a href="/limit"
18
+ 'Limit Number of Items to Show
@@ -1,12 +1,12 @@
1
- .hi-logger.hi-rounded-corners
2
- .hi-logger-header
3
- div.hi-code-info
4
- = self[ :stack ][0].to_s
5
- .hi-code-line
6
- = self[ :stack ][0].code_line
7
- .hi-logger-body
8
- - self[ :objects ].each do |object|
9
- .hi-logger-section
10
- .hi-logger-output
11
- == object.to_hi_html( self[ :history ] )
1
+ .hi-logger.hi-rounded-corners
2
+ .hi-logger-header
3
+ div.hi-code-info
4
+ = self[ :stack ][0].to_s
5
+ .hi-code-line
6
+ = self[ :stack ][0].code_line
7
+ .hi-logger-body
8
+ - self[ :objects ].each do |object|
9
+ .hi-logger-section
10
+ .hi-logger-output
11
+ == object.to_hi_html( self[ :history ] )
12
12
  div style="clear:both;"
@@ -1,2 +1,2 @@
1
- span class="#{ self[ :classname ] }"
2
- = self[ :object ].inspect
1
+ span class="#{ self[ :classname ] }"
2
+ = self[ :object ].inspect
@@ -1,10 +1,10 @@
1
- div class="#{ self[ :classname ] }"
2
- = "#<#{ self[ :object ].class }"
3
- .hi-indent
4
- - self[ :object ].instance_variables.each do |key|
5
- div
6
- span.hi-instance-variable
7
- = key
8
- ':
9
- == self[ :object ].instance_variable_get( key ).to_hi_html( self[ :history ] )
1
+ div class="#{ self[ :classname ] }"
2
+ = "#<#{ self[ :object ].class }"
3
+ .hi-indent
4
+ - self[ :object ].instance_variables.each do |key|
5
+ div
6
+ span.hi-instance-variable
7
+ = key
8
+ ':
9
+ == self[ :object ].instance_variable_get( key ).to_hi_html( self[ :history ] )
10
10
  '>
@@ -1,3 +1,3 @@
1
- - id = rand( 1000000000 )
2
- span.hi-string
3
- = self.inspect
1
+ - id = rand( 1000000000 )
2
+ span.hi-string
3
+ = self.inspect
@@ -1,3 +1,3 @@
1
- class GG
2
- VERSION = "0.9.10"
3
- end
1
+ class GG
2
+ VERSION = "0.9.11"
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.10
4
+ version: 0.9.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -91,6 +91,7 @@ files:
91
91
  - lib/gg.rb
92
92
  - lib/gg/core.rb
93
93
  - lib/gg/demo_app.rb
94
+ - lib/gg/history.rb
94
95
  - lib/gg/logger.rb
95
96
  - lib/gg/public/gg.css
96
97
  - lib/gg/rack_plugin.rb