Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hacking rails.vim to work with Padrino

Tags:

vim

ruby

padrino

I recently cloned rails.vim (vim-rails) hoping to modify it to work with Padrino projects.

Currently I'm trying to get the Rcontroller command to look not only in app/controllers (perfect for rails) but also in any folder in the project that has a sub-folder called 'controllers'. So when I type Rcontroller in command-mode and hit tab, I should be able to tab through admin/controllers/base.rb, admin/controllers/accounts.rb, app/controllers/events.rb etc. This will let users of the plugin to jump to controllers in a 'subapp' of a Padrino application. e.g. PADRINO_ROOT/admin

The current controllerList function seems to handle this autocompletion and here's what I have so far (only slightly modified from the original source)

function! s:controllerList(A,L,P)
  let con = padrino#app().relglob("*/controllers/","**/*",".rb") 
  call map(con,'s:sub(v:val,"_controller$","")')
  return s:autocamelize(con,a:A)  
endfunction

I added the wildcard before the controllers directory but this gives results like

  • Rcontroller ers/base
  • Rcontroller ers/sessions
  • Rcontroller s/events

for the last one it looks like there is somethings weird going on with string lengths or overlap...

Ideally I'd like to get it to the point where typing Rcontroller admin<TAB> should result in autocompletion to Rcontroller admin/controllers/accounts.rb. Likewise, Rcontroller app<TAB> should result in Rcontroller app/controllers/events.rb

The code for the viewList function has something similar to this and its code is as follows:

 function! s:viewList(A,L,P)
   let c = s:controller(1)
   let top = padrino#app().relglob("app/views/",s:fuzzyglob(a:A))
   call filter(top,'v:val !~# "\\~$"')
   if c != '' && a:A !~ '/'
     let local = padrino#app().relglob("app/views/".c."/","*.*[^~]")
     return s:completion_filter(local+top,a:A)
   endif
   return s:completion_filter(top,a:A)
 endfunction

Anyone have any suggestions? Thanks in advance.

like image 479
gcahill Avatar asked Apr 20 '11 12:04

gcahill


1 Answers

You probably want the full path to look like this:

**/controllers/**/*.rb

which globs as "look under any directory for a directory called controllers, then look anywhere under that for a file ending in .rb"

Looking at other usages of "relglob", I can only guess at how it's supposed to work, but my guess is:

  • first param is "which directory to start looking in"
  • second param is "how to multiply out the directories from there"
  • third param is "actual files that will match"

based on this assumption, my guess would be to use:

padrino#app().relglob("app/","**/controllers/**/*",".rb") 

Caveat: this is based on my understanding of glob, not of vim or relglob adjust as per actual usage.

Note: have added "app/" in the assumption that you're unlikely to want to be tabbing through any controllers under vendor/plugin or vendor/gems. This may not be the case, in which case, feel free to change it to "."

like image 167
Taryn East Avatar answered Oct 19 '22 13:10

Taryn East