Platinum Partner

Vim Folding For RSpec Editing


" fold text between context and specify
function! ShowRSpecContext()
  let spec_idx = search('specify\s\+".\+"', 'Wbn', '^')
  let ctx_idx  = search('context\s\+".\+"', 'Wbn', '^')
  if spec_idx && ctx_idx
    exec (ctx_idx+1).','.(spec_idx-1).'fold'
  endif
endfunction

" fold text between all contexts and specify lines
function! ShowRSpecAnnotation()
 call cursor('$', 0)
 try
   foldo!
 catch
 endtry
 let cur_line = line('$')
 while cur_line > 0
   let prev_spec = search('\(context\|specify\)\s\+".\+"', 'Wb', '^')
   if ! prev_spec
     break
   endif
   exec (prev_spec).','.cur_line.'fold'
   let cur_line=prev_spec-1
 endwhile
endfunction
command! Sx :call ShowRSpecContext()
command! Sa :call ShowRSpecAnnotation()

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}