Commit | Line | Data |
bb2ea7b7 |
1 | " See http://www.vim.org/scripts/script.php?script_id=1318 |
9f4e6b22 |
2 | " Written by Sartak and doy, feel free to add your own! |
bb2ea7b7 |
3 | |
4 | if !exists('loaded_snippet') || &cp |
5 | finish |
6 | endif |
7 | |
f93358a2 |
8 | function! RemoveEmptySuperClass() |
9a5242eb |
9 | s/^extends '<{}>';\n//e |
10 | return @z |
11 | endfun |
12 | |
f93358a2 |
13 | function! RemoveEmptyLine() |
a55ef827 |
14 | s/^\s*<{}>\s*\n//e |
15 | return @z |
16 | endfun |
17 | |
f93358a2 |
18 | function! Snippet(abbr, str) |
9e14e28f |
19 | if type(a:str) == type([]) |
20 | return Snippet(a:abbr, join(a:str, "\n")) |
21 | endif |
22 | let st = g:snip_start_tag |
23 | let et = g:snip_end_tag |
24 | let cd = g:snip_elem_delim |
25 | let str = substitute(a:str, '<{.\{-}\zs:\ze.\{-}}>', cd, "") |
26 | let str = substitute(str, '<{', st, "") |
27 | let str = substitute(str, '}>', et, "") |
28 | exec 'Snippet '.a:abbr.' '.str |
29 | endfunction |
30 | |
f93358a2 |
31 | function! SnippetFile(filename) |
9e14e28f |
32 | let abbr = fnamemodify(a:filename, ':t:r') |
33 | let str = readfile(a:filename) |
34 | return Snippet(abbr, str) |
35 | endfunction |
36 | |
37 | call Snippet('class', [ |
38 | \"package <{ClassName}>;", |
39 | \"use Moose;", |
40 | \"", |
41 | \"extends '<{SuperClass:RemoveEmptySuperClass()}>;", |
42 | \"", |
43 | \"<{}>", |
44 | \"", |
45 | \"__PACKAGE__->meta->make_immutable;", |
46 | \"no Moose;", |
47 | \"", |
48 | \"1;"]) |
49ac30b5 |
49 | call Snippet('role', [ |
50 | \"package <{RoleName}>;", |
51 | \"use Moose::Role;", |
52 | \"", |
53 | \"<{}>", |
54 | \"", |
55 | \"no Moose::Role;", |
56 | \"", |
57 | \"1;"]) |
9e14e28f |
58 | call Snippet('has', [ |
59 | \"has <{attr}> => (", |
60 | \ "is => '<{rw}>',", |
61 | \ "isa => '<{Str}>',", |
a55ef827 |
62 | \ "<{options:RemoveEmptyLine()}>", |
9e14e28f |
63 | \");"]) |
64 | call Snippet('hasl', [ |
65 | \"has <{attr}> => (", |
66 | \ "is => '<{rw}>',", |
67 | \ "isa => '<{Str}>',", |
68 | \ "lazy_build => 1,", |
a55ef827 |
69 | \ "<{options:RemoveEmptyLine()}>", |
9e14e28f |
70 | \");", |
71 | \"", |
a75bdf8d |
72 | \"sub _build_<{attr}> {", |
9e14e28f |
73 | \ "my $self = shift;", |
74 | \ "<{}>", |
75 | \"}"]) |
76 | call Snippet('sub', [ |
77 | \"sub <{name}> {", |
78 | \ "my $self = shift;", |
79 | \ "<{}>", |
80 | \"}"]) |
81 | call Snippet('around', [ |
82 | \"around <{name}> => sub {", |
babbac06 |
83 | \ "my $<{next}> = shift;", |
9e14e28f |
84 | \ "my $self = shift;", |
85 | \ "<{}>", |
86 | \"};"]) |
9ac2672c |
87 | call Snippet('before', [ |
88 | \"before <{name}> => sub {", |
89 | \ "my $self = shift;", |
90 | \ "<{}>", |
91 | \"};"]) |
92 | call Snippet('after', [ |
93 | \"after <{name}> => sub {", |
94 | \ "my $self = shift;", |
95 | \ "<{}>", |
96 | \"};"]) |
bb2ea7b7 |
97 | |
9e14e28f |
98 | "for file in globpath(&rtp, 'snippets/*') |
99 | "call SnippetFile(file) |
100 | "endfor |