Skip to content

Commit 7bd8fe3

Browse files
committed
Refactor Ruby path setup
1 parent 9a623cf commit 7bd8fe3

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

autoload/rails.vim

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,14 +2300,6 @@ function! s:match_partial(func) abort
23002300
endif
23012301
endfunction
23022302

2303-
function! s:app_template_handlers() dict abort
2304-
return s:uniq(['raw', 'erb', 'html', 'builder', 'ruby', 'coffee', 'haml', 'jbuilder'] +
2305-
\ filter(map(keys(self.projections()),
2306-
\ 'matchstr(v:val, "^\\Capp/views/\\*\\.\\zs(\\w\\+$")'), 'len(v:val)'))
2307-
endfunction
2308-
2309-
call s:add_methods('app', ['template_handlers'])
2310-
23112303
function! s:suffixes(type) abort
23122304
if a:type =~# '^stylesheets\=$\|^css$'
23132305
let exts = ['css', 'scss', 'css.scss', 'sass', 'css.sass']
@@ -5103,28 +5095,31 @@ function! s:set_path_options() abort
51035095
endfunction
51045096

51055097
function! rails#ruby_setup() abort
5106-
let self = rails#buffer()
5107-
let path = filter(self.projected('path'), 'type(v:val) == type("")')
5108-
5109-
let path += self.app().internal_load_path()
5110-
let path += ['app/views']
5111-
if len(self.controller_name())
5112-
let path += ['app/views/'.self.controller_name(), 'app/views/application', 'public']
5098+
if !s:active()
5099+
return
51135100
endif
5114-
let format = self.format(0)
5115-
for ext in self.app().template_handlers()
5101+
let path = rails#app().internal_load_path()
5102+
let path += [rails#app().path('app/views')]
5103+
if len(rails#buffer().controller_name())
5104+
let path += [rails#app().path('app/views/'.rails#buffer().controller_name()), rails#app().path('app/views/application')]
5105+
endif
5106+
let format = rails#buffer().format(0)
5107+
let exts = ['raw', 'erb', 'html', 'builder', 'ruby', 'coffee', 'haml', 'jbuilder']
5108+
call extend(exts,
5109+
\ filter(map(keys(rails#app().projections()),
5110+
\ 'matchstr(v:val, "^\\Capp/views/\\*\\.\\zs(\\w\\+$")'), 'len(v:val)'))
5111+
for ext in exts
51165112
exe 'setlocal suffixesadd+=.' . ext
51175113
if len(format)
51185114
exe 'setlocal suffixesadd+=.' . format . '.' . ext
51195115
endif
51205116
endfor
5121-
if !self.app().has_rails5()
5122-
let path += ['vendor/plugins/*/lib', 'vendor/rails/*/lib']
5117+
if !rails#app().has_rails5()
5118+
let path += [rails#app().path('vendor/plugins/*/lib'), rails#app().path('vendor/rails/*/lib')]
51235119
endif
5124-
call add(path, self.app().path())
5120+
call add(path, rails#app().path())
51255121

5126-
call map(path, 'self.app().path(v:val)')
5127-
let engine_paths = map(copy(self.app().engines()), 'v:val . "/app/*"')
5122+
let engine_paths = map(copy(rails#app().engines()), 'v:val . "/app/*"')
51285123
call rails#update_path(path, engine_paths)
51295124

51305125
let b:undo_ftplugin = get(b:, 'undo_ftplugin', 'exe') . '|setlocal pa= sua= inc='

0 commit comments

Comments
 (0)