mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 13:13:03 +00:00
* textmate_import imports macros just like commands (no body)
* imported the Rails macros, no adjustments * logic in rails-mode/.yas-setup.el supports the "intelligent" migration snippet
This commit is contained in:
parent
626a8be41f
commit
3d0262d67f
@ -48,4 +48,50 @@
|
|||||||
(and (yas/rails-root)
|
(and (yas/rails-root)
|
||||||
(string-match "db/migrate/" default-directory)))
|
(string-match "db/migrate/" default-directory)))
|
||||||
|
|
||||||
|
(defvar yas/rails-intelligent-migration-snippet-bits
|
||||||
|
'((:rename_column . ((:up . "rename_column :${1:table_name}, :${2:column_name}, :${3:new_column_name}$0")
|
||||||
|
(:down . "rename_column :$1, :$3, :$2" )))
|
||||||
|
|
||||||
|
(:rename_column_continue . ((:up . "rename_column :${1:table_name}, :${2:column_name}, :${3:new_column_name}\nmncc$0")
|
||||||
|
(:down . "rename_column :$1, :$3, :$2" )))
|
||||||
|
|
||||||
|
(:rename_table . ((:up . "rename_table :${1:old_table_name}, :${2:new_table_name}$0")
|
||||||
|
(:down . "rename_table :$2, :$1" )))
|
||||||
|
|
||||||
|
(:rename_table_continue . ((:up . "rename_table :${1:old_table_name}, :${2:new_table_name}\nmntc$0")
|
||||||
|
(:down . "rename_table :$2, :$1" )))
|
||||||
|
|
||||||
|
(:add_remove_column . ((:up . "add_column :${1:table_name}, :${2:column_name}, :${3:string}$0")
|
||||||
|
(:down . "remove_column :$1, :$2" )))
|
||||||
|
|
||||||
|
(:add_remove_column_continue . ((:up . "add_column :${1:table_name}, :${2:column_name}, :${3:string}\nmarcc$0")
|
||||||
|
(:down . "remove_column :$1, :$2" )))
|
||||||
|
|
||||||
|
(:create_drop_table . ((:up . "create_table :${1:table_name}, :force . true do |t|\nt.$0\nt.timestamps\nend")
|
||||||
|
(:down . "drop_table :$1" )))
|
||||||
|
|
||||||
|
(:change_change_table . ((:up . "change_table :${1:table_name} do |t|\nt.$0\nend")
|
||||||
|
(:down . "change_table :$1 do |t|\nend" )))
|
||||||
|
|
||||||
|
(:add_remove_index . ((:up . "add_index :${1:table_name}, :${2:column_name}$0")
|
||||||
|
(:down . "remove_index :$1, :$2" )))
|
||||||
|
|
||||||
|
(:add_remove_unique_index . ((:up . "add_index :${1:table_name}, ${2:[:${3:column_name}${4:, :${5:column_name}}]}, :unique . true$0")
|
||||||
|
(:down . "remove_index :$1, :column . $2" )))
|
||||||
|
|
||||||
|
(:add_remove_named_index . ((:up . "add_index :${1:table_name}, [:${2:column_name}${3:, :${4:column_name}}], :name . \"${5:index_name}\"${6:, :unique . true}$0")
|
||||||
|
(:down . "remove_index :$1, :name . :$5" )))))
|
||||||
|
|
||||||
|
|
||||||
|
(defun yas/rails-intelligent-migration-snippet (type)
|
||||||
|
(let* ((start (point))
|
||||||
|
(end (save-excursion
|
||||||
|
(search-forward-regexp "^\s*def\sself\.down" nil 'noerror)))
|
||||||
|
(up (aget (aget yas/rails-intelligent-migration-snippet-bits type) :up))
|
||||||
|
(down (aget (aget yas/rails-intelligent-migration-snippet-bits type) :down))
|
||||||
|
(snippet
|
||||||
|
(and up down start end (concat up
|
||||||
|
(buffer-substring-no-properties start end)
|
||||||
|
"\n" down))))
|
||||||
|
(delete-region start end)
|
||||||
|
(yas/expand-snippet snippet)))
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
# -*- mode: snippet -*-
|
||||||
|
# type: command
|
||||||
|
# key: [press tab twice to generate create_table]
|
||||||
|
# contributor: Translated from TextMate Snippet
|
||||||
|
# name: Drop / Create Table (Second Half)
|
||||||
|
## condition: "meta.rails.migration - meta.rails.migration.create_table - meta.rails.migration.change_table"
|
||||||
|
# --
|
@ -0,0 +1,7 @@
|
|||||||
|
# -*- mode: snippet -*-
|
||||||
|
# type: command
|
||||||
|
# key: mind
|
||||||
|
# contributor: Translated from TextMate Snippet
|
||||||
|
# name: Add / Remove Index
|
||||||
|
## condition: "meta.rails.migration - meta.rails.migration.create_table - meta.rails.migration.change_table"
|
||||||
|
# --
|
@ -0,0 +1,7 @@
|
|||||||
|
# -*- mode: snippet -*-
|
||||||
|
# type: command
|
||||||
|
# key: mind
|
||||||
|
# contributor: Translated from TextMate Snippet
|
||||||
|
# name: Add / Remove Named Index
|
||||||
|
## condition: "meta.rails.migration - meta.rails.migration.create_table - meta.rails.migration.change_table"
|
||||||
|
# --
|
@ -0,0 +1,7 @@
|
|||||||
|
# -*- mode: snippet -*-
|
||||||
|
# type: command
|
||||||
|
# key: mind
|
||||||
|
# contributor: Translated from TextMate Snippet
|
||||||
|
# name: Add / Remove Unique Index
|
||||||
|
## condition: "meta.rails.migration - meta.rails.migration.create_table - meta.rails.migration.change_table"
|
||||||
|
# --
|
@ -0,0 +1,7 @@
|
|||||||
|
# -*- mode: snippet -*-
|
||||||
|
# type: command
|
||||||
|
# key: [press tab twice to generate add_column]
|
||||||
|
# contributor: Translated from TextMate Snippet
|
||||||
|
# name: Remove / Add Column (Second Half)
|
||||||
|
## condition: "meta.rails.migration - meta.rails.migration.create_table - meta.rails.migration.change_table"
|
||||||
|
# --
|
@ -49,7 +49,7 @@ Choice.options do
|
|||||||
short '-f'
|
short '-f'
|
||||||
long '--file=SNIPPET FILE NAME'
|
long '--file=SNIPPET FILE NAME'
|
||||||
desc 'A specific snippet that you want to copy or a glob for various files'
|
desc 'A specific snippet that you want to copy or a glob for various files'
|
||||||
default '*.{tmSnippet,plist}'
|
default '*.{tmSnippet,plist,tmMacro}'
|
||||||
end
|
end
|
||||||
|
|
||||||
option :print_pretty do
|
option :print_pretty do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user