Skip to content

Instantly share code, notes, and snippets.

@qickstarter
Created November 7, 2012 09:56
Show Gist options
  • Save qickstarter/4030523 to your computer and use it in GitHub Desktop.
Save qickstarter/4030523 to your computer and use it in GitHub Desktop.
" hamlとerbをhtmlに変換する
"
" 変換後のディレクトリを指定することも可能。
" 同じディレクトリに、pathというファイルを作り
" `cat path` -> `../`
" となっていれば、その相対パスディレクトリに保存する
"
function! ConvertHamlToHtml(fileType)
" 設定ファイルを読み込む
let dir_name = expand("%:p:h")
let save_path = ''
if filereadable(dir_name . '/path')
let save_path = readfile("path")[0]
endif
" 2html
let current_file = expand("%")
let target_file = dir_name.'/'.save_path.substitute(current_file, '.'.expand("%:e").'$', '.html', 'g')
" コマンドの分岐
if a:fileType == 'eruby'
" exec ":call vimproc#system('rm " .target_file"')"
let convert_cmd = 'erb ' . current_file . ' > ' . target_file
elseif a:fileType == 'haml'
let convert_cmd = 'haml ' . current_file . ' ' . target_file
endif
echo "convert " . a:fileType . ' to ' . target_file
exec ":call vimproc#system('" . convert_cmd . "')"
endfunction
au Filetype haml nmap <buffer><Leader>R :<C-U>call ConvertHamlToHtml("haml")<CR>
au Filetype eruby nmap <buffer><Leader>R :<C-U>call ConvertHamlToHtml("eruby")<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment