Dr Nic

Post-Halloween RadRails trick – all TextMate snippets available

Textmate Snippets to Radrails

HTML snippets
Ruby snippets

I tease myself with things I can’t have – like watching TextMate demo videos. One wonderful video shows a test-driven design demonstration by James Edward Gray II where he used Textmate snippets to generate the various assert statements. For example:

ase => assert_equal(expected, actual)
asn => assert_nil(instance)
asm => assert_match(/expected_pattern/, actual_string)

I’d been using Corban Brook’s templates but they didn’t include any assert or migration templates. And I wanted them without having to spend $3049 on TextMate [1]

This made me cranky

Solution 1: Learn Emacs. Setting up Emacs with all the modules you’ll need is a non-trival exercise. That is, put aside a day or so and don’t expect to be finished when time runs out. Plus, a version of GNU Emacs for Windows hasn’t been released since 2005. Not a lot of OSS love there.

Solution 2: Offer to build Textmate for Windows. I’m sure I read once that the Textmate author was open to porting of Textmate to Windows. That must be the past, because their website claims very strongly that there will never be a port:

countless requests for both a Windows and Linux port, but TextMate remains exclusive for the Mac, and that is how we like it!

That’s just lazy if you ask me.

Solution 3: Port Textmate’s snippet libraries (bundles) over to RadRails. Textmate has a more powerful syntax for its snippets than RadRails has for its templates (a limitation inherited from Eclipse), but SUCCESS! On the 31st of October – the day when Textmate was lauded around the blogosphere for its Halloween theme, I ported all their snippets into RadRails. OoooOOOOHHH spooooky.

You can now access the latest and greatest in templates/snippets for Radrails, for Ruby/Rails and RHTML (or click on the yellow boxes at the top).


  1. Download the two template XML files.
  2. Open RadRails
  3. Go to Windows > Preferences > Ruby > Editor > Templates, to see the list of included templates
  4. Click on any template, and press Ctrl-A to select them all.
  5. Click on Remove, to delete them all
  6. Click Import…, select the file ruby-rr-templates.xml
  7. Change to Rails > Editiors > RHTML Editor > RHTML Templates
  8. Remove all the current templates
  9. Click Import…, select the file rhtml-rr-templates.xml
  10. Press Ok to close the dialog and you’re done

Too difficult? The next release of RadRails will include these new templates.

How to use templates/snippets?

You can peruse a textmate-snippets-cheat-sheet, but really, spend 20 minutes looking through the template lists in RadRails. The name of the template is the text you type into the editor to activate the template.

So, the name of assert_equals is ase. So, type ase and press CTRL-SPACE, and a list of options pops up. Press return on the selected option.

Want to see all available assert_* templates? Type as and CTRL-SPACE and there they are. Nifty.


The RadRails guys are going to host these templates to allow anonymous access to make submitting patches relatively easy (if you know how to wield SVN). In future perhaps there will be a nice website for collaboratively sharing and downloading updates to templates.

Templates for JavaScript and CSS

I’ve put in a request for adding template support for JS and CSS as I have ported the JavaScript+CSS bundles as well. We just need a UI to import them into RadRails.

[1] TextMate is 39 euros = $49 at the moment. Plus $3000 for a new Mac.

Related posts:

  1. Validate and Save your Ruby in TextMate – with secret Rubinus superpowers In some TextMate bundles, if you save a file it...
  2. Using Ruby within TextMate snippets and commands I didn’t know you could run Ruby within TextMate snippets....
  3. TextMate bundles for Merb If you are using TextMate (OS X) or E Text...
  4. Writing C extensions in RubyGems using newgem generators (plus a free TextMate bundle) Already know C extensions in RubyGems? Cool – then just...
  5. Rails 2.0 TextMate bundle – Tasty Tidbit – respond_to and view navigation The new release of the Rails TextMate bundle is coming...

75 Responses to “Post-Halloween RadRails trick – all TextMate snippets available”

  1. peri says:

    Thanks! This is awesome!
    I have been using rad rails on windows since learning rails…and love it. However, I was on the fence about getting a mac…sweet machine…but not a friendly price. You may have single-handedly saved me from buyer’s remorse!

    It’s great to see these advances that helps those of us developing on win machines. This makes it that much easier to have ruby/rails integrate a little easier into the workplace. Where I work is pretty cool….but not cool enough to sport us all 17″ macBook pros with 3G ram (droool).

  2. Dr Nic says:

    @self – perhaps I should ask for % of Mac purchase price as a donation towards the “Dr Nic’s son’s nappy/diaper program”.

    @peri – my wife single-handedly saves me from buyer’s remose with key phrases like “you don’t need one of those”, and “but you’ve already got two laptops” (forgetting as necessary that one is hers).

  3. zerohalo says:

    Yippee! Thanks, Dr. Nic. The lack of snippets in RadRails (I didn’t even know it could be done at all), was one of the main reasons I was still using JEdit w/Ruby extension (which is great too–nice and fast; but I like the ability to start/stop servers and especially the Eclipse Subversion control that comes with RadRails).

  4. brett says:

    Dr. Nic, you’ve done it again. This is something that I have been meaning to work on, but alas, life has gotten in the way time and time again.
    sudo gem install free_time_multiplier
    Anyway, thanks for the awesome contribution.

  5. dagi3d says:

    thanks for the effort!

  6. Alex MacCaw says:

    Absolutely brilliant! Increased productivity tenfold.

  7. Phil says:

    I ported all the Rails Textmate snippets to Emacs and then promptly failed to ever use them. I dunno; I guess new habits like that are tricky to learn to the point where they get deeply ingrained.

    (You can get the latest GNU Emacs for Windows here: http://www.emacswiki.org/cgi-bin/wiki/CategoryWThirtyTwo Official builds will be available once 22 is released (probably within the month) but CVS is outstandingly stable.)

  8. [...] Per contribuire a velocizzare la scrittura di applicazioni basate su Ruby on Rails, Dr Nic Williams è riuscito a ricreare tutti gli snippet utili di TextMate su Rad Rails. Potete trovare tutte le informazioni utili sul sito di Dr Nic. La prossima versione di Rad Rails li avrà incorporati, ma per il momento ecco una breve guida in italiano per l’installazione degli snippet su Rad Rails ed il successivo utilizzo. [...]

  9. Matte says:

    Thanks for your brilliant effort! My co-worker works on Windows and tomorrow he will be happy for the new snippets!!! Good Work

  10. heri says:

    hi there

    i have ..TM_XHTML>.. all over the place in rhtml files (meta, br, input….). i guess i could make a find all and replace ${TM_XHTML} by /> in the xml files but there must be a setting i should change… thanks if you care to answer me.

    apart from that, i would say this is the most significant contribution i have seen in a month or so for the rails community.

  11. Joram says:

    This is simply brilliant…
    You really raised my productivity!
    Thanks for all the work!

  12. Brad Wilson says:

    Oh very nice. I’ve been putting off creating templates for regular things for a while now. Great work Dr Nic.

  13. haxx says:

    “Solution 2: … That’s just lazy if you ask me.”

    It’s not lazy, it’s elitist. They figured out they could maintain a stronger user base by catering to that “you’re special” feeling Mac users seem to need to get through the day.

    Product A is your product. You are loyal to Product A. Product A is your reward for your loyalty to Product A. You are special because you use Product A.

  14. relaxdiego says:

    Oh great. I just bought a Mac 30 minutes ago. Looks like I’m going to have to give it away now that it’s useless.

  15. Peter Cooper says:

    haxx: Not necessarily. He’s a one-man band, and he might not like developing on Windows. XCode + Objective C is miles away from the Windows alternatives.. and he probably wouldn’t want to use cross-platform kits as they look horrendous on almost every system.

  16. Dr Nic says:

    @heri – yeah some of the Textmate keywords could be better converted into something meaningful. Others could be cleaned up. When we move them to SVN it will be easier for everyone to export + create patches of improvements.

    @haxx – I could have summarised differently, but it is essentially surprising to declare you will not port a program over to a desktop env on 90-95% of machines. As Peter said, he’s a one-man band, so its not surprising and indeed clever to focus on one set of technologies.

    Perhaps no one has yet asked him for a license to develop TextMate for Windows version.

  17. Mystilleef says:

    For those of you who use Linux and want a good and simple text editor that does templates, have a look at Scribes.

    http://scribes.sf.net/demo.htm (Flash Demo)

    website: http://scribes.sf.net/

    templates: http://scribes.sf.net/templates.tar.bz2

  18. [...] Dr Nic has ported all TextMate’s snippets over to RadRails which is great for us Windows developers. http://drnicwilliams.com/2006/11/06/post-halloween-radrails-trick-all-textmate-snippets-available/ [...]

  19. Paul says:


  20. Anonymous says:

    RadRails trick – all TextMate snippets available…

    Are you jealous of all the snippet goodness in TextMate, but you’re using RadRails on Windows? Dr. Nic has you covered….

  21. Edgar says:

    Thanks a lot. Recently I’m trying RadRails and your templates makes my life easier

  22. [...] Get your templates and read Dr. Nic’s announcement on his blog. [...]

  23. Ben Kittrell says:

    I think Apple is paying textmate to not release a windows version, just to get railers to buy macs. It’s certainly tempted me from time to time.

    But now I don’t have to worry anymore, thanks to Dr. Nic!

  24. Snippets in RadRails…

    When I started out with Rails, I was using Notepad++ and it served my needs fine. Recently, I made the switch to the excellent RadRails IDE. I’m still learning my way around this Eclipse based tool, but overall I’m very impressed. I jus…

  25. [...] Gracias Dr Nic  por esta fantástica contribución. Seguro que ahorraras muchas horas a todos. Como véis las instrucciones las he reproducido de su página Web. [...]

  26. Brian says:


  27. DR says:

    This is something I’ve been waiting for, thanks for saving me shloads of time. Bravo DR. NIC RIVIERA

  28. Rodney says:

    Nic, I strongly object to this. Other than that, great great work. I might actually try out RadRails again … on my mac ofcourse.

  29. Greg says:

    Dr Nic,

    What’s the best way for us to be alert for any updates to the snippets?

    Great work!

  30. Dr Nic says:

    @greg – Short term – yeah stay tuned here, but I’ll put them on SVN + some nicer mechanism for tracking changes + submitting patches to the raw XML, so we can all continue to contribute new radrails specific templates.

    Fingers crossed also that we get Javascript + CSS support in RR soonish too.

  31. Greg says:

    Tks Nick – excellent

  32. Corban Brook says:

    Great Victory Dr. Nic,

    I’m glad to see you go the distance. I certainly got quite sick of typing out xml after the first 70 or so snippets. After the lazyness set in, I continue adding a few rules here or there for migrations or logger and text unit stuff as i needed them but never released it.

    You have certainly gone above and beyond. pip pip!

    I talked to Matt and Kyle about adding an additional content assist button, CTRL+TAB or so, which would execute the snippet in place without bringing down the content assist drop down.. something i feel as an extra step i dont want to take most of the time.

    CTRL+SPACE is nice when you type a few letters of a template trigger and want to see a list of available options, but textmate triggers are meant to be small 3 – 5 letters long, after using them for a while and get them hammered into your brain it would be nice to avoid that other step. For the while i think the idea is tabled, but the textmate templates have caught on a great deal and i think they may be more inclined to work on that feature in the future.

    Have a nice one.

  33. Dr Nic says:

    @corban – I can now appreciate your original effort even more if you were typing out XML manually! :) If you add a template via the GUI, you can export all the templates via the Export button. But I guess you knew this else you wouldn’t know what the schema was! :)

    All these templates were programmatically generated. The 1st draft took an evening (Oct 31st), it took another 4 evenings or so to get around all the edge cases and vagarities of Eclispe’s Content Assist (names can only have letters, numbers and underscore, but snippet tab completions can have any character it seems). Content Assist won’t trigger for single character names – I’m not sure if i actually fixed this in the templates above though :P

    I’d really like a TAB or Ctrl-Tab key combo. I’m not sure how deeply embedded this sort of behaviour is in Eclipse, so I dare not ask too much :)

    I’d also like to get rid of all the other crap that appears in the Content Assist that isn’t my templates. I initially converted $TM_SELECTED_TEXT -> ${selected_lines} (or whatever the Radrails variable is that is similar) but your template would appear at bottom of a very long list of crap and there was no quick way to get to your template without using the mouse to scroll to the bottom. So I changed them to ${paste} to tell you to paste the original code here :)

    So, getting rid of def, class etc from the inbuilt Content Assist menu would be great, so that only the templates work. A commonly discovered “bug” is that we can’t autocomplete on “def” – you have to autocomplete on “de” and then select “def” from the drop down. Crazy.

    Hopefully templates+Content Assist get some love in the future now that its worth loving them with all our lovely templates.

    BTW – there is a discussion about adding Javascript + CSS template support to Radrails here at the forum

  34. Luke Stark says:

    Am I mistaken are is the “:” busted…

    You know, for setting symbols in hashes.

    : –> :your_symbol => “your_var”

  35. Dr Nic says:

    @luke – yeah a bunch aren’t clean yet and contain names that aren’t value for content assist. Unfortunately, only names can contain [A-Za-z0-9_] chars. What’s a better name for this one?

  36. Luke Stark says:

    How about “hs” for a basic {:item => “value”}?

  37. Dr Nic says:

    @luke – ok, and I duplicated it as ‘hp’ (hash pair) – and I’ll see which one seems more natural for awhile :)

  38. Chris says:

    Great job! It’s kind of fun trying to figure out the shortcuts by typing in abbreviations then CTRL+SPACE.

    Could you add “frt” for form_remote_tag? That would be very handy.
    Keep up the great work.

  39. I was just trying to figure out how much trouble it would be to auto-port TextMate snippets to Emacs. Did you port the snippets manually, or did you create a tool to do it? If the latter, mind sharing your plist XML-processing code? :-D

  40. Dr Nic says:

    @marshall – I wrote a tool. The easy part which is inherently reuseable was the fetch + Hpricot parse of the TextMate snippets.

    The hard part (for RadRails) and possible less reusable was the conversion. RadRails templates aren’t as powerful so the original syntax in each ${…} variable had to be converted to a simple name ${name} or removed all together. Emacs snippets might allow much more power. Infact, perhaps you’d want to go about it the opposite way, and write a parser for the original TM snippets text so it supports the same syntax.

    There is an emacs snippet.el on the web somewhere (“A quick stab at providing a simple template facility” – from the header), but it might provide some target syntax for you to generate.

    Having said all that – the code is at http://drnicwilliams.com/svn/textmate_snippets/trunk I think I turned on anonymous access. If you can’t access it, email me for a copy. The generated files are all in the root. Not a clean place to put them, but I wasn’t expecting visitors :)

  41. [...] Simply swing on over to RadRails and pick up a copy. Then, go to Dr Nic’s excellent template post and follow his instructions for importing his wonderful shortcuts into RR.  The post also describes how to use them. They’re GREAT! You won’t even have to do this in the next version of RadRails, these templates will be included by default! [...]

  42. [...] Cet article est un rapide résumé en français de l’article de Dr Nic Post-Halloween RadRails trick – all TextMate snippets available. [...]

  43. Leslie Viljoen says:

    In 0.7.1 I don’t seem to have this template context:

    Only “ruby” is listed.

    Meaning RadRails ignores my import of the rhtml templates. How can I fix that? If I change the template contexts to “ruby” the import works, but the context is wrong.

  44. Hi,

    I did something similar to this a month or so ago, however, I was wondering what you would think if I modularized them (View templates, test templates, model templates and so on), modularized yours, eliminating dups, and then uploaded to your SVN site?


  45. Leslie Viljoen says:

    After adding your templates and a few of my own, I needed a quick-reference guide. So I exported the templates to another xml file and then ran them through this quick script:

    all = File.new("templates.xml").read
    lines = all.split("<template")
    lines.each do |l|
     if l =~ /name="(.+?)"/
       print $1.ljust(20)
     if l =~/description="(.+?)"/
       puts $1
  46. Dr Nic says:

    @leslie part 1 – did you upload the rhtml ones into the RHTML template section? It is listed under Rails, not Ruby.

    @james – sounds like a great idea. Alternately, go to http://radrailstemplates.com/radrailstemplates and create a ticket there (its not officially released but that should work at the moment) and attach the new files there if you want. Or if you are lazy, email them to me :)

    There isn’t an easy way to import without duplication, but we’ll figure something out in time.

  47. [...] I have started to cleanup the Ruby and RHTML templates previously released. They are now stored on SVN so you can get latest versions. They now have a ticketing system for improvements. They now have a Wiki for everyone to help everyone. [...]

  48. [...] Je ne vais pas refaire le boulot de Nic, qui expliquera le pourquoi du comment mieux que moi. Lire ici. [...]

  49. ColinD says:

    Presently using textmate on my mac, but stuck to corp systems in work, so linux or windows hence radrails. AS I know eclipse and rational, radrails is a natural home, being able to carry the productivity keystrokes from textmate into radrails is great! Thankyou.

    Roll on the integration and improvements :)