[LRUG] Tool to show included partials in RoR?

Richard Livsey richard at livsey.org
Fri Jan 22 02:14:14 PST 2010


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.
Any chance putting what you have on a gist at github?

> 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...
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.

> 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.
I might have a play over the weekend.

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



More information about the Chat mailing list