rails_debugging_toolbar 0.0.2
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/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +42 -0
- data/History.txt +5 -0
- data/README.markdown +87 -0
- data/Rakefile +2 -0
- data/lib/ext/action_controller.rb +10 -0
- data/lib/rails_debugging_toolbar/version.rb +3 -0
- data/lib/rails_debugging_toolbar.rb +211 -0
- data/rails_debugging_toolbar.gemspec +23 -0
- metadata +92 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rails_debugging_toolbar (0.0.1)
|
5
|
+
actionpack (>= 2.3.5)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
abstract (1.0.0)
|
11
|
+
actionpack (3.0.3)
|
12
|
+
activemodel (= 3.0.3)
|
13
|
+
activesupport (= 3.0.3)
|
14
|
+
builder (~> 2.1.2)
|
15
|
+
erubis (~> 2.6.6)
|
16
|
+
i18n (~> 0.4)
|
17
|
+
rack (~> 1.2.1)
|
18
|
+
rack-mount (~> 0.6.13)
|
19
|
+
rack-test (~> 0.5.6)
|
20
|
+
tzinfo (~> 0.3.23)
|
21
|
+
activemodel (3.0.3)
|
22
|
+
activesupport (= 3.0.3)
|
23
|
+
builder (~> 2.1.2)
|
24
|
+
i18n (~> 0.4)
|
25
|
+
activesupport (3.0.3)
|
26
|
+
builder (2.1.2)
|
27
|
+
erubis (2.6.6)
|
28
|
+
abstract (>= 1.0.0)
|
29
|
+
i18n (0.5.0)
|
30
|
+
rack (1.2.1)
|
31
|
+
rack-mount (0.6.13)
|
32
|
+
rack (>= 1.0.0)
|
33
|
+
rack-test (0.5.7)
|
34
|
+
rack (>= 1.0)
|
35
|
+
tzinfo (0.3.24)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
actionpack (>= 2.3.5)
|
42
|
+
rails_debugging_toolbar!
|
data/History.txt
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Render Debugging Toolbar for Rails
|
2
|
+
|
3
|
+
If you are looking at the front end of a Rails app and see something you want to
|
4
|
+
work on, there are several ways you might answer the question:
|
5
|
+
|
6
|
+
## Which template is rendering that particular chunk of HTML?
|
7
|
+
|
8
|
+
If you have simple views, logical markup and your URLs map very quickly to
|
9
|
+
views, then you can probably just open your editor and guess pretty much
|
10
|
+
exactly where you need to edit. You're in the Rails happy place, and you
|
11
|
+
probably don't need a tool to help you.
|
12
|
+
|
13
|
+
If you're working on a less-happy Rails application, however, you might have
|
14
|
+
some of the following impediments:
|
15
|
+
|
16
|
+
* hundreds of similarly-named views
|
17
|
+
* complex views with partials within partials
|
18
|
+
* URLs that don't map so easily quickly and obviously to view filenames
|
19
|
+
* markup without obviously unique patterns to search for
|
20
|
+
|
21
|
+
I was in this situation recently; I found myself wishing for something
|
22
|
+
to just tell me where the HTML was coming from.
|
23
|
+
|
24
|
+
# The Render Debugging Toolbar helps you find your view
|
25
|
+
|
26
|
+
There are tools that let you interactively point at the different parts of
|
27
|
+
your page and tell you a bunch of back-end information.
|
28
|
+
|
29
|
+
Drupal has the [Drupal Theme Developer][1], Django has the
|
30
|
+
[Django Debug Toolbar][2], but I couldn't find anything to
|
31
|
+
help me out when I asked Rails the same question of this Rails app:
|
32
|
+
"What is generating that HTML right there?"
|
33
|
+
|
34
|
+
The Render Debugging Toolbar aims to be that tool for Rails.
|
35
|
+
|
36
|
+
# Installation
|
37
|
+
|
38
|
+
Add the following to the "development" group in your Gemfile:
|
39
|
+
gem "rails-render-debugging-toolbar"
|
40
|
+
Bundler will take care of the rest when you run
|
41
|
+
bundle install
|
42
|
+
|
43
|
+
If you're not using Bundler, you won't have a Gemfile, so you'll need
|
44
|
+
to install the gem manually.
|
45
|
+
|
46
|
+
# Usage
|
47
|
+
|
48
|
+
The toolbar needs a lot of extra markup to do its work, so you probably won't
|
49
|
+
want to leave it enabled all the time. You can turn it on for a single request
|
50
|
+
by adding the query parameter "?debug=render" to a request.
|
51
|
+
|
52
|
+
For example, if you are interested in the page:
|
53
|
+
|
54
|
+
http://localhost:3000/examples/new
|
55
|
+
|
56
|
+
You can try the toolbar by visiting the following:
|
57
|
+
|
58
|
+
http://localhost:3000/examples/new?template_debug
|
59
|
+
|
60
|
+
When the toolbar is enabled, you should see a little debugging checkbox overlaid
|
61
|
+
on top of the normal page. Switch it on, and then everything you point at should
|
62
|
+
show a panel of debugging information about what rendered it.
|
63
|
+
|
64
|
+
Simply point at the element you're interested in, and the panel will tell you
|
65
|
+
where the view is.
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
[1]: http://drupal.org/project/devel_themer
|
70
|
+
[2]: https://github.com/robhudson/django-debug-toolbar
|
71
|
+
|
72
|
+
|
73
|
+
# License
|
74
|
+
|
75
|
+
Copyright 2011 Rob Hunter and ThoughtWorks, Inc
|
76
|
+
|
77
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
78
|
+
you may not use this file except in compliance with the License.
|
79
|
+
You may obtain a copy of the License at
|
80
|
+
|
81
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
82
|
+
|
83
|
+
Unless required by applicable law or agreed to in writing, software
|
84
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
85
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
86
|
+
See the License for the specific language governing permissions and
|
87
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
class ActionController::Base
|
3
|
+
private
|
4
|
+
def assign_shortcuts_with_debugging_toolbar_support(request, response)
|
5
|
+
assign_shortcuts_without_debugging_toolbar_support(request, response)
|
6
|
+
response.template.extend(RailsDebuggingToolbar::Extensions::ActionView) if request.parameters.has_key?(:template_debug)
|
7
|
+
end
|
8
|
+
alias_method_chain :assign_shortcuts, :debugging_toolbar_support
|
9
|
+
end
|
10
|
+
|
@@ -0,0 +1,211 @@
|
|
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
|
8
|
+
|
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
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rails_debugging_toolbar/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rails_debugging_toolbar"
|
7
|
+
s.version = RailsDebuggingToolbar::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Rob Hunter"]
|
10
|
+
s.email = ["rhunter@thoughtworks.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Use your browser to find which template rendered some HTML}
|
13
|
+
s.description = %q{This tool helps you dig deeper through the Rails rendering stack using just your browser.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "rails_debugging_toolbar"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "actionpack", ">= 2.3.5"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_debugging_toolbar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Rob Hunter
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-31 00:00:00 +11:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: actionpack
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
- 5
|
34
|
+
version: 2.3.5
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: This tool helps you dig deeper through the Rails rendering stack using just your browser.
|
38
|
+
email:
|
39
|
+
- rhunter@thoughtworks.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- Gemfile
|
49
|
+
- Gemfile.lock
|
50
|
+
- History.txt
|
51
|
+
- README.markdown
|
52
|
+
- Rakefile
|
53
|
+
- lib/ext/action_controller.rb
|
54
|
+
- lib/rails_debugging_toolbar.rb
|
55
|
+
- lib/rails_debugging_toolbar/version.rb
|
56
|
+
- rails_debugging_toolbar.gemspec
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: ""
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
hash: 3
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project: rails_debugging_toolbar
|
87
|
+
rubygems_version: 1.3.7
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Use your browser to find which template rendered some HTML
|
91
|
+
test_files: []
|
92
|
+
|