skwpspace yan pritzker’s home on the web

skwpspace is Yan Pritzker's home on the web

Blog :: Photography :: About Me

TwitterCounter for @skwp

Get the news feed
Get updates by email
Follow me on twitter

hello, i'm yan

This blog is about startups, blogging, Ruby On Rails, virtualization and cloud computing, photography, customer service, marketing, ux and design, git, and lots more.

Top Posts

planypus

I'm the founder of Planypus, the place to share your plans!

cohesiveft

Accessible, manageable, virtualized application stacks ready to download or deploy to the cloud!

flickr

smokingThe old man and the accordionBicycle 6x6Eva 6x6Shaffies 6x6Phone Booth Velvia 6x6WynnStar 6x6

Archives

Contact

Reach me at yan at pritzker.ws

Posted
8 October 2006 @ 5am

Tagged
RubyOnRails

Pretty tree display for all your Rails view partials

If you’re developing an app of significant complexity in Rails, you may start getting lost in a sea of partials. Inspired by an idea by my friend and Planypus developer Alex Antonov, I decided to hack together a little script that does a depth first traversal of all your view files looking for partial calls and prints out a map. It currently supports printing this tree in plaintext format or in html format with links to each file. The only thing it can’t really do right now is follow a call from a view to a helper that renders another partial, as the script is relatively dumb and is based on regexes, not ruby syntax parsing.

You invoke the script like so

# use :plain or :html to get output
PartialParser.new(:plain).go(ARGV.first || "app/views")

Here’s a sample output

*app/views/activities/list.rhtml
|---app/views/activities/_activity.rhtml
|------app/views/activities/_expanded_spread_the_word.rhtml
|---------app/views/activities/_new_activity_user_tags.rhtml
|---------app/views/activities/_new_activity_users.rhtml
|------app/views/activities/_rsvp_summary.rhtml

Grab the script here.

I’m sure this script can be improved a whole bunch so please let me know how. Patches are welcome. I’ll get it up on rubyforge after it’s been through a bit of alpha testing. The script is also inefficient in its handling of file descriptors because it opens files at every level as it recurses so that can be improved if necessary, though I’ll doubt it would make much difference for the relatively shallow trees people generally have in their app.


No Comments Yet


There are no comments yet. You could be the first!

Leave a Comment

Tesly Jr.: free pretty reports of your rails test run Quick mongrel load testing trick