rails_debugging_toolbar 0.0.2 → 0.0.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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_debugging_toolbar (0.0.1)
4
+ rails_debugging_toolbar (0.0.3)
5
5
  actionpack (>= 2.3.5)
6
6
 
7
7
  GEM
data/History.txt CHANGED
@@ -1,3 +1,16 @@
1
+ == 0.0.3 (2011-02-14)
2
+ === Bugfixes
3
+ * The rendering output should stay inside HTML <body> tags, so
4
+ as not to trigger quirks mode rendering or any other weirdness.
5
+ * jQuery is loaded automatically in case it's not already present,
6
+ rather than just failing.
7
+
8
+ === New features
9
+ * Works with Rails 3.0 as well as Rails 2.3
10
+ * Better variable inspection -- hashes should show up in table-like things.
11
+ * You can turn off debug-follows-pointer and scroll around the detail
12
+
13
+
1
14
 
2
15
  == 0.0.2 (2011-01-31)
3
16
 
data/README.markdown CHANGED
@@ -65,6 +65,14 @@ Simply point at the element you're interested in, and the panel will tell you
65
65
  where the view is.
66
66
 
67
67
 
68
+ # Dependencies
69
+ The Rails Debugging Toolbar works with Rails 2.3.5 for sure, and it should
70
+ work with Rails 3.0.0 as well.
71
+
72
+ The toolbar also needs jQuery to do its job, and will load jQuery automatically
73
+ if it's not already on the page. One day I would like to make the toolbar work
74
+ with no external dependencies but right now I'm happy with jQuery.
75
+
68
76
 
69
77
  [1]: http://drupal.org/project/devel_themer
70
78
  [2]: https://github.com/robhudson/django-debug-toolbar
@@ -1,211 +1,3 @@
1
- require 'ext/action_controller'
2
- module RailsDebuggingToolbar
3
- module Extensions
4
- module ActionView
5
- def render(options = {}, local_assigns = {}, &block)
6
- actual_output = super(options, local_assigns, &block)
7
- id = next_available_render_id
1
+ require 'action_pack'
2
+ require "rails_debugging_toolbar/action_pack_#{ActionPack::VERSION::MAJOR}_handler"
8
3
 
9
- on_entering_render
10
- record_render_details(id, options, local_assigns)
11
- on_leaving_render
12
-
13
- return debug_log_after_body(actual_output) if at_outer_level_render?
14
-
15
- wrapped_output(actual_output, id)
16
- end
17
-
18
- private
19
- attr_writer :my_render_depth
20
- def render_partial(options = {})
21
- actual_output = super(options)
22
- id = next_available_render_id
23
-
24
- on_entering_render
25
- record_render_details(id, options, {})
26
- on_leaving_render
27
-
28
- wrapped_output(actual_output, id)
29
- end
30
-
31
- def on_entering_render
32
- self.my_render_depth = my_render_depth.succ
33
- end
34
- def on_leaving_render
35
- self.my_render_depth = my_render_depth.pred
36
- end
37
-
38
- def wrapped_output(actual_output, id)
39
- ERB.new(<<-HTML).result(binding)
40
- <span class='render-debug partial' id='render-debug-wrapper-<%= h id %>'>
41
- <%= actual_output %>
42
- </span>
43
- HTML
44
- end
45
-
46
- def debug_log_after_body(actual_output)
47
- debug_log = ERB.new(<<-HTML).result(binding)
48
- <div class='render-debug' id='debug-log'>
49
- <% recorded_render_details.each_pair do |id, stuff| %>
50
- <%
51
- recorded_options = stuff[:options]
52
- locals = recorded_options[:locals] || {}
53
- partial = recorded_options[:partial] || "unknown"
54
- unrecognized_options = recorded_options.reject do |option_name, option_value|
55
- [:locals, :partial].include? option_name
56
- end
57
- %>
58
- <div class="render-debug render-detail" id="render-debug-detail-<%= h id %>">
59
- <h3><label for="render-debug-wrapper-<%= h id %>"><code><%= h partial %></code></label></h3>
60
- <% if locals.any? %>
61
- <h4><label for="render-debug-locals-<%= h id %>">Locals</label></h4>
62
- <dl>
63
- <% locals.each_pair do |local_name, local_value| %>
64
- <dt><%= h local_name %></dt>
65
- <dd><code><%= h local_value.inspect %></code></dd>
66
- <% end %>
67
- </dl>
68
- <% end %>
69
-
70
- <% if unrecognized_options.any? %>
71
- <h4><label for="render-debug-options-<%= h id %>">Other options</label></h4>
72
- <dl>
73
- <% unrecognized_options.each_pair do |option_name, option_value| %>
74
- <dt><%= h option_name %></dt>
75
- <dd><%= h option_value.inspect %></dd>
76
- <% end %>
77
- </dl>
78
- <% end %>
79
- </div>
80
- <% end %>
81
- </div>
82
- <form action="#" class="render-debug debug-show">
83
- <input type="checkbox" id="enable-debug-detail-checkbox" name="render" value="debug" />
84
- <label for="enable-debug-detail-checkbox">Show rendering details</label>
85
- <input type="checkbox" id="debug-follows-cursor-checkbox" name="follow_cursor" value="yes" />
86
- <label for="debug-follows-cursor-checkbox">Show rendering details</label>
87
- </form>
88
- <style type="text/css">
89
- #debug-log {
90
- display: block; position: absolute; top: 0px; right: 0px; top: 0px; width: 300px; z-index: -1000;
91
- background: transparent;
92
- font-family: sans-serif;
93
- text-align: left;
94
- color: #ccc;
95
- border: none;
96
- }
97
- #debug-log.active {
98
- display: block; position: fixed; top: 0px; right: 0px; top: 0px; width: 300px; z-index: 1000;
99
- background: black; opacity: 0.8;
100
- border: thin solid white;
101
- }
102
- #debug-log .render-detail {
103
- display: none;
104
- }
105
- #debug-log .render-detail.active {
106
- display: block;
107
- border-top: thin dashed #777;
108
- padding-bottom: 1ex;
109
- padding-top: 1ex;
110
- }
111
- #debug-log h1,
112
- #debug-log h2,
113
- #debug-log h3,
114
- #debug-log h4,
115
- #debug-log h5,
116
- #debug-log h6
117
- {
118
- font-weight: bold;
119
- display: block;
120
- padding-top: 1ex;
121
- font-size: 20px;
122
- color: white;
123
- }
124
- #debug-log h3
125
- {
126
- color: #f13;
127
- text-align: center;
128
- height: auto;
129
- width: 80%;
130
- padding-left: 1em;
131
- padding-right: 1em;
132
- }
133
- #debug-log code {
134
- white-space: pre;
135
- }
136
- #debug-log dl {
137
- display: block;
138
- }
139
- #debug-log dt {
140
- display: block;
141
- margin-left: 0px;
142
- font-weight: bold;
143
- float: left;
144
- width: 8em;
145
- word-break: break-all;
146
- overflow: hidden;
147
- }
148
- #debug-log dd {
149
- display: block;
150
- margin-left: 2px;
151
- max-height: 4ex;
152
- overflow: hidden;
153
- }
154
- form.debug-show {
155
- display: block; position: fixed; bottom: 0px; left: 0px; width: 100px; z-index: 1000;
156
- background: black; opacity: 1.0;
157
- border: thin solid white;
158
- }
159
- </style>
160
-
161
- <script type="text/javascript">
162
- (function ($) {
163
- $(function() {
164
- var checkbox = $("input#enable-debug-detail-checkbox");
165
-
166
- checkbox.change(function() {
167
- if ($(this).is(':checked')) {
168
- $("#debug-log").addClass("active");
169
- $(".render-debug.partial").hover(function() {
170
- var detail_div = $("label[for=" + this.id + "]").parents("#debug-log .render-detail");
171
- detail_div.addClass("active");
172
- }, function() {
173
- var detail_div = $("label[for=" + this.id + "]").parents("#debug-log .render-detail");
174
- detail_div.removeClass("active");
175
- });
176
- } else {
177
- $("#debug-log").removeClass("active");
178
- $(".render-debug.partial").unbind();
179
- }
180
- });
181
- });
182
- })(jQuery);
183
- </script>
184
- HTML
185
- actual_output.sub("</body>", debug_log + "</body>".html_safe!)
186
- end
187
-
188
- def my_render_depth
189
- @some_render_depth ||= 0
190
- end
191
-
192
- def at_outer_level_render?
193
- (my_render_depth == 0)
194
- end
195
-
196
- def next_available_render_id
197
- @render_id_counter ||= 0
198
- @render_id_counter += 1 # XXX: totally not thread safe
199
- @render_id_counter
200
- end
201
-
202
- def record_render_details(id, options, local_assigns)
203
- recorded_render_details[id] = {:options => options, :local_assigns => local_assigns}
204
- end
205
-
206
- def recorded_render_details
207
- @recorded_render_details ||= {}
208
- end
209
- end
210
- end
211
- end
@@ -1,3 +1,5 @@
1
+ require 'rails_debugging_toolbar/extensions'
2
+ require 'action_pack'
1
3
 
2
4
  class ActionController::Base
3
5
  private
@@ -0,0 +1,7 @@
1
+ require 'rails_debugging_toolbar/extensions'
2
+ require 'action_pack'
3
+
4
+ class ActionController::Base
5
+ include RailsDebuggingToolbar::Extensions::ActionController
6
+ end
7
+
@@ -0,0 +1,254 @@
1
+ require 'sha1'
2
+ module RailsDebuggingToolbar
3
+ module Extensions
4
+ module ActionController
5
+ def view_context
6
+ returning(super) do |view|
7
+ extension_module = ::RailsDebuggingToolbar::Extensions::ActionView
8
+ view.extend(extension_module) unless view.kind_of? extension_module
9
+ end
10
+ end
11
+ end
12
+ module ActionView
13
+ def render(options = {}, local_assigns = {}, &block)
14
+ actual_output = super(options, local_assigns, &block)
15
+ id = next_available_render_id
16
+
17
+ record_render_details(id, options, local_assigns)
18
+
19
+ return debug_log_after_body(actual_output) if actual_output.include? "</body>"
20
+
21
+ wrapped_output(actual_output, id)
22
+ end
23
+
24
+ private
25
+ attr_writer :my_render_depth
26
+ def render_partial(options = {})
27
+ actual_output = super(options)
28
+ id = next_available_render_id
29
+
30
+ on_entering_render
31
+ record_render_details(id, options, {})
32
+ on_leaving_render
33
+
34
+ wrapped_output(actual_output, id)
35
+ end
36
+
37
+ def on_entering_render
38
+ self.my_render_depth = my_render_depth.succ
39
+ end
40
+ def on_leaving_render
41
+ self.my_render_depth = my_render_depth.pred
42
+ end
43
+
44
+ def wrapped_output(actual_output, id)
45
+ open_wrapping = raw("<span class='render-debug partial' id='render-debug-wrapper-#{ h id}'>")
46
+ close_wrapping = raw("</span>")
47
+
48
+ # insert the wrapping spans, but staying inside any <body> / </body>
49
+ output_with_open_wrapping = actual_output.rpartition(/<body\b.*?>/).insert(2, open_wrapping).join
50
+ output_with_both_wrapping = output_with_open_wrapping.partition('</body>').insert(1, close_wrapping).join
51
+
52
+ # open_wrapping + actual_output + close_wrapping
53
+ raw(output_with_both_wrapping)
54
+ end
55
+
56
+ def debug_log_after_body(actual_output)
57
+ debug_log = ERB.new(<<-HTML).result(binding)
58
+ <div class='render-debug' id='debug-log'>
59
+ <% recorded_render_details.each_pair do |id, stuff| %>
60
+ <%
61
+ recorded_options = stuff[:options]
62
+ locals = recorded_options[:locals] || {}
63
+ partial = recorded_options[:partial] || "unknown"
64
+ unrecognized_options = recorded_options.reject do |option_name, option_value|
65
+ [:locals, :partial].include? option_name
66
+ end
67
+ %>
68
+ <div class="render-debug render-detail" id="render-debug-detail-<%= h id %>">
69
+ <h3><label for="render-debug-wrapper-<%= h id %>"><code><%= h partial %></code></label></h3>
70
+ <% if locals.any? %>
71
+ <h4><label for="render-debug-locals-<%= h id %>">Locals</label></h4>
72
+ <%= print_hash_as_html_for_debugging(locals) %>
73
+ <% end %>
74
+
75
+ <% if unrecognized_options.any? %>
76
+ <h4><label for="render-debug-options-<%= h id %>">Other options</label></h4>
77
+ <%= print_hash_as_html_for_debugging(unrecognized_options) %>
78
+ <% end %>
79
+ </div>
80
+ <% end %>
81
+ </div>
82
+ <form action="#" class="render-debug" id="debug-show">
83
+ <input type="checkbox" id="enable-debug-detail-checkbox" name="render" value="debug" accesskey="r" />
84
+ <label for="enable-debug-detail-checkbox">Show rendering details (<kbd>r</kbd)>)</label>
85
+ <input type="checkbox" id="debug-follows-cursor-checkbox" name="follow_cursor" checked="checked" accesskey="f" />
86
+ <label for="debug-follows-cursor-checkbox">Debug follows cursor (<kbd>f</kbd)>)</label>
87
+ </form>
88
+ <style type="text/css">
89
+ #debug-log {
90
+ display: block; position: absolute; top: 0px; right: 0px; top: 0px; width: 300px; z-index: -1000;
91
+ background: transparent;
92
+ font-family: sans-serif;
93
+ text-align: left;
94
+ color: #ccc;
95
+ border: none;
96
+ overflow: hidden;
97
+ height: 4px; /* just enough to know it's there */
98
+ }
99
+ #debug-log.active {
100
+ display: block; position: fixed; top: 0px; right: 0px; top: 0px; width: 300px; z-index: 1000;
101
+ background: rgba(0,0,0,0.8);
102
+ color: #ccc;
103
+ border: thin solid white;
104
+ overflow: auto;
105
+ height: 100%;
106
+ }
107
+ #debug-log .render-detail {
108
+ display: none;
109
+ }
110
+ #debug-log .render-detail.active {
111
+ display: block;
112
+ border-top: thin dashed #777;
113
+ padding-bottom: 1ex;
114
+ padding-top: 1ex;
115
+ }
116
+ #debug-log h1,
117
+ #debug-log h2,
118
+ #debug-log h3,
119
+ #debug-log h4,
120
+ #debug-log h5,
121
+ #debug-log h6
122
+ {
123
+ font-weight: bold;
124
+ display: block;
125
+ padding-top: 1ex;
126
+ font-size: 20px;
127
+ color: white;
128
+ }
129
+ #debug-log h3
130
+ {
131
+ color: #f13;
132
+ text-align: center;
133
+ height: auto;
134
+ width: 80%;
135
+ padding-left: 1em;
136
+ padding-right: 1em;
137
+ }
138
+ #debug-log code {
139
+ white-space: pre;
140
+ }
141
+ #debug-log dl {
142
+ display: block;
143
+ }
144
+ #debug-log dt {
145
+ display: block;
146
+ margin-left: 0px;
147
+ font-weight: bold;
148
+ }
149
+ #debug-log dd {
150
+ display: block;
151
+ margin-left: 2px;
152
+ max-height: 4ex;
153
+ }
154
+ form#debug-show {
155
+ display: block; position: fixed; bottom: 0px; left: 0px; width: 30em; z-index: 1000;
156
+ background: rgba(0,0,0,1.0);
157
+ color: #ccc;
158
+ border: thin solid white;
159
+ }
160
+ </style>
161
+ <script type="text/javascript">//<![CDATA
162
+ // Load JQuery if it's not already present
163
+ if (typeof(jQuery) === 'undefined') {
164
+ document.write('<scr' + 'ipt type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></scr' + 'ipt>');
165
+ }
166
+ // ]>
167
+ </script>
168
+ <script type="text/javascript">//<![CDATA
169
+ (function ($) {
170
+ $(function() {
171
+ var show_bar_checkbox = $("input#enable-debug-detail-checkbox");
172
+ var follow_cursor_checkbox = $("input#debug-follows-cursor-checkbox");
173
+ var should_follow_cursor = $(follow_cursor_checkbox).is(':checked');
174
+
175
+ show_bar_checkbox.change(function() {
176
+ if ($(show_bar_checkbox).is(':checked')) {
177
+ $("#debug-log").addClass("active");
178
+ } else {
179
+ $("#debug-log").removeClass("active");
180
+ $(".render-debug.partial").unbind();
181
+ }
182
+ });
183
+ follow_cursor_checkbox.change(function() {
184
+ should_follow_cursor = $(follow_cursor_checkbox).is(':checked');
185
+ if (should_follow_cursor) {
186
+ // a clean slate for mousing around
187
+ $("#debug-log .render-detail.active").removeClass("active");
188
+ }
189
+ });
190
+ $(".render-debug.partial").hover(function() {
191
+ if (!should_follow_cursor) { return true; }
192
+
193
+ var detail_div = $("label[for=" + this.id + "]").parents("#debug-log .render-detail");
194
+ detail_div.addClass("active");
195
+ }, function() {
196
+ if (!should_follow_cursor) { return true; }
197
+
198
+ var detail_div = $("label[for=" + this.id + "]").parents("#debug-log .render-detail");
199
+ detail_div.removeClass("active");
200
+ });
201
+
202
+ });
203
+ })(jQuery);
204
+ //]>
205
+ </script>
206
+ HTML
207
+ output_with_debug_log = actual_output.sub("</body>", debug_log + raw("</body>"))
208
+ @debug_log_rendered = true
209
+ output_with_debug_log
210
+ end
211
+
212
+ def my_render_depth
213
+ @some_render_depth ||= 0
214
+ end
215
+
216
+ def at_outer_level_render?
217
+ (my_render_depth == 0)
218
+ end
219
+
220
+ def next_available_render_id
221
+ @render_id_counter ||= 0
222
+ @render_id_counter += 1 # XXX: totally not thread safe
223
+ @render_id_counter
224
+ end
225
+
226
+ def record_render_details(id, options, local_assigns)
227
+ recorded_render_details[id] = {:options => options, :local_assigns => local_assigns}
228
+ end
229
+
230
+ def recorded_render_details
231
+ @recorded_render_details ||= {}
232
+ end
233
+
234
+ def print_as_html_for_debugging(subject)
235
+ return h subject.relative_path if subject.respond_to? :relative_path
236
+ return h subject.path if subject.respond_to? :path
237
+ return print_as_html_for_debugging if subject.respond_to? :each_pair
238
+ ERB.new("<code><%= h subject.inspect %></code>").result(binding)
239
+ end
240
+
241
+ def print_hash_as_html_for_debugging(hsh)
242
+ ERB.new(<<-HTML).result(binding)
243
+ <dl>
244
+ <% hsh.each_pair do |key, value| %>
245
+ <dt><%= h key %></dt>
246
+ <dd><%= print_as_html_for_debugging(value) %></code></dd>
247
+ <% end %>
248
+ </dl>
249
+ HTML
250
+ end
251
+
252
+ end
253
+ end
254
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsDebuggingToolbar
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency "actionpack", ">= 2.3.5"
22
+ s.add_dependency "actionpack", ">= 2.3.5", "< 4.0.0"
23
23
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_debugging_toolbar
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rob Hunter
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-31 00:00:00 +11:00
18
+ date: 2011-02-14 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -32,6 +32,14 @@ dependencies:
32
32
  - 3
33
33
  - 5
34
34
  version: 2.3.5
35
+ - - <
36
+ - !ruby/object:Gem::Version
37
+ hash: 63
38
+ segments:
39
+ - 4
40
+ - 0
41
+ - 0
42
+ version: 4.0.0
35
43
  type: :runtime
36
44
  version_requirements: *id001
37
45
  description: This tool helps you dig deeper through the Rails rendering stack using just your browser.
@@ -50,8 +58,10 @@ files:
50
58
  - History.txt
51
59
  - README.markdown
52
60
  - Rakefile
53
- - lib/ext/action_controller.rb
54
61
  - lib/rails_debugging_toolbar.rb
62
+ - lib/rails_debugging_toolbar/action_pack_2_handler.rb
63
+ - lib/rails_debugging_toolbar/action_pack_3_handler.rb
64
+ - lib/rails_debugging_toolbar/extensions.rb
55
65
  - lib/rails_debugging_toolbar/version.rb
56
66
  - rails_debugging_toolbar.gemspec
57
67
  has_rdoc: true