views:

43

answers:

2

I'm using a js.erb template to render some jQuery. When editing an html.erb file in TextMate, I frequently use the convenient key combo, ctrl+>, to create and then toggle the following tags:

<%=  %>
<%  %>
<%-  -%>
<%#  %>

This shortcut doesn't work by default when editing js.erb files. In the Bundle Editor, I found a snippet called "Insert ERb’s <% .. %> or <%= .. %>" under "Ruby". By adding "source.js" to the scope selector I was able to get insertion to work, but when I pressed the key combo multiple times, instead of toggling the tag I got a tag inside of a tag like this:

<%= <%=  %> %>

I've tried changing the scope of the command called "Toggle ERb Tags" but I can't seem to get toggling to work. Any suggestions?

A: 

Your Ruby on Rails Textmate bundle may be outdated due to changes in Ruby 1.9.

Update your tmbundle and this problem should go away.

Raphomet
Thanks for the suggestion, but that didn't solve the problem. I updated both the Ruby on Rails bundle using your link and the Ruby bundle(http://github.com/drnic/ruby-tmbundle). It looks like there are some cool new features, but I'm having the same problem with the tag toggling in js.erb files.
balexand
Ah, sorry to hear that. Upgrading fixed a similar problem for me. I hope you figure out what the problem is!
Raphomet
+1  A: 

One possible reasono why this is the case is that the snippet that generates the angle brackets for you is defined thus:

<%= $0 %>

This puts this text into your source after the tab-trigger occurs. The $0 is a placeholder for the cursor; it's final resting place after the snippet is completed. Since the cursor rests in the middle and this is a simple snippet, repeatedly performing the tab-trigger will nest these brackets.

To achieve what you want, you have to do it in a script. You can use any scripting language as long as you appropriately specify the shebang line. I am not a proficient scripter so I'll try to solve this using pseudocode.

if selected_text
    if no_wrapping_angle_brackets
        surround_with_angle_brackets
    else
        strip_angle_brackets
else
    if no_wrapping_angle_brackets
        surround_with_angle_brackets
    else
        strip_angle_brackets

It's not much but I hope this helps

Yasky