黑客rails.vim与Padrino一起工作
我最近克隆了rails.vim (vim-rails),希望修改它以与 Padrino 项目一起使用。
目前,我正在尝试让 Rcontroller 命令不仅在应用程序/控制器(非常适合 Rails)中查找,而且在项目中具有名为“控制器”子文件夹的任何文件夹中查找。因此,当我在命令模式下输入 Rcontroller 并点击 Tab 时,我应该能够通过 admin/controllers/base.rb
、admin/controllers/accounts.rb
、 app/controllers/events.rb
等。这将使插件的用户跳转到 Padrino 应用程序的“子应用程序”中的控制器。例如 PADRINO_ROOT/admin
当前的 controllerList
函数似乎可以处理此自动完成,这是我到目前为止所拥有的(仅对原始源进行了轻微修改)
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
我在控制器之前添加了通配符目录,但这给出了类似
Rcontroller ers/base
Rcontroller ers/sessions
Rcontroller s/events
的结果,最后一个看起来有些奇怪继续处理字符串长度或重叠...
理想情况下,我希望输入 Rcontroller adminRcontroller app
应该生成 Rcontroller app/controllers/events.rb
viewList
函数的代码与此类似其代码如下:
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
有人有什么建议吗?提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能希望完整路径看起来像这样:
which globs as“在任何目录下查找名为controllers的目录,然后在该目录下的任何位置查找以.rb结尾的文件”
查看“relglob”的其他用法,我只能猜测它应该如何工作,但我的猜测是:
第三个参数是基于此的 假设,我的猜测是使用:
警告:这是基于我对 glob 的理解,而不是 vim 或 relglob
根据实际使用情况调整。
注意:添加“app/”是假设您不太可能希望通过供应商/插件或供应商/gems 下的任何控制器进行 Tab 键切换。情况可能并非如此,在这种情况下,请随意将其更改为“。”
You probably want the full path to look like this:
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:
based on this assumption, my guess would be to use:
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 "."