黑客rails.vim与Padrino一起工作

发布于 2024-11-02 14:48:10 字数 1578 浏览 6 评论 0原文

我最近克隆了rails.vim (vim-rails),希望修改它以与 Padrino 项目一起使用。

目前,我正在尝试让 Rcontroller 命令不仅在应用程序/控制器(非常适合 Rails)中查找,而且在项目中具有名为“控制器”子文件夹的任何文件夹中查找。因此,当我在命令模式下输入 Rcontroller 并点击 Tab 时,我应该能够通过 admin/controllers/base.rbadmin/controllers/accounts.rbapp/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 admin应该导致自动完成 Rcontroller admin/controllers/accounts。 rb.同样,Rcontroller 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他是夢罘是命 2024-11-09 14:48:10

您可能希望完整路径看起来像这样:

**/controllers/**/*.rb

which globs as“在任何目录下查找名为controllers的目录,然后在该目录下的任何位置查找以.rb结尾的文件”

查看“relglob”的其他用法,我只能猜测它应该如何工作,但我的猜测是:

  • 第一个参数是“开始查找哪个目录”
  • 第二个参数是“如何从那里乘出目录”
  • “将匹配的实际文件”

第三个参数是基于此的 假设,我的猜测是使用:

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

警告:这是基于我对 glob 的理解,而不是 vim 或 relglob
根据实际使用情况调整。

注意:添加“app/”是假设您不太可能希望通过供应商/插件或供应商/gems 下的任何控制器进行 Tab 键切换。情况可能并非如此,在这种情况下,请随意将其更改为“。”

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 "."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文