A collection of Sublime Text snippets useful for writing ERB
Tab Trigger | Before | After |
---|---|---|
lt | <%= link_to $1, $2 %> | <%= link_to("$1", $2) %> |
ltd | None | <%= link_to("$1", $2, method: :delete, data: { confirm: "Are you sure?" } ) %> |
form | <%= form_for(@$1 ) do |f| %> $2 <% end %> |
<%= simple_form_for(@$1 ) do |f| %> $2 <% end %> |
fp | None | <%= f.input $1 %> |
each | <% @$1.each do |$2| %> <% end %> |
|
pct | None | <%# TODO : $1 %> |
lti | None | <%= link_to(${1:root}_path, class: "${2:btn btn-primary}") do %> </i> $0 |
##Installation
These snippets can now be installed via Sublime Package Control. If you do not use package control, simply checkout the source code into Sublime Text's packages directory. The location is system specific:
$ cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/
$ git clone https://github.com/sdlong/ERB-Sublime-Snippets.git ERB\ Snippets
$ cd %APPDATA%/Sublime Text 2/Packages/
$ git clone https://github.com/sdlong/ERB-Sublime-Snippets.git ERB\ Snippets
$ cd ~/.Sublime Text 2/Packages/
$ git clone https://github.com/sdlong/ERB-Sublime-Snippets.git ERB\ Snippets
##Snippets and Bindings
Snippet | Tab Trigger | Output |
---|---|---|
ERB tags | __er__ | `<% %>` |
print ERB tags | __pe__ | `<%= %>` |
print ERB comment | __pc__ | `<%# %>` |
`if` block | __if__ | `<% if %>...<% end %>` |
`if` / `else` block | __ife__ | `<% if %>...<% else %>...<% end %>` |
`else` tag | __else__ | `<% else %>` |
`elsif` tag | __elsif__ | `<% elsif %>` |
`unless` block | __unless__ | `<% unless %>...<% end %>` |
`end` block | __end__ | `<% end %>` |
`submit_tag` helper | __st__ | `<%= submit_tag ..., ... %>` |
`text_field_tag` helper | __tft__ | `<%= text_field_tag ..., ... %>` |
`password_field_tag` helper | __pft__ | `<%= password_field_tag ..., ... %>` |
`label_tag` helper | __lblt__ | `<%= label_tag ..., ... %>` |
`link_to` helper | __lt__ | `<%= link_to ..., ... %>` |
`form_for` helper | __form__ | `<%= form_for(@ ) do |f| %> ... <% end %>` |
`t()` helper | __t__ | `<%= t('@') %>` |
##Questions, Comments, Concerns?
Feel free to submit a pull request with any snippets you would like to add to the project. If you have any problems or suggestions you can contact me on twitter.
##License
Released under WTFPL, Version 2