whiny_rendering 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +2 -0
- data/README.rdoc +59 -0
- data/Rakefile +1 -1
- data/init.rb +2 -0
- data/lib/whiny_rendering.rb +56 -7
- data/whiny_rendering.gemspec +3 -3
- metadata +5 -4
data/Manifest
CHANGED
data/README.rdoc
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
= WhinyRendering
|
2
|
+
|
3
|
+
WhinyRendering is a gem for Rails which provides a method for ActionView that displays information about the current controller, action, template being rendered, and a list of all the partials being used in that view as well.
|
4
|
+
|
5
|
+
It's the result of a lot of conversations held around the office about how convenient it would be to have a list, on the page you are viewing in the browser, of the exact template (and partials!) that you are actually seeing rendered in the browser. The idea is to plug it in to a project that you may not be too familiar with, and to cut down on all that annoying searching through the controllers and/or views to figure out what is actually going on in the view.
|
6
|
+
|
7
|
+
This is a really early version. Feel free to send me feedback, ideas, pull requests, what-have-you.
|
8
|
+
|
9
|
+
== Installing
|
10
|
+
|
11
|
+
Assuming you have gemcutter installed (gem install gemcutter):
|
12
|
+
|
13
|
+
gem install whiny_rendering
|
14
|
+
|
15
|
+
Or, if you prefer plugins:
|
16
|
+
|
17
|
+
script/plugin install git://github.com/philcrissman/whiny_rendering.git
|
18
|
+
|
19
|
+
(Haven't tested it as a plugin, feedback welcomed.)
|
20
|
+
|
21
|
+
== Usage
|
22
|
+
|
23
|
+
In your layout (probably application.html.(erb|haml)):
|
24
|
+
|
25
|
+
<%= whiny_rendering %>
|
26
|
+
|
27
|
+
This outputs a div containing the rendering information.
|
28
|
+
|
29
|
+
There are other formats available for use, however:
|
30
|
+
|
31
|
+
You can hide the div, and provide a unobtrusive link that developers can click
|
32
|
+
to toggle its display (using prototype):
|
33
|
+
|
34
|
+
<%= whiny_rendering(:hidden) %>
|
35
|
+
|
36
|
+
Or, if you use jQuery:
|
37
|
+
|
38
|
+
<%= whiny_rendering(:hidden_jquery) %>
|
39
|
+
|
40
|
+
Using :hidden_prototype will also work, in the event that you'd like to be
|
41
|
+
explicit.
|
42
|
+
|
43
|
+
You can also render it as an HTML comment rather than a div:
|
44
|
+
|
45
|
+
<%= whiny_rendering(:comment) %>
|
46
|
+
|
47
|
+
If you use haml, well; you know what to do.
|
48
|
+
|
49
|
+
You probably only want to see this in development mode, so you might rather:
|
50
|
+
|
51
|
+
<%= whiny_rendering if RAILS_ENV=="development" %>
|
52
|
+
|
53
|
+
... or something like that.
|
54
|
+
|
55
|
+
Right now, this will put a div with the relevant information at whatever spot in your template you placed the call to whiny_rendering. It's completely unstyled, and there's no whiny_rendering.css included with the gem (yet!), but the div has the id of #whiny_rendering (hope you weren't using that for something already), so it is very easy to just add a few styles for this div to your default stylesheet.
|
56
|
+
|
57
|
+
== Miscellany
|
58
|
+
|
59
|
+
Author's homepage: http://philcrissman.com
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('whiny_rendering', '0.1.
|
5
|
+
Echoe.new('whiny_rendering', '0.1.1') do |g|
|
6
6
|
g.description = "Add a helper that will be explicitly whiny about what templates and/or partials are being rendered."
|
7
7
|
g.url = "http://github.com/philcrissman/whiny_rendering"
|
8
8
|
g.author = "Phil Crissman"
|
data/init.rb
ADDED
data/lib/whiny_rendering.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module WhinyRendering
|
2
2
|
|
3
|
-
def whiny_rendering
|
3
|
+
def whiny_rendering(format=:div)
|
4
4
|
unless @_memoized__pick_partial_template.nil?
|
5
5
|
partials = @_memoized__pick_partial_template.map do |p|
|
6
6
|
p[1].instance_variable_get(:"@_memoized_path")
|
@@ -8,15 +8,64 @@ module WhinyRendering
|
|
8
8
|
else
|
9
9
|
partials = []
|
10
10
|
end
|
11
|
+
|
12
|
+
output = case format
|
13
|
+
when :div
|
14
|
+
build_div_output(partials)
|
15
|
+
when :hidden
|
16
|
+
build_hidden_prototype_output(partials)
|
17
|
+
when :hidden_prototype
|
18
|
+
build_hidden_prototype_output(partials)
|
19
|
+
when :hidden_jquery
|
20
|
+
build_hidden_jquery_output(partials)
|
21
|
+
when :comment
|
22
|
+
build_comment_output(partials)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def build_div_output(partials, hidden = false)
|
11
28
|
div = <<-EOD
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
29
|
+
<div id='whiny_rendering' #{"style='display:none;'" if hidden} >
|
30
|
+
Controller <strong>#{ @controller.controller_name}</strong> and action <strong>#{ @controller.action_name }</strong>
|
31
|
+
rendering template <strong>#{ @_first_render.instance_variable_get(:"@_memoized_path") }</strong>.
|
32
|
+
#{ "Rendering partials: <strong>" + partials.join(', ') + "</strong>" unless partials.empty? }
|
33
|
+
</div>
|
34
|
+
EOD
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_comment_output(partials)
|
38
|
+
comment = <<-EOD
|
39
|
+
<!--
|
40
|
+
Controller: #{ @controller.controller_name}
|
41
|
+
Action: #{ @controller.action_name}
|
42
|
+
Template: #{ @_first_render.instance_variable_get(:"@_memoized_path")}
|
43
|
+
#{ partials.empty? ? "-->" : "Partials: " + partials.join(', ') + "\n-->" }
|
44
|
+
EOD
|
45
|
+
end
|
46
|
+
|
47
|
+
def build_hidden_jquery_output(partials)
|
48
|
+
output = "<a href='#' id='whiny_rendering_toggle' style='font-size:0.8em;'>Whiny Rendering</a>\n"
|
49
|
+
output << build_div_output(partials, true)
|
50
|
+
output << <<-EOD
|
51
|
+
<script type="text/javascript">
|
52
|
+
jQuery('#whiny_rendering_toggle').toggle(
|
53
|
+
function () {
|
54
|
+
jQuery('#whiny_rendering').show();
|
55
|
+
},
|
56
|
+
function () {
|
57
|
+
jQuery('#whiny_rendering').hide();
|
58
|
+
}
|
59
|
+
);
|
60
|
+
</script>
|
17
61
|
EOD
|
18
62
|
end
|
19
63
|
|
64
|
+
def build_hidden_prototype_output(partials)
|
65
|
+
output = "<a href='javascript:$('whiny_rendering').toggle();' id='whiny_rendering_toggle' style='font-size:0.8em;'>Whiny Rendering</a>\n"
|
66
|
+
output << build_div_output(partials, true)
|
67
|
+
end
|
68
|
+
|
20
69
|
end
|
21
70
|
|
22
71
|
|
@@ -34,4 +83,4 @@ end
|
|
34
83
|
# <% end %>
|
35
84
|
# <% else %>
|
36
85
|
# nil
|
37
|
-
# <% end %>
|
86
|
+
# <% end %>
|
data/whiny_rendering.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{whiny_rendering}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Phil Crissman"]
|
9
|
-
s.date = %q{2010-
|
9
|
+
s.date = %q{2010-07-31}
|
10
10
|
s.description = %q{Add a helper that will be explicitly whiny about what templates and/or partials are being rendered.}
|
11
11
|
s.email = %q{phil@betadeluxe.com}
|
12
12
|
s.extra_rdoc_files = ["README.rdoc", "lib/whiny_rendering.rb"]
|
13
|
-
s.files = ["README.rdoc", "Rakefile", "lib/whiny_rendering.rb", "rails/init.rb", "
|
13
|
+
s.files = ["README.rdoc", "Rakefile", "init.rb", "lib/whiny_rendering.rb", "rails/init.rb", "whiny_rendering.gemspec", "Manifest"]
|
14
14
|
s.homepage = %q{http://github.com/philcrissman/whiny_rendering}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Whiny_rendering", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Phil Crissman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-07-31 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -30,10 +30,11 @@ extra_rdoc_files:
|
|
30
30
|
files:
|
31
31
|
- README.rdoc
|
32
32
|
- Rakefile
|
33
|
+
- init.rb
|
33
34
|
- lib/whiny_rendering.rb
|
34
35
|
- rails/init.rb
|
35
|
-
- Manifest
|
36
36
|
- whiny_rendering.gemspec
|
37
|
+
- Manifest
|
37
38
|
has_rdoc: true
|
38
39
|
homepage: http://github.com/philcrissman/whiny_rendering
|
39
40
|
licenses: []
|