[LRUG] Tool to show included partials in RoR?

Jocke Selin jocke at selincite.com
Fri Jan 22 03:33:31 PST 2010


On 22 Jan 2010, at 10:14, Richard Livsey wrote:
> On Fri, Jan 22, 2010 at 9:50 AM, Jocke Selin <jocke at selincite.com> wrote:
>> On 21 Jan 2010, at 22:20, Richard Livsey wrote:
>>> On Thu, Jan 21, 2010 at 3:25 PM, Jocke Selin <jocke at selincite.com> wrote:
>>>> Hi,
>>>> 
>>>> I'm wondering if there's some nice tool that I could point at a file in the app/views/ dir on my machine and it could render, ascii'ally of graphically, which files are "render partial" from there on. I'd like a tree with the file names, that's pretty much all I'd really need.
>>>> 
>>> A bit of hacking and I've made a simple gem to do just this.
>>> 
>>> $ gem install giraffe
>>> $ giraffe /path/to/app/views/ graph.png
> 
>> That's very impressive. I must say. Sadly I hacked my own version yesterday. Not as fancy as yours, though. It just lists templates recursively and indents based on the "depth".
>> That was pretty much all I needed; to in some minor graphical way (ASCII in my case) show which template is included from which template.
> 
> How did you detect the partials, I'm not particularly keen on the regex I used.

A friend helped me with a regexp - So far in life I've found myself quite regexp incompatible despite reading half of the book before losing it in a drunken taxi ride home.

> Any chance putting what you have on a gist at github?

Right, I knew this day would come. I had to learn GitHub. :)

Here you go.
http://github.com/jocke/Find-Partials


>> However, I do think that what you've done should be part of Rails; If you can generate the DB structure, why can't you generate the structure of Views?! I'm not 100% sure that using an external library should be required though as on my older days I've turned a bit allergic to installing more stuff. Despite that I can see myself installing graphviz just to get a nice "view structure" printed out (I have my DB model taped up on the wall in front of me). :)
> 
> I think going further would be interesting, working out which
> controllers/actions render which templates etc...

One thing that hit me, if this would be for all views, not just single-branch/single-file is that the script could parse and register all files, and then generate relationships between them. This would be good for systems that use a lot of shared templates.

> Removing the requirement on graphviz would be easy, just require that
> for the graphical part and fall back on ASCII if it's not there.

I do like the idea of having a graphical representation of the relationships. However, dependencies are always a bit tricky. :-/ "Damned if you do, damned if you don't"?


>> At the moment it works off one template, doesn't take into account shared templates, nor any variable partials etc.
> 
> Likewise with what I knocked up, I think the next step would be to use
> Rails itself to resolve template paths so that collections and altered
> view_paths come into the mix.

Well, yes, if it'd be a "real" part of Rails, I can see a lot of tweaks like that to make things better. Rake task for example.

> I might have a play over the weekend.

Keep us posted if you make any progress. Please use anything off my code if you find anything useful.

> Cheers for mentioning the problem, it was a fun little challenge.

Thanks for your efforts. :)

/JS


More information about the Chat mailing list