Forum: Ruby on Rails Anyone know a way to create html comments with the names of the views?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
43324b085dc9c3eb8fd9a69e45c7adc2?d=identicon&s=25 mixtli (Guest)
on 2009-04-03 16:05
(Received via mailing list)
I work with a lot of designers.  The question I get all the time is:
Where is the template that displays xyz?  I was thinking it would be
nice if rails would print the name of each template it loads as an
html comment like so:

<!-- LAYOUT: layouts/application.html.erb -->
<html><head>etc..</head>
<body>
<!-- TEMPLATE: blog/index.html.erb -->
<!-- TEMPLATE: blog/_side_bar.html.erb -->
</body>
</html>

Not having to answer these questions all day would really make my day.
I poked around the rails code for a couple hours and don't see an
obvious way.  Does anyone have an idea on how to do this?

Thanks!
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-03 16:08
(Received via mailing list)
On Apr 3, 2:06 pm, mixtli <ronmcclai...@gmail.com> wrote:
> I work with a lot of designers.  The question I get all the time is:
> Where is the template that displays xyz?  I was thinking it would be
> nice if rails would print the name of each template it loads as an
> html comment like so:
>
Seems like you can do this by overriding  render_template in
template.rb. Seems like a fairly handy idea actually, when I have
worked with designers that's definitely a question that has come up
often!

Fred
359b7a7fc263382baee62d91c1e4c25e?d=identicon&s=25 Emanuele Tozzato (mekdigital)
on 2009-04-03 16:15
(Received via mailing list)
NICE! It will be my next plugin! If nil? of course! ;)

iPhonized!
43324b085dc9c3eb8fd9a69e45c7adc2?d=identicon&s=25 mixtli (Guest)
on 2009-04-03 16:51
(Received via mailing list)
For now, I just slapped this in a file in lib and include it in
environment.rb:

module ActionView
  class Template
    def render_template(view, local_assigns = {})
      "<!-- TEMPLATE: #{self.template_path} -->\n" + render(view,
local_assigns)
    rescue Exception => e
      raise e unless filename
      if TemplateError === e
        e.sub_template_of(self)
        raise e
      else
        raise TemplateError.new(self, view.assigns, e)
      end
    end
  end
end


Works in Rails 2.3 anyway.  I'm sure there is a cleaner way, and it
should probably be made into an environment specific config option.
But I'm in a hurry right now.

Thanks for the pointer.
43324b085dc9c3eb8fd9a69e45c7adc2?d=identicon&s=25 mixtli (Guest)
on 2009-04-03 17:12
(Received via mailing list)
Use "<!-- TEMPLATE: #{self.load_path}/#{self.template_path} -->\n"
instead to get the full path from RAILS_ROOT.  Useful if you're
pulling in views from plugins/engines.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-03 19:51
(Received via mailing list)
On 3 Apr 2009, at 15:50, mixtli wrote:

>
>
> For now, I just slapped this in a file in lib and include it in
> environment.rb:
>
For what it's worth i've pluginised this:
http://github.com/fcheung/tattler/tree/master

Fred
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2009-04-03 19:54
(Received via mailing list)
Coming in late, but there's also this..

http://github.com/gwynm/noisy_partials/tree/master
3131fcea0a711e5ad89c8d49cc9253b4?d=identicon&s=25 Julian Leviston (Guest)
on 2009-04-03 20:29
(Received via mailing list)
My designer works it out from the URL and routes file

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/
359b7a7fc263382baee62d91c1e4c25e?d=identicon&s=25 Emanuele Tozzato (mekdigital)
on 2009-04-04 01:57
(Received via mailing list)
*plug-in-ized* and blogged! quick! :)

On Fri, Apr 3, 2009 at 10:50 AM, Frederick Cheung
<frederick.cheung@gmail.com> wrote:
359b7a7fc263382baee62d91c1e4c25e?d=identicon&s=25 Emanuele Tozzato (mekdigital)
on 2009-04-08 02:55
(Received via mailing list)
I'm using it and it's cool, but it should probably check if any layout
statement is present on the controller: if layout is nil then I
probably don't need/want any comment in the template :)

(found this with the :tex view of instiki clone)

thanks 4 the plugin!

On Fri, Apr 3, 2009 at 10:50 AM, Frederick Cheung
<frederick.cheung@gmail.com> wrote:
> For what it's worth i've pluginised this: http://github.com/fcheung/tattler/tree/master


--
Emanuele Tozzato
+1 (619) 549 3230
1985 Sherington Place, #E302
Newport Beach, CA 92663
http://mekdigital.com
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-08 09:16
(Received via mailing list)
On Apr 8, 1:54 am, Emanuele Tozzato <etozz...@gmail.com> wrote:
> I'm using it and it's cool, but it should probably check if any layout
> statement is present on the controller: if layout is nil then I
> probably don't need/want any comment in the template :)
>

More precisely if what it's rendering isn't html it probably shouldn't
be putting html comments in!

Fred
This topic is locked and can not be replied to.