From b2a91d1ea38d46be57a89e52a02cb7940e59eea4 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 12 Mar 2014 13:04:54 +0800 Subject: [PATCH 1/5] add options_for_select add method `options_for_select` from Rails. --- snippets/eruby.snippets | 2 ++ 1 file changed, 2 insertions(+) diff --git a/snippets/eruby.snippets b/snippets/eruby.snippets index 9541835..bc13fcb 100644 --- a/snippets/eruby.snippets +++ b/snippets/eruby.snippets @@ -107,6 +107,8 @@ snippet ntc <%= number_to_currency(${1}) %> snippet ofcfs <%= options_from_collection_for_select ${1:collection}, ${2:value_method}, ${3:text_method}, ${0:selected_value} %> +snippet ofs + <%= options_for_select ${1:collection}, ${2:value_method} %> snippet rf <%= render :file => "${1:file}"${0} %> snippet rt From 9371c648e18c765abdd811725fa57d73e937de00 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 12 Mar 2014 13:35:17 +0800 Subject: [PATCH 2/5] add rails callbak methods --- snippets/ruby.snippets | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/snippets/ruby.snippets b/snippets/ruby.snippets index 1798e08..e4be782 100644 --- a/snippets/ruby.snippets +++ b/snippets/ruby.snippets @@ -749,8 +749,45 @@ snippet mapwo ${1:map}.with_options :${2:controller} => '${3:thing}' do |$3| ${0} end + +# before callback +snippet mbv + before_validation :${0:method} +snippet mbc + before_create :${0:method} +snippet mbu + before_update :${0:method} snippet mbs before_save :${0:method} +snippet mbd + before_destroy :${0:method} + +# after callback +snippet mav + after_validation :${0:method} +snippet maf + after_find :${0:method} +snippet mat + after_touch :${0:method} +snippet mac + after_create :${0:method} +snippet mau + after_update :${0:method} +snippet mas + after_save :${0:method} +snippet mad + after_destroy :${0:method} +snippet mrc + +# around callback + around_create :${0:method} +snippet mru + around_update :${0:method} +snippet mrs + around_save :${0:method} +snippet mrd + around_destroy :${0:method} + snippet mcht change_table :${1:table_name} do |t| ${0} From 7924eee16b4bff6e3ca8745605bfc392e2915af1 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Fri, 14 Mar 2014 23:00:50 +0800 Subject: [PATCH 3/5] change abbreviation to c for controller --- snippets/ruby.snippets | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/snippets/ruby.snippets b/snippets/ruby.snippets index e4be782..4c07578 100644 --- a/snippets/ruby.snippets +++ b/snippets/ruby.snippets @@ -750,42 +750,46 @@ snippet mapwo ${0} end +########################### +# controller snippets # +########################### + # before callback -snippet mbv +snippet cbv before_validation :${0:method} -snippet mbc +snippet cbc before_create :${0:method} -snippet mbu +snippet cbu before_update :${0:method} -snippet mbs +snippet cbs before_save :${0:method} -snippet mbd +snippet cbd before_destroy :${0:method} # after callback -snippet mav +snippet cav after_validation :${0:method} -snippet maf +snippet caf after_find :${0:method} -snippet mat +snippet cat after_touch :${0:method} -snippet mac +snippet cac after_create :${0:method} -snippet mau +snippet cau after_update :${0:method} -snippet mas +snippet cas after_save :${0:method} -snippet mad +snippet cad after_destroy :${0:method} -snippet mrc # around callback +snippet crc around_create :${0:method} -snippet mru +snippet cru around_update :${0:method} -snippet mrs +snippet crs around_save :${0:method} -snippet mrd +snippet crd around_destroy :${0:method} snippet mcht @@ -933,6 +937,8 @@ snippet mct create_table :${1:table_name} do |t| ${0} end +snippet mdt + drop_table :${1:table_name} snippet migration class .. < ActiveRecord::Migration .. def up .. def down .. end class ${1:class_name} < ActiveRecord::Migration def up From dfc456ea492ef757ed1e593de23fc8339402796e Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Sat, 15 Mar 2014 00:32:23 +0800 Subject: [PATCH 4/5] respect the convention --- snippets/ruby.snippets | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/snippets/ruby.snippets b/snippets/ruby.snippets index 4c07578..0083cca 100644 --- a/snippets/ruby.snippets +++ b/snippets/ruby.snippets @@ -756,41 +756,41 @@ snippet mapwo # before callback snippet cbv - before_validation :${0:method} + before_validation :${0:method} snippet cbc - before_create :${0:method} + before_create :${0:method} snippet cbu - before_update :${0:method} + before_update :${0:method} snippet cbs before_save :${0:method} snippet cbd - before_destroy :${0:method} + before_destroy :${0:method} # after callback snippet cav - after_validation :${0:method} + after_validation :${0:method} snippet caf - after_find :${0:method} + after_find :${0:method} snippet cat - after_touch :${0:method} + after_touch :${0:method} snippet cac - after_create :${0:method} + after_create :${0:method} snippet cau - after_update :${0:method} + after_update :${0:method} snippet cas - after_save :${0:method} + after_save :${0:method} snippet cad - after_destroy :${0:method} + after_destroy :${0:method} # around callback snippet crc - around_create :${0:method} + around_create :${0:method} snippet cru - around_update :${0:method} + around_update :${0:method} snippet crs - around_save :${0:method} + around_save :${0:method} snippet crd - around_destroy :${0:method} + around_destroy :${0:method} snippet mcht change_table :${1:table_name} do |t| From fc65844236629e26428dd2f2b4b8aece3e1c3c62 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Mon, 24 Mar 2014 17:51:34 +0800 Subject: [PATCH 5/5] use m as prefix and fix conflicts with other snippets --- snippets/ruby.snippets | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/snippets/ruby.snippets b/snippets/ruby.snippets index 0083cca..95eca9d 100644 --- a/snippets/ruby.snippets +++ b/snippets/ruby.snippets @@ -750,46 +750,46 @@ snippet mapwo ${0} end -########################### -# controller snippets # -########################### +############################### +# model callback snippets # +############################### # before callback -snippet cbv +snippet mbv before_validation :${0:method} -snippet cbc +snippet mbc before_create :${0:method} -snippet cbu +snippet mbu before_update :${0:method} -snippet cbs +snippet mbs before_save :${0:method} -snippet cbd +snippet mbd before_destroy :${0:method} # after callback -snippet cav +snippet mav after_validation :${0:method} -snippet caf +snippet maf after_find :${0:method} -snippet cat +snippet mat after_touch :${0:method} -snippet cac +snippet macr after_create :${0:method} -snippet cau +snippet mau after_update :${0:method} -snippet cas +snippet mas after_save :${0:method} -snippet cad +snippet mad after_destroy :${0:method} # around callback -snippet crc +snippet marc around_create :${0:method} -snippet cru +snippet maru around_update :${0:method} -snippet crs +snippet mars around_save :${0:method} -snippet crd +snippet mard around_destroy :${0:method} snippet mcht @@ -937,8 +937,6 @@ snippet mct create_table :${1:table_name} do |t| ${0} end -snippet mdt - drop_table :${1:table_name} snippet migration class .. < ActiveRecord::Migration .. def up .. def down .. end class ${1:class_name} < ActiveRecord::Migration def up