Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails describe HTML content source

I am looking for a gem or elegant way to setup system where I would be able to see where certain HTML content came from. I am working on a big project, and a lot of my times goes determining where a certain piece of HTML content came from. I know you are able to see which layouts, partials are used to render a page in logs but I am looking for something more practical.

An example of this would be.

<!-- ... app/views/layouts/main.html.slim -->
<body>
  <!-- ... app/views/people/index.html.slim -->
  <div class="foo">
    <table clas="items">
      <!-- ... app/views/people/shared/_person.html.slim -->
      <td>
        <span>John Doe</span>
      </td>
    </table>
  </div>
</body>

Where before rendering any partial / page / layout rails render engine would add a comment describing origin.

like image 620
Haris Krajina Avatar asked Nov 07 '16 11:11

Haris Krajina


1 Answers

Maybe this rails_view_annotator gem would be a good starting point:

The Rails View Annotator wraps the rendering of Rails partials with html comments indicating the disk location of the rendered partial.

According to the project README, the gem will output rendered content like this:

<!-- begin: app/views/user/_bio.html.haml (from app/views/user/show.html.haml:4) -->
<div class='bio'>Ed's Bio</div>
<!-- end: app/views/user/_bio.html.haml (from app/views/user/show.html.haml:4) -->

However, it doesn't look like it's in active development so might not be compatible with recent Rails versions, YMMV.

like image 151
wjordan Avatar answered Oct 23 '22 15:10

wjordan