Sunday, March 15, 2009

XCode ERB file highlighting

Ok...  I've been trying to use XCode 3.1.2 to edit Ruby on Rails projects, and choking every time I load up an ERB file.  XCode just doesn't recognize the syntax.  I have, in numerous sessions, searched for the correct solution, and then, this morning, while thinking, I had a brainwave!  Follow this:

  • OS X 10.5/Leopard comes with Ruby on Rails 1.8.5
  • RoR 1.8.5 uses the RHTML file extension
  • I made a RHTML file, and there you go!  It works in XCode
  • I searched through the OS X libraries for the reference, and found it
Here's the answer:
  1. Open this file in a text editor:/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Versions/A/Resources/Standard file types.pbfilespec
  2. Search for rhtml, and you'll find this line:  Extensions = (shtml, jsp, rhtml);
  3. Change it to this: Extensions = (shtml, jsp, rhtml, erb);
In other words, add the ERB file extension to the list of files the developer tools recognize as Embedded Ruby Code.  XCode should now highlight ERB files correctly.

Why didn't one of the Apple developers post this months ago?

5 comments:

Unknown said...

Thanks for that!

Anonymous said...

Just what I was looking for. Thanks!

Anonymous said...

When I do this XCode starts revealing the file in the Finder instead of opening it. Any ideas?

Unknown said...

Sorry... No idea.

You haven't given much information, so no-one can give an informed answer unless they experienced the same problem as you. My guess would be that you, or some software you installed, has changed the default associations for .erb files, or for XCode, and that's a whole other can of worms.

Anonymous said...

.erb is set to open in XCode. Still don't know what happened, but I fixed it by changing the line a few lines above the one mentioned in your article...

Extensions = (htm, html); to Extensions = (htm, html, erb);

Thanks for the article. That's something that's been bugging me for a while now, and along with the Completion Dictionary (http://www.obdev.at/products/completion-dictionary/index.html) XCode can handle Rails development full time.