vimrc/sources_non_forked/vim-snippets/UltiSnips/eruby.snippets

238 lines
10 KiB
Text
Raw Normal View History

2014-08-03 22:02:51 +00:00
extends html
priority -50
2012-08-17 03:41:25 +00:00
# TextMate added these variables to cope with changes in ERB handling
# in different versions of Rails -- for instance, Rails 3 automatically
# strips whitespace so that it's no longer necessary to use a form like
# <% end -%>, but if you're still maintaining Rails 2 projects, you
# can't omit the minus sign and get the same behavior.
#
# The following regex replace substitutes the function below for the
# TextMate variable references after the snippets are converted:
#
# /\v\$\{(TM_RAILS_TEMPLATE_([^_]+)_RUBY_([^_\s]+))\}/`!p textmate_var('\1', snip)`/g
#
global !p
def textmate_var(var, snip):
lookup = dict(
TM_RAILS_TEMPLATE_START_RUBY_EXPR = snip.opt('g:tm_rails_template_start_ruby_expr', '<%= '),
TM_RAILS_TEMPLATE_END_RUBY_EXPR = snip.opt('g:tm_rails_template_end_ruby_expr', ' %>'),
TM_RAILS_TEMPLATE_START_RUBY_INLINE = snip.opt('g:tm_rails_template_start_ruby_inline', '<% '),
TM_RAILS_TEMPLATE_END_RUBY_INLINE = snip.opt('g:tm_rails_template_end_ruby_inline', ' %>'),
TM_RAILS_TEMPLATE_END_RUBY_BLOCK = '<% end %>'
)
snip.rv = lookup[var]
return
2012-08-17 03:41:25 +00:00
endglobal
2017-02-11 13:01:38 +00:00
snippet % "<% $0 %>" i
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_INLINE', snip)`$0`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_INLINE', snip)`
endsnippet
2017-02-11 13:01:38 +00:00
snippet = "<%= $0 %>" i
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`$0`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
2012-08-17 03:41:25 +00:00
###########################################################################
# GENERATED FROM get_tm_snippets.py + REGEX REPLACE #
###########################################################################
snippet fi "<%= Fixtures.identify(:symbol) %>"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`Fixtures.identify(:${1:name})`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`$0
endsnippet
2015-12-08 13:20:04 +00:00
snippet ft "form_tag" w
2023-04-01 20:48:04 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_INLINE', snip)`form_tag(${1:action: '${2:update}'}${3:, ${4:${5:class}: '${6:form}'\}}}) do`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
$0
2012-08-17 03:41:25 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)`
endsnippet
2015-12-08 13:20:04 +00:00
snippet ffs "form_for submit 2" w
2023-04-01 20:48:04 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`${1:f}.submit '${2:Submit}'${3:, disable_with: '${4:$2ing...}'}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet f. "f_fields_for (nff)" w
2012-08-17 03:41:25 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_INLINE', snip)`f.fields_for :${1:attribute} do |${2:f}|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_INLINE', snip)`
$0
`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)`
endsnippet
2015-12-08 13:20:04 +00:00
snippet f. "f.checkbox" w
2012-08-17 03:41:25 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.check_box :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
2015-12-08 13:20:04 +00:00
snippet f. "f.file_field" w
2012-08-17 03:41:25 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.file_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
2015-12-08 13:20:04 +00:00
snippet f. "f.hidden_field" w
2012-08-17 03:41:25 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.hidden_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
2015-12-08 13:20:04 +00:00
snippet f. "f.label" w
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.label :${1:attribute}${2:, "${3:${1/[[:alpha:]]+|(_)/(?1: :\u$0)/g}}"}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet f. "f.password_field" w
2012-08-17 03:41:25 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.password_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
2015-12-08 13:20:04 +00:00
snippet f. "f.radio_button" w
2015-03-14 20:02:10 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.radio_button :${1:attribute}, :${2:tag_value}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet f. "f.submit" w
2023-04-01 20:48:04 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.submit "${1:Submit}"${2:, disable_with: '${3:$1ing...}'}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet f. "f.text_area" w
2012-08-17 03:41:25 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.text_area :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
2015-12-08 13:20:04 +00:00
snippet f. "f.text_field" w
2012-08-17 03:41:25 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.text_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
2015-12-08 13:20:04 +00:00
snippet ffe "form_for with errors" w
2012-08-17 03:41:25 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`error_messages_for :${1:model}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`form_for @${2:$1} do |f|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
$0
2012-08-17 03:41:25 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)`
endsnippet
2015-12-08 13:20:04 +00:00
snippet ff "form_for" w
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`form_for @${1:model} do |f|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
$0
2012-08-17 03:41:25 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)`
endsnippet
2015-12-08 13:20:04 +00:00
snippet ist "image_submit_tag" w
2023-04-01 20:48:04 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`image_submit_tag("${1:agree.png}"${2:${3:, id: "${4:${1/^(\w+)(\.\w*)?$/$1/}}"}${5:, name: "${6:${1/^(\w+)(\.\w*)?$/$1/}}"}${7:, class: "${8:${1/^(\w+)(\.\w*)?$/$1/}-button}"}${9:, disabled: ${10:false}}})`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet it "image_tag" w
2023-04-01 20:48:04 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`image_tag "$1${2:.png}"${3:${4:, title: "${5:title}"}${6:, class: "${7:class}"}}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
snippet layout "layout"
2023-04-01 20:48:04 +00:00
layout "${1:template_name}"${2:${3:, only: ${4:[:${5:action}, :${6:action}]}}${7:, except: ${8:[:${9:action}, :${10:action}]}}}
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet jit "javascript_include_tag" w
2023-04-01 20:48:04 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`javascript_include_tag ${1::all}${2:, cache: ${3:true}}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet lt "link_to (name, dest)" w
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", ${2:dest}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet lia "link_to (action)" w
2023-04-01 20:48:04 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", action: "${2:index}"`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet liai "link_to (action, id)" w
2023-04-01 20:48:04 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", action: "${2:edit}", id: ${3:@item}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet lic "link_to (controller)" w
2023-04-01 20:48:04 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", controller: "${2:items}"`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet lica "link_to (controller, action)" w
2023-04-01 20:48:04 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", controller: "${2:items}", action: "${3:index}"`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet licai "link_to (controller, action, id)" w
2023-04-01 20:48:04 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", controller: "${2:items}", action: "${3:edit}", id: ${4:@item}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet linpp "link_to (nested path plural)" w
2017-02-11 13:01:38 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:"${2:link text...}"}, ${3:${10:parent}_${11:child}_path(${12:@}${13:$10})}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet linp "link_to (nested path)" w
2017-02-11 13:01:38 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:"${2:link text...}"}, ${3:${12:parent}_${13:child}_path(${14:@}${15:$12}, ${16:@}${17:$13})}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet lipp "link_to (path plural)" w
2012-08-17 03:41:25 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:"${2:link text...}"}, ${3:${4:model}s_path}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
2015-12-08 13:20:04 +00:00
snippet lip "link_to (path)" w
2017-02-11 13:01:38 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:"${2:link text...}"}, ${3:${12:model}_path(${13:@}${14:$12})}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet lim "link_to model" w
2012-08-17 03:41:25 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:model}.${2:name}, ${3:${4:$1}_path(${14:$1})}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet hide "page.hide (*ids)"
page.hide ${1:"${2:id(s)}"}
endsnippet
snippet ins "page.insert_html (position, id, partial)"
2023-04-01 20:48:04 +00:00
page.insert_html :${1:top}, ${2:"${3:id}"}, ${4:partial: "${5:template}"}
2012-08-17 03:41:25 +00:00
endsnippet
snippet rep "page.replace (id, partial)"
2023-04-01 20:48:04 +00:00
page.replace ${1:"${2:id}"}, ${3:partial: "${4:template}"}
2012-08-17 03:41:25 +00:00
endsnippet
snippet reph "page.replace_html (id, partial)"
2023-04-01 20:48:04 +00:00
page.replace_html ${1:"${2:id}"}, ${3:partial: "${4:template}"}
2012-08-17 03:41:25 +00:00
endsnippet
snippet show "page.show (*ids)"
page.show ${1:"${2:id(s)}"}
endsnippet
snippet tog "page.toggle (*ids)"
page.toggle ${1:"${2:id(s)}"}
endsnippet
snippet vis "page.visual_effect (effect, id)"
page.visual_effect :${1:toggle_slide}, ${2:"${3:DOM ID}"}
endsnippet
snippet rp "render (partial) (rp)"
2023-04-01 20:48:04 +00:00
render partial: "${1:item}"
2012-08-17 03:41:25 +00:00
endsnippet
snippet rpc "render (partial,collection) (rpc)"
2023-04-01 20:48:04 +00:00
render partial: "${1:item}", collection: ${2:@$1s}
2012-08-17 03:41:25 +00:00
endsnippet
snippet rpl "render (partial,locals) (rpl)"
2023-04-01 20:48:04 +00:00
render partial: "${1:item}", locals: { ${2:$1}: ${3:@$1}$0 }
2012-08-17 03:41:25 +00:00
endsnippet
snippet rpo "render (partial,object) (rpo)"
2023-04-01 20:48:04 +00:00
render partial: "${1:item}", object: ${2:@$1}
2012-08-17 03:41:25 +00:00
endsnippet
snippet rps "render (partial,status) (rps)"
2023-04-01 20:48:04 +00:00
render partial: "${1:item}", status: ${2:500}
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet slt "stylesheet_link_tag" w
2023-04-01 20:48:04 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`stylesheet_link_tag ${1::all}${2:, cache: ${3:true}}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
2015-12-08 13:20:04 +00:00
snippet st "submit_tag" w
2023-04-01 20:48:04 +00:00
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`submit_tag "${1:Save changes}"${2:, id: "${3:submit}"}${4:, name: "${5:$3}"}${6:, class: "${7:form_$3}"}${8:, disabled: ${9:false}}${10:, disable_with: "${11:Please wait...}"}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
2012-08-17 03:41:25 +00:00
endsnippet
snippet else "else (ERB)"
2012-08-17 03:41:25 +00:00
<% else %>
$0
2012-08-17 03:41:25 +00:00
endsnippet
snippet lf "link_to_function"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to_function ${1:"${2:Greeting}"}, "${3:alert('Hello world!')}"$4`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
# vim:ft=snippets: