Saturday, February 3, 2007

jEdit for Ruby on Rails

I received my copy of Agile Web Development with Rails yesterday, and eager to get started, I fired up my long-time favourite code editor, jEdit. Over the past five or six years I've used jEdit for just about every coding task I've ever undertaken, so I decided to try it out for Rails work.

After a couple of hours of downloading plugins and fiddling around with settings, I decided to save my notes here in the hopes that it would save you some time (and so I'd have it written down somewhere for the next time!). I'll assume you're starting from scratch:

  1. Download and install Exuberant Ctags (supports the CTagsSidekick plugin). According to the plugin docs, you need a recent version of this program.

  2. Check the system requirements for jEdit, then download and install the appropriate Java Runtime Environment.

  3. Download and install jEdit.

  4. If all is good, fire up jEdit, then select the menu Plugins -> Plugin Manager.

  5. Select the Install tab, then select and install the following plugins:

    • CodeBrowser: provides a tree view of the document structure

    • Console: integrated command-line with some smarts.

      • Doesn't work so well with applications that don't immediately flush their output buffer, e.g. for tailing WEBrick output.

      • Works well with the ErrorList plugin to highlight runtime errors in Ruby code.



    • CTagsSidekick: another, somewhat slicker document structure browser.

    • ErrorList: as the name implies, displays a list of errors generated by SideKick parsers

    • ProjectViewer: Best of the half-dozen project organization plugins. Some integration with console, e.g. switching the project view as you navigate the source tree in Console, or switch buffers in the main text edit view.

    • RubyPlugin: the big kahuna - makes jEdit a into real Rails locomotive :) I can't say enough about the features it provides, just read up on the author's site.

    • Sidekick: provides the framework for CTagsSidekick to do its magic.



    • XML: provides an HTML parser and tag completion facility for Sidekick



  6. Most of these plugins should install without a hitch. You might have to restart jEdit to let it find and install all of them correctly.

  7. Once all of the plugins are happily installed, select the "Plugin Options..." from the "Plugins" menu, then update the following plugin settings:

    1. Code Browser:

      1. Enter the path to the Ctags executable (e.g. on my system it's C:\Ctags\ctags.exe).



    2. Ctags Sidekick:

      1. Enter the path to the Ctags executable (e.g. on my system it's C:\Ctags\ctags.exe).

      2. Set "Group tags by" to "namespace (multi-level)"

      3. Click "Show icons" if it isn't selected.



    3. SideKick:

      1. In the Parsers section, set "rhtml" mode to the "html" parser, and "ruby" mode to the "ruby" parser.



    4. ProjectViewer:

      1. If you plan to use ProjectViewer to manage your Rails projects, add *.rb, *.rhtml and *.yml to the "Files to import" field of the "General Options" section.



    5. Click "OK" to save the settings and close the Plugin Options window.



  8. Select "Global Options" from the Utilities menu, then update the following settings:

    1. Editing:

      1. Select "html" from the list of modes.

      2. Uncheck "Use default settings".

      3. Add "rhtml" to the "File name glob" field, like so: *.{html,htm,hta,rhtml}



    2. Shortcuts:

      1. Select "Plugin: RubyPlugin" from the "Edit Shortcuts" list, then add the shortcuts as suggested on the jEditPlugin Features Page.



    3. Click "OK" to save the settings and close the "Global Options" window.



  9. Also see the excellent tips on Eadz's Ruby on Rails on jEdit page, and this howto on setting up RoR abbreviations.

  10. Best to restart jEdit so the buffer mode changes take effect.

    • You can confirm the mode is HTML by opening a .rhtml file then checking that HTML mode is displayed in the status bar, e.g. "(html,indent,Cp1252)".

    • Also, select the "Beautify Buffer" command from the menu Plugins -> Beauty. It should tidy up the HTML formatting.

    • Finally, a list of HTML tags should pop up when you type an opening tag bracket "<".

    • Sometimes jEdit "forgets" the mode it's using. Just restart it - it will remember where you were editing the file and which files you had open. Sweet.




That's about it. I welcome any and all corrections or additional tips!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.