Easy Way to identify Partials

1 view
Skip to first unread message

mike...@gmail.com

unread,
Oct 12, 2009, 4:29:49 AM10/12/09
to rubyonrails-talk
Hey there,
here we have a bunch of interns, so called marketing specialists and other folks just pushing out more and more layouts, views and partials. Now when theres a SEO wanting to change a link on page A to point to landing page 123 isntead of landing page 234 it can be a pain to jsut find the file where this link is generated.

Do you know of an easy way to identify which part of a page comes from which partial file? Perhaps a plugin adding a border or something?

Greeting Mike

Max Williams

unread,
Oct 12, 2009, 9:08:37 AM10/12/09
to rubyonra...@googlegroups.com
Your log file lists all of the partials that are rendered to build up a
page - is that enough information? mine looks like this for example.

Rendered ratings/_rate (258.6ms)
Rendered resources/_single_resource (268.7ms)
Rendered resources/_resource (276.7ms)
Rendered resources/_property_hyperlinks (1.6ms)
Rendered resources/_note_tag_list (0.8ms)
Rendered taggings/_tags_section (1.4ms)

listing those has highlighted the fact that some of them are very slow,
must go and see if i can optimise them...
--
Posted via http://www.ruby-forum.com/.

mike

unread,
Oct 13, 2009, 4:16:45 PM10/13/09
to rubyonra...@googlegroups.com
Thanks for your. 
I was already aware of the log file. It is OK, but it would be fine if i had some hints in the rendered HTML. 

Something like


<!-- =BEGIN layouts/application.html.erb -->
<head><title>Flux Compensator</title></head>
<body>
<!-- =BEGIN layouts/products.html.erb -->
<h1>Showing you a Product</h1>
<!-- =BEGIN products/show.html.erb -->
Product Name: <b>Flux Compensator</b>
Parts:
<!-- =BEGIN product/_part.html.erb -->
Hypercapacitor Gizmo<br/>
<!-- =END products/_part.html.erb -->
<p>Thank you for your interest in Flux Compensator</p>
<!-- =END products/show.html.erb -->
<a href="/products">Index</a>
<!-- =END layouts/products.html.erb -->
</body>
<!-- =END layouts/application.html.erb -->

It would be lovely if there was a plugin that accomplishes this. I would also appreciate any hint as to how achieve this functionality. 

Thanks, Mike

Greg Donald

unread,
Oct 13, 2009, 5:59:48 PM10/13/09
to rubyonra...@googlegroups.com
On Mon, Oct 12, 2009 at 3:29 AM, <mike...@gmail.com> wrote:
> Do you know of an easy way to identify which part of a page comes from which
> partial file? Perhaps a plugin adding a border or something?

This will add comments to your erb templates:

unless RAILS_ENV == 'production'
module ActionView
module TemplateHandlers
class ERB < TemplateHandler
include Compilable
cattr_accessor :erb_trim_mode
self.erb_trim_mode = '-'
def compile(template)
src = ::ERB.new("<% __in_erb_template=true %>\n<!-- BEGIN #{
template } -->\n#{ template.source}\n<!-- END #{ template } -->\n",
nil, erb_trim_mode, '@output_buffer').src
RUBY_VERSION >= '1.9' ? src.sub(/\A#coding:.*\n/, '') : src
end
end
end
end
end

Mine lives in my environment.rb.


--
Greg Donald
http://destiney.com/

Marnen Laibow-Koser

unread,
Oct 13, 2009, 6:06:02 PM10/13/09
to rubyonra...@googlegroups.com
Greg Donald wrote:
> On Mon, Oct 12, 2009 at 3:29 AM, <mike...@gmail.com> wrote:
>> Do you know of an easy way to identify which part of a page comes from which
>> partial file? Perhaps a plugin adding a border or something?
>
> This will add comments to your erb templates:
>
[...]

Ooh, neat! I'll have to play with that -- thanks for sharing it.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org

mike

unread,
Oct 14, 2009, 4:54:45 AM10/14/09
to rubyonra...@googlegroups.com
Yay, thank you Greg!

Frederick Cheung

unread,
Oct 14, 2009, 5:35:54 AM10/14/09
to Ruby on Rails: Talk

On Oct 13, 9:16 pm, mike <mikez...@gmail.com> wrote:
>
> It would be lovely if there was a plugin that accomplishes this. I would
> also appreciate any hint as to how achieve this functionality.
>

I wrote this a little while ago: http://github.com/fcheung/tattler

Fred

mike

unread,
Oct 16, 2009, 6:20:28 AM10/16/09
to rubyonra...@googlegroups.com
Greg, your solution works great. However, it can interfere with js
templates. So i added <% if request and request.xhr? %> to the
injected code.
Frederick, will look into it when im in the office :)
Greetings

2009/10/13, Greg Donald <gdo...@gmail.com>:
--
Von meinen Mobilgerät aus gesendet

mike

unread,
Oct 16, 2009, 11:01:00 AM10/16/09
to rubyonra...@googlegroups.com
Nice Plugin!
Reply all
Reply to author
Forward
0 new messages