« Web Inspector in Safari 3 | Main | The preview feature and more updates on re-coding innoq.com »

Make TextMate cope with Rails 2.0 filename convention

In Rails 2.0 view templates have an ending like .html.erb, .css.erb or .xml.erb (instead of f.i. .rhtml in Rails 1.2.x). So if you've selected a syntax highlighting in TextMate for - say a .html.erb template, this would apply to all templates with ending .erb (i.e. .css.erb etc.) and that's bad, because you want the .css.erb file to have another syntax highlighting (CSS!).

To fix this, you simply have to do the following:

  1. In the TextMate menu select Bundles -> Bundle Editor -> Edit Languages
  2. Expand the "Ruby On Rails" item
  3. Select "HTML (Rails)"
  4. Replace "fileTypes = ( 'rhtml' );" with "fileTypes = ( 'rhtml', 'html.erb' );"
  5. Redo this for every language you use (i.e. CSS -> css.erb, XML -> xml.erb...) in its corresponding menu
  6. Now you can select a separate highlighting for every .erb extension

(via Google Groups)

Comments (5)

David Flaherty:

Daniel,

Thanks for the helpful post. Still having some problems, though. I've grabbed the latest rails bundle from the TextMate svn respository and followed your directions, but in spite of having deleted the plain '.erb' from HTML (Rails), TextMate still seems to be reading css.erb files with HTML highlighting. I've reloaded the bundles and restarted the program a number of times. Any ideas?

For CSS:

{ scopeName = 'source.css'; comment = ''; fileTypes = ( 'css', 'css.erb' ); etc.

for HTML (Rails): { scopeName = 'text.html.ruby'; fileTypes = ( 'rhtml', 'html.erb' ); foldingStartMarker = '(?x) etc.

Thanks, D

Hi David,

so far everything looks alright with your settings. They are exactly the same as mine; and in my case this works fine.

If you didn't already do this:
Maybe you have to explicitly apply the correct syntax highlighting (CSS) for css.erb files once.
You can do this in the status bar at the bottom. Right next to "column" and "line" display, there's the drop-down menu for syntax highlighting. Open a css.erb file and then choose "CSS" in that menu.
TextMate should then remember the settings for these files.

I hope this will work out for you.

David Flaherty:

Daniel,

Well, I thought that I had done that before to no avail, but it seems to have fixed the problem. Thank you so very, very much! Ahhh, TextMate, how I hate you & how I love you!

  • D
Vern:

I suppose there is no way yet to get ruby syntax in the css.erb file as we do in html.erb?

I checked the bundle editor and without knowing much about it can and it looks like it requires a specific language file set up for this.

Has anyone tackled this yet? I don't think I could fake my way through it. I thought maybe there is a way to apply "both" language types to one format.

Maybe one could combine code fragments of the CSS language and the HTML (Rails) language.
But I'm really not sure if this would work...

And as I don't have that many css.erb files, I haven't tried this myself.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

DanielHi. I'm Daniel Pietzsch and this is my innoQ-Blog. I'm a 26y old student at FH Bochum and working student at innoQ.
In this blog I mainly write about the progress concerning my diploma thesis which will be an in-house application for innoQ based on Ruby on Rails, but some other (geek) stuff might appear here, too.

daniel [dot] pietzsch [alt-L] innoq [dot] com

I recommend

Categories

License

Creative Commons License This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.31