dev_panel 0.2.2 → 0.2.3

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.
@@ -14,22 +14,30 @@ module DevPanel
14
14
  end
15
15
 
16
16
  def ajax_call
17
- '<div id="DevPanel"></div><script type="text/javascript">
18
- $.ajax({
19
- url: "/__DevPanel/main",
20
- success: function(response) {
21
- $("#DevPanel").html(response);' + hide_container +
22
- '
23
- $("#devPanelHider").on("click", function(s) {
24
- $("#devPanelContainer").toggle();
25
- $.get("/__DevPanel/set_options?visible=" + $("#devPanelContainer").is(":visible"));
26
- });
27
- $("#devPanelWindow").draggable({stop: function() {
28
- $.get("/__DevPanel/set_options?top=" + $("#devPanelWindow").position().top + "&left=" + $("#devPanelWindow").position().left);
29
- }});
30
- }
31
- });
32
- </script>'
17
+ <<-html_code
18
+ <div id="DevPanel"></div><script type="text/javascript">
19
+ $.ajax({
20
+ url: "/__DevPanel/main",
21
+ success: function(response) {
22
+ $("#DevPanel").html(response);
23
+ #{hide_container};
24
+ $("#viewTime").click(function(e) {
25
+ $("#partialList").css('top', e.pageY + 10 + 'px');
26
+ $("#partialList").css('left', e.pageX + 10 + 'px');
27
+ $("#partialList").toggle();
28
+ });
29
+ $("#devPanelHider").on("click", function(s) {
30
+ $("#devPanelContainer").toggle();
31
+ $("#partialList").hide();
32
+ $.get("/__DevPanel/set_options?visible=" + $("#devPanelContainer").is(":visible"));
33
+ });
34
+ $("#devPanelWindow").draggable({stop: function() {
35
+ $.get("/__DevPanel/set_options?top=" + $("#devPanelWindow").position().top + "&left=" + $("#devPanelWindow").position().left);
36
+ }});
37
+ }
38
+ });
39
+ </script>
40
+ html_code
33
41
  end
34
42
 
35
43
  def hide_container
@@ -21,78 +21,144 @@ module DevPanel
21
21
  end
22
22
 
23
23
  def css
24
- "<style>
25
- #devPanelWindow {
26
- border-radius: 3px;
27
- margin-bottom: 2px;
28
- box-shadow: 0 0 10px rgba(0, 0, 0, 0.03), 1px 1px 0 rgba(0, 0, 0, 0.05), -1px 1px 0 rgba(0, 0, 0, 0.05), 0 0 0 4px rgba(0, 0, 0, 0.04);
29
- font-family: menlo, lucida console, monospace;
30
- border: 2px solid #000;
31
- }
32
-
33
- #devPanelHider {
34
- background: #F1F1F1;
35
- box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
36
- font-family: arial;
37
- font-size: 12.8px;
38
- overflow: hidden;
39
- padding: 6px 10px;
40
- border: solid 1px #CCC;
41
- border-bottom: 0;
42
- border-top-left-radius: 2px;
43
- border-top-right-radius: 2px;
44
- }
45
-
46
- #devPanelContainer {
47
- font-family: menlo, lucida console, monospace;
48
- background-color: #fff;
49
- box-shadow: inset 3px 3px 3px rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(0, 0, 0, 0.1);
50
- }
51
-
52
- #devPanelContainer td {
53
- font-family: arial;
54
- color: #000;
55
- font-size: 10px;
56
- font-weight: normal;
57
- padding: 8px;
58
- overflow: auto;
59
- }
60
-
61
- #devPanelContainer tr {
62
- background-color: #FACC9B;;
63
- }
64
-
65
- #devPanelContainer td.firstColumn {
66
- width: 60px;
67
- font-weight: bold;
68
- }
69
-
70
- #devPanelContainer .alt {
71
- background-color: #FFF;;
72
- }
73
- </style>"
24
+ <<-css_code
25
+ <style>
26
+ #devPanelWindow {
27
+ border-radius: 3px;
28
+ margin-bottom: 2px;
29
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.03), 1px 1px 0 rgba(0, 0, 0, 0.05), -1px 1px 0 rgba(0, 0, 0, 0.05), 0 0 0 4px rgba(0, 0, 0, 0.04);
30
+ font-family: menlo, lucida console, monospace;
31
+ border: 2px solid #000;
32
+ }
33
+
34
+ #devPanelHider {
35
+ background: #F1F1F1;
36
+ box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
37
+ font-family: arial;
38
+ font-size: 12.8px;
39
+ overflow: hidden;
40
+ padding: 6px 10px;
41
+ border: solid 1px #CCC;
42
+ border-bottom: 0;
43
+ border-top-left-radius: 2px;
44
+ border-top-right-radius: 2px;
45
+ }
46
+
47
+ #devPanelContainer {
48
+ font-family: menlo, lucida console, monospace;
49
+ background-color: #fff;
50
+ box-shadow: inset 3px 3px 3px rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(0, 0, 0, 0.1);
51
+ }
52
+
53
+ #devPanelContainer td {
54
+ font-family: arial;
55
+ color: #000;
56
+ font-size: 10px;
57
+ font-weight: normal;
58
+ padding: 8px;
59
+ overflow: auto;
60
+ }
61
+
62
+ #devPanelContainer tr {
63
+ background-color: #FACC9B;;
64
+ }
65
+
66
+ #devPanelContainer td.firstColumn {
67
+ width: 60px;
68
+ font-weight: bold;
69
+ }
70
+
71
+ #devPanelContainer .alt {
72
+ background-color: #FFF;
73
+ }
74
+
75
+ #viewTime {
76
+ font-size: 10px;
77
+ text-decoration: underline;
78
+ }
79
+
80
+ #partialList {
81
+ position: absolute;
82
+ top: 0px;
83
+ left: 0px;
84
+ background: #F1F1F1;
85
+ border: 2px solid #000;
86
+ background-color: #fff;
87
+ box-shadow: inset 3px 3px 3px rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(0, 0, 0, 0.1);
88
+ font-family: arial;
89
+ font-size: 10px;
90
+ overflow: hidden;
91
+ padding: 6px 10px;
92
+ border-top-left-radius: 2px;
93
+ border-top-right-radius: 2px;
94
+ display: none;
95
+ z-index: 1;
96
+ }
97
+ </style>
98
+ css_code
74
99
  end
75
100
 
76
101
  def html_containers
77
- str = '<div id="devPanelWindow" style="padding: 3px; color: #000; background-color: #F0F0F5; position: absolute; float: left; top: ' + Stats.top.to_s + 'px; left: ' + Stats.left.to_s + 'px;" >'
78
- str += '<div id="devPanelHider" style="width: 150px; text-align:center; border: solid 1px #fff"><a href="#">Show/Hide Stats</a> / <span style="font-size: 10px">' + Stats.data[:action_controller].duration.round(0).to_s + 'ms</span></div>'
79
- str += '<div id="devPanelContainer" style="width: 300px; padding-top: 20px">'
102
+ <<-html_code
103
+ <div id='partialList'>#{partial_list}</div>
104
+ <div id="devPanelWindow" style="padding: 3px; color: #000; background-color: #F0F0F5; position: absolute; float: left; top: #{Stats.top.to_s}px; left: #{Stats.left.to_s}px;" >
105
+ <div id="devPanelHider" style="width: 150px; text-align:center; border: solid 1px #fff"><a href="#">Show/Hide Stats</a> / <span style="font-size: 10px">#{Stats.data[:action_controller].duration.round(0).to_s}ms</span></div>
106
+ <div id="devPanelContainer" style="width: 300px; padding-top: 20px">
107
+ html_code
108
+ end
109
+
110
+ def stats(symbol)
111
+ Stats.data[:action_controller].payload[symbol]
80
112
  end
81
113
 
82
114
  def html_table
83
- str = '<table style="width: 300px; table-layout: fixed">'
84
- str += "<tr class='alt'><td class='firstColumn'>Total Time:</td> <td>#{Stats.data[:action_controller].duration.round(2).to_s}ms</td></tr>"
85
- controller_time = (Stats.data[:action_controller].duration - Stats.data[:action_controller].payload[:view_runtime])
86
- str += "<tr><td class='firstColumn'>Controller Time:</td> <td> #{controller_time.round(2).to_s}ms</td></tr>"
87
- str += "<tr class='alt'><td class='firstColumn'>View Time:</td> <td>#{Stats.data[:action_controller].payload[:view_runtime].round(2).to_s}ms</td></tr>"
88
- str += "<tr><td class='firstColumn'>Partials Rendered:</td> <td> #{Stats.data[:partial_count] || 0}</td></tr>"
89
- str += "<tr class='alt'><td class='firstColumn'>Response Code:</td> <td> #{Stats.data[:action_controller].payload[:status].to_s}</td></tr>"
90
- str += "<tr><td class='firstColumn'>Controller:</td> <td> #{Stats.data[:action_controller].payload[:controller].to_s}</td></tr>"
91
- str += "<tr class='alt'><td class='firstColumn'>Action:</td> <td> #{Stats.data[:action_controller].payload[:action].to_s}</td></tr>"
92
- str += "<tr><td class='firstColumn'>Method:</td> <td> #{Stats.data[:action_controller].payload[:method].to_s}</td></tr>"
93
- str += "<tr class='alt'><td class='firstColumn'>Params:</td> <td> #{Stats.data[:action_controller].payload[:params]}</td></tr>"
94
- str += "<tr><td class='firstColumn'>Log:</td> <td> #{Stats.data[:log]}</td></tr>"
95
- str += "</table></div></div>"
115
+ controller_time = (Stats.data[:action_controller].duration - stats(:view_runtime))
116
+ table_rows = rowify([
117
+ first_td("Total Time:") + td("#{Stats.data[:action_controller].duration.round(2).to_s}ms"),
118
+ first_td("Controller Time:") + td("#{controller_time.round(2).to_s}ms"),
119
+ first_td("View Time:") + td("#{stats(:view_runtime).round(2).to_s}ms"),
120
+ first_td("Partials Rendered:") + td(partial_count),
121
+ first_td("Response Code:") + td(stats(:status)),
122
+ first_td("Controller:") + td(stats(:controller)),
123
+ first_td("Action:") + td(stats(:action)),
124
+ first_td("Method:") + td(stats(:method)),
125
+ first_td("Params:") + td(stats(:params)),
126
+ first_td("Log:") + td(Stats.data[:log])
127
+ ])
128
+
129
+ "<table style='width: 300px; table-layout: fixed'>#{table_rows}</table></div></div>"
130
+ end
131
+
132
+ def partial_count
133
+ "<div id='viewTime'>#{Stats.data[:partial_count] || 0}</div>"
96
134
  end
135
+
136
+ def partial_list
137
+ str = ""
138
+ Stats.data[:partials].each_pair {|k,v| str << "#{k}: #{Stats.data[:partials][k]}<br>" }
139
+ str
140
+ end
141
+
142
+ def tr(content = "", klass="")
143
+ "<tr class=#{klass}>#{content}</tr>"
144
+ end
145
+
146
+ def td(content = "")
147
+ "<td>#{content}</td>"
148
+ end
149
+
150
+ def first_td(content = "")
151
+ "<td class='firstColumn'>#{content}</td>"
152
+ end
153
+
154
+ def rowify(arr)
155
+ result = ""
156
+ arr.each_with_index do |data, index|
157
+ result += tr(data, index.even? ? "alt" : "")
158
+ puts tr(data, index.even? ? "alt" : "")
159
+ end
160
+ result
161
+ end
162
+
97
163
  end
98
164
  end
@@ -17,6 +17,11 @@ module DevPanel
17
17
  ActiveSupport::Notifications.subscribe('render_partial.action_view') do |*args|
18
18
  Stats.data[:partial_count] ||= 0
19
19
  Stats.data[:partial_count] += 1
20
+ event = ActiveSupport::Notifications::Event.new(*args)
21
+ partial_name = event.payload[:identifier].split("app").last
22
+ Stats.data[:partials] ||= {}
23
+ Stats.data[:partials][partial_name] ||= 0
24
+ Stats.data[:partials][partial_name] += 1
20
25
  end
21
26
 
22
27
  end
@@ -41,8 +41,17 @@ module DevPanel
41
41
 
42
42
  def self.log(log)
43
43
  @@data[:log] ||= ""
44
+ @@data[:log] += "<div style='border-bottom: 1px black solid'>"
44
45
  @@data[:log] += CGI::escapeHTML("#{log}")
45
- @@data[:log] += "<br>--------------<br>"
46
+ @@data[:log] += "</div>"
46
47
  end
48
+
49
+ def self.time
50
+ start = Time.now
51
+ yield
52
+ time_spent = ((Time.now - start)*1000).round(2)
53
+ self.log("Time Elapsed: #{time_spent}ms")
54
+ end
55
+
47
56
  end
48
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev_panel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-09 00:00:00.000000000 Z
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A panel that appears in the browser to provide stats on page load times
15
15
  and other debugging information for Rails 3