aboutsummaryrefslogtreecommitdiff
path: root/autoload/sonictemplate.vim
diff options
context:
space:
mode:
Diffstat (limited to 'autoload/sonictemplate.vim')
-rw-r--r--autoload/sonictemplate.vim14
1 files changed, 13 insertions, 1 deletions
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim
index 229d2cb..f411ada 100644
--- a/autoload/sonictemplate.vim
+++ b/autoload/sonictemplate.vim
@@ -169,9 +169,20 @@ function! sonictemplate#getvar(name) abort
return has_key(s:vars[ft], a:name) ? s:vars[ft][a:name] : ''
endfunction
+function! s:dir() abort
+ let l:name = expand('%:t:r:')
+ if empty(l:name)
+ let l:name = fnamemodify(getcwd(), ':t')
+ endif
+ return substitute(l:name, '[^a-zA-Z0-9]', '_', 'g')
+endfunction
+
function! s:name(default) abort
let l:name = expand('%:t:r:')
- return empty(l:name) ? a:default : l:name
+ if empty(l:name)
+ let l:name = a:default
+ endif
+ return substitute(l:name, '[^a-zA-Z0-9]', '_', 'g')
endfunction
function! sonictemplate#apply(name, mode, ...) abort
@@ -223,6 +234,7 @@ function! sonictemplate#apply(name, mode, ...) abort
let ft = s:get_filetype()
let ft = ft != "" ? ft : "_"
let c = join(readfile(f), "\n")
+ let c = substitute(c, '{{_dir_}}', s:dir(), 'g')
let c = substitute(c, '{{_name_}}', s:name('Main'), 'g')
let c = substitute(c, '{{_name_:\([^}]\+\)}}', '\=s:name(submatch(1))', 'g')
let tmp = c