Mercurial > vim-piecrust
comparison plugin/piecrust.vim @ 1:6185e60279c0
Added `Pcposturl` command.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 04 May 2012 11:51:22 -0700 |
parents | d09875b9f100 |
children | af8514b79c04 |
comparison
equal
deleted
inserted
replaced
0:d09875b9f100 | 1:6185e60279c0 |
---|---|
222 | 222 |
223 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:FindWebsiteFiles Pcedit :call s:PcEdit(<bang>0, <f-args>)") | 223 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:FindWebsiteFiles Pcedit :call s:PcEdit(<bang>0, <f-args>)") |
224 | 224 |
225 " }}} | 225 " }}} |
226 | 226 |
227 " Pcposturl {{{ | |
228 | |
229 function! s:PcPostUrl(path) abort | |
230 " Get information about the given path. | |
231 let l:website = s:piecrust_website() | |
232 let l:fullPath = l:website.GetFullPath('_content/posts/' . a:path) | |
233 let l:output = l:website.RunCommand('find', '--exact', '--components', l:fullPath) | |
234 call s:trace(l:output) | |
235 | |
236 " Get each bit of info from the command output. | |
237 let l:lines = split(l:output, '\n') | |
238 let l:components = {} | |
239 for line in l:lines | |
240 let l:kv = split(line, ': ') | |
241 if len(l:kv) != 2 | |
242 continue | |
243 endif | |
244 let l:components[l:kv[0]] = l:kv[1] | |
245 endfor | |
246 | |
247 " Check for errors | |
248 if !has_key(l:components, 'year') || | |
249 \!has_key(l:components, 'month') || | |
250 \!has_key(l:components, 'day') || | |
251 \!has_key(l:components, 'slug') | |
252 call s:error(join(l:lines, '\n')) | |
253 return | |
254 endif | |
255 | |
256 " Print the `pcposturl` command. | |
257 let l:posturl = "{{ pcposturl(" | |
258 let l:posturl .= l:components['year'] . ", " | |
259 let l:posturl .= l:components['month'] . ", " | |
260 let l:posturl .= l:components['day'] . ", " | |
261 let l:posturl .= "'" . l:components['slug'] . "'" | |
262 let l:posturl .= ") }}" | |
263 call setreg(v:register, l:posturl) | |
264 execute 'normal "' . v:register . 'p' | |
265 endfunction | |
266 | |
267 function! s:FindWebsitePosts(ArgLead, CmdLine, CursorPos) abort | |
268 let l:website = s:piecrust_website() | |
269 let l:output = l:website.RunCommand('find', '--posts', a:ArgLead) | |
270 let l:matches = split(l:output, '\n') | |
271 let l:length = strlen('_content/posts/') | |
272 call map(l:matches, 'strpart(v:val, ' . l:length . ')') | |
273 return l:matches | |
274 endfunction | |
275 | |
276 call s:AddMainCommand("-nargs=? -complete=customlist,s:FindWebsitePosts Pcposturl :call s:PcPostUrl(<f-args>)") | |
277 | |
278 " }}} | |
279 | |
227 " Autoload Functions {{{ | 280 " Autoload Functions {{{ |
228 | 281 |
229 " Rescans the current buffer for setting up PieCrust commands. | 282 " Rescans the current buffer for setting up PieCrust commands. |
230 " Passing '1' as the parameter enables debug traces temporarily. | 283 " Passing '1' as the parameter enables debug traces temporarily. |
231 function! piecrust#rescan(...) | 284 function! piecrust#rescan(...) |