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