# HG changeset patch # User Ludovic Chabant # Date 1336157482 25200 # Node ID 6185e60279c0ea2e383b3566321bbbdb131018c1 # Parent d09875b9f1000bf8dac7333985fd3f9786ef1344 Added `Pcposturl` command. diff -r d09875b9f100 -r 6185e60279c0 plugin/piecrust.vim --- a/plugin/piecrust.vim Sat Mar 31 11:29:12 2012 -0700 +++ b/plugin/piecrust.vim Fri May 04 11:51:22 2012 -0700 @@ -224,6 +224,59 @@ " }}} +" Pcposturl {{{ + +function! s:PcPostUrl(path) abort + " Get information about the given path. + let l:website = s:piecrust_website() + let l:fullPath = l:website.GetFullPath('_content/posts/' . a:path) + let l:output = l:website.RunCommand('find', '--exact', '--components', l:fullPath) + call s:trace(l:output) + + " Get each bit of info from the command output. + let l:lines = split(l:output, '\n') + let l:components = {} + for line in l:lines + let l:kv = split(line, ': ') + if len(l:kv) != 2 + continue + endif + let l:components[l:kv[0]] = l:kv[1] + endfor + + " Check for errors + if !has_key(l:components, 'year') || + \!has_key(l:components, 'month') || + \!has_key(l:components, 'day') || + \!has_key(l:components, 'slug') + call s:error(join(l:lines, '\n')) + return + endif + + " Print the `pcposturl` command. + let l:posturl = "{{ pcposturl(" + let l:posturl .= l:components['year'] . ", " + let l:posturl .= l:components['month'] . ", " + let l:posturl .= l:components['day'] . ", " + let l:posturl .= "'" . l:components['slug'] . "'" + let l:posturl .= ") }}" + call setreg(v:register, l:posturl) + execute 'normal "' . v:register . 'p' +endfunction + +function! s:FindWebsitePosts(ArgLead, CmdLine, CursorPos) abort + let l:website = s:piecrust_website() + let l:output = l:website.RunCommand('find', '--posts', a:ArgLead) + let l:matches = split(l:output, '\n') + let l:length = strlen('_content/posts/') + call map(l:matches, 'strpart(v:val, ' . l:length . ')') + return l:matches +endfunction + +call s:AddMainCommand("-nargs=? -complete=customlist,s:FindWebsitePosts Pcposturl :call s:PcPostUrl()") + +" }}} + " Autoload Functions {{{ " Rescans the current buffer for setting up PieCrust commands.