From 65d61396541c563ede37de7abd052453af5e5648 Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 28 Oct 2011 10:22:20 +0900 Subject: add {{_if_:foo;bar;baz}}. --- doc/template-vim.txt | 9 ++++++++- plugin/template.vim | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/template-vim.txt b/doc/template-vim.txt index 0e49f8c..c407eff 100644 --- a/doc/template-vim.txt +++ b/doc/template-vim.txt @@ -167,9 +167,16 @@ Note that I'm using pathogen-vim. |{{_expr_:xxx}}| : expression in vimscript. - For example, "Current Time:|{{_expr_:strftime('%c')}}|" will be + For example: "Current Time:|{{_expr_:strftime('%c')}}|" will be > Current Time: 2011/10/27 20:19:00 +< + |{{_if_:expr;foo;bar}}| : ternary operator + + For example: When today is saturday, + "Today is |{{_if_:strftime('%w')%6;OrdinaryDay;Holiday}}|" will be +> + Today is Holiday < ============================================================================== vim:tw=78:ts=8:ft=help:norl:noet:fen:fdl=0: diff --git a/plugin/template.vim b/plugin/template.vim index a6cbc59..dd742a5 100644 --- a/plugin/template.vim +++ b/plugin/template.vim @@ -70,6 +70,7 @@ function! s:Template(name) abort let val = input(var . ":") let c = substitute(c, '\V{{_input_:'.var.'}}', '\=val', 'g') endfor + let c = substitute(c, '{{_if_:\(.\{-}\);\(.\{-}\)\(;\(.\{-}\)\)\{-}}}', '\=eval(submatch(1))?submatch(2):submatch(4)', 'g') let c = substitute(c, '{{_expr_:\(.\{-}\)}}', '\=eval(submatch(1))', 'g') if len(c) == 0 return @@ -96,8 +97,9 @@ function! s:Template(name) abort if stridx(c, '{{_cursor_}}') silent! call search('{{_cursor_}}', 'w') silent! s/{{_cursor_}}//g - silent! exe "normal! \" endif + silent! exe "normal! \" + startinsert endfunction " vim:ts=4:sw=4:et -- cgit v1.2.3-54-g00ecf