Created
September 13, 2016 03:51
-
-
Save chemzqm/f155aec0eff3d09b31eb0f502b7b7934 to your computer and use it in GitHub Desktop.
load lorem from web API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
command! -nargs=* Lorem :call s:LoadLorem(<f-args>) | |
" load lorem with number and optional tag name | |
function! s:LoadLorem(...) | |
let num = get(a:, 1, 1) | |
let html_tag = exists('a:2') ? a:2 : '' | |
let url = 'https://devlorem.kovah.de/api/'.num.'/json' | |
let output = system('curl -s '.url) | |
if v:shell_error && output !=# "" | |
echohl Error | echon output | echohl None | |
return | |
endif | |
let line = getcurpos()[1] | |
let list = copy(webapi#json#decode(output)) | |
if !empty(html_tag) | |
call append(line, map(list, '"<'.html_tag.'>".v:val."</'.html_tag.'>"')) | |
else | |
call append(line, list) | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment