forked from scrooloose/vimfiles
/
snippets.vim.win32
103 lines (83 loc) · 3.23 KB
/
snippets.vim.win32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
call NERDSnippetsReset()
call NERDSnippetsFromDirectory("~/vimfiles/snippets")
function! s:camelCase(s)
"upcase the first letter
let toReturn = substitute(a:s, '^\(.\)', '\=toupper(submatch(1))', '')
"turn all '_x' into 'X'
return substitute(toReturn, '_\(.\)', '\=toupper(submatch(1))', 'g')
endfunction
function! s:underscore(s)
"down the first letter
let toReturn = substitute(a:s, '^\(.\)', '\=tolower(submatch(1))', '')
"turn all 'X' into '_x'
return substitute(toReturn, '\([A-Z]\)', '\=tolower("_".submatch(1))', 'g')
endfunction
function! s:inRailsEnv()
return filereadable(getcwd() . '/config/environment.rb')
endfunction
function! Snippet_Sweeper()
let class = s:camelCase(substitute(expand("%:t"), '^\(.*\)_sweeper\.rb', '\1', ''))
let instance = s:underscore(class)
return "class <+".class."+>Sweeper < ActionController::Caching::Sweeper\<CR>".
\ "observe <+".class."+>\<CR>\<CR>".
\ "def after_save(<+".instance."+>)\<CR>".
\ "expire_cache(<+".instance."+>)\<CR>".
\ "end\<CR>\<CR>".
\ "def after_destroy(<+".instance."+>)\<CR>".
\ "expire_cache(<+".instance."+>)\<CR>".
\ "end\<CR>\<CR>".
\ "def expire_cache(<+".instance."+>)\<CR>".
\ "expire_page\<CR>".
\ "end\<CR>".
\"end\<CR>"
endfunction
"ruby {{{1
function! Snippet_RubyClassNameFromFilename()
let name = expand("%:t:r")
return s:camelCase(name)
endfunction
function! Snippet_MigrationNameFromFilename()
let name = substitute(expand("%:t:r"), '^.\{-}_', '', '')
return s:camelCase(name)
endfunction
function! Snippet_MigrationNameFromFilename()
let name = substitute(expand("%:t:r"), '^.\{-}_', '', '')
return s:camelCase(name)
endfunction
if s:inRailsEnv()
call NERDSnippetsFromDirectoryForFiletype('~/vimfiles/snippets/ruby-rails', 'ruby')
call NERDSnippetsFromDirectoryForFiletype('~/vimfiles/snippets/ruby-rspec', 'ruby')
else
"create merb snippets
endif
"eruby {{{1
if s:inRailsEnv()
call NERDSnippetsFromDirectoryForFiletype('~/vimfiles/snippets/eruby-rails', 'eruby')
call NERDSnippetsFromDirectoryForFiletype('~/vimfiles/snippets/ruby-rails-rjs', 'javascript')
else
"create merb snippets
endif
call NERDSnippetsFromDirectoryForFiletype('~/vimfiles/snippets/html', 'eruby')
call NERDSnippetsFromDirectoryForFiletype('~/vimfiles/snippets/javascript', 'javascript')
call NERDSnippetsFromDirectoryForFiletype('~/vimfiles/snippets/javascript-jquery', 'javascript')
"xhtml {{{1
call NERDSnippetsFromDirectoryForFiletype('~/vimfiles/snippets/html', 'xhtml')
"php {{{1
call NERDSnippetsFromDirectoryForFiletype('~/vimfiles/snippets/html', 'php')
"java {{{1
function! Snippet_JavaClassNameFromFilename()
return expand("%:t:r")
endfunction
"global {{{1
function! s:start_comment()
return substitute(&commentstring, '^\([^ ]*\)\s*%s\(.*\)$', '\1', '')
endfunction
function! s:end_comment()
return substitute(&commentstring, '^.*%s\(.*\)$', '\1', '')
endfunction
function! Snippet_Modeline()
return s:start_comment() . " vim: set <+settings+>:" . s:end_comment()
endfunction
"call NERDSnippetGlobal("modeline", "\<c-r>=Snippet_Modeline()\<cr>")
" modeline {{{1
" vim: set fdm=marker: