Yesterday I tried radrails, which is quite nice for a free tool. Being a Komodo fan however (thanks to my employer for paying the license) the only obvious advantage for me would be being able to switch between controller and corresponding view.
Because I was getting a bit jealous of this feature in Textmate/RadRails/… I cooked up a way to do the same in Komodo.
How can this work in Komodo ?
When calling external commands (via the Toolbox) in Komodo you can give path + linenumber of current file being edited (amongst others) as parameters. You can start the Komodo binary passing a filename + linenumber, and Komodo is nice enough not to start itself twice or load the same file twice when doing this.
The ‘figuring out what controller/action we’re in and calling the corresponding view‘-part (and vice versa) is handled by a little ruby script. (which could probably be much tighter, but I’m still a ‘ruby nuby’ and if I have to clean it up before publishing it’ll probably never leave my personal Toolbox… so be thankfull I have enough guts and ego to dare publish my dirty code 😉
How to install this script in the Komodo toolbox ?
- Save the script below (let’s call it ‘open_ctrl_view.rb’) wherever you like to save such things.
Remember to chmod +x it to make it executable!
- In open_ctrl_view.rb : Edit the path to your komodo installation, or just put ‘komodo’ if komodo is in your search path.
Edit the shebang to point to the correct ruby version if necessary.
- In komodo: add new command in toolbox. As command, enter ‘open_ctrl_view.rb %F %L’ (include full path to whre you saved open_ctrl_view.rb if necessary)
%F will insert the full path and %L the current line of the file being edited
- Run in: ‘Command Output Tab’ (default option) and I marked ‘Do not open output pane’ below. If necessary you can always switch to the output pane manually if something went wrong.
Add key binding if necessary (warning: this is a bit buggy in Komodo 3.5.2 but should be fixed in 3.5.3)
Windows users: Probably the same as above, except no need for chmod’ing, and you’ll probably need ‘ruby open_ctrl_view.rb %F %L’ instead as command.
Mac users: Aren’t you using Textmate ?
The script (open_ctrl_view.rb)
No guarantees are made. Your head might explode, ladadi ladada, etc.
I was going to include it as text in this post, but even enclosed in the proper tags it looks all funny, so download it here.
If you make nice enhancements: let me know! (what about a similar script that loads the model your cursor is positioned on ? Komodo can also send the word your cursor is on as a parameter)