Skip to content

Commit 38fcde6

Browse files
committed
Implement laravel#app().templates()
Returns a Dictionary of the app's templates in the form { 'layouts.app': 'layouts/app.blade.php', ... } which can be used for completion.
1 parent 4d33be3 commit 38fcde6

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

autoload/laravel.vim

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ function! s:app_path(...) dict abort
6464
return join([self._root] + a:000, '/')
6565
endfunction
6666

67+
""
68+
" glob() in context of app root.
69+
function! s:app_glob(pat) dict abort
70+
return glob(self.path(a:pat), 1, 1)
71+
endfunction
72+
6773
""
6874
" Check whether path exists in project.
6975
function! s:app_has_path(path) dict abort
@@ -122,8 +128,14 @@ function! s:app_expand_migration(slug) dict abort
122128
return fnamemodify(self.find_migration(a:slug), ':t:r')
123129
endfunction
124130

125-
call s:add_methods('app', ['has_dir', 'has_file', 'has_path'])
126-
call s:add_methods('app', ['path', 'src_path', 'config_path', 'migrations_path', 'find_migration', 'expand_migration'])
131+
""
132+
" Get absolute path to views directory, optionally with [path] appended.
133+
function! s:app_views_path(...) dict abort
134+
return join([self._root, 'resources/views'] + a:000, '/')
135+
endfunction
136+
137+
call s:add_methods('app', ['glob', 'has_dir', 'has_file', 'has_path'])
138+
call s:add_methods('app', ['path', 'src_path', 'config_path', 'migrations_path', 'find_migration', 'expand_migration', 'views_path'])
127139

128140
""
129141
" Detect app's namespace
@@ -297,7 +309,19 @@ endfunction
297309
" { 'layouts.app': 'layouts/app.blade.php', ... }
298310
function! s:app_templates() abort dict
299311
if self.cache.needs('templates')
312+
let files = self.glob('resources/views/**/*.php')
313+
call map(files, 'substitute(v:val, ''' . self.views_path() . '/'', "", "")')
314+
315+
let slugs = map(copy(files), 'fnamemodify(v:val, ":r:r")')
316+
call map(slugs, 'substitute(v:val, "/", ".", "g")')
317+
300318
let templates = {}
319+
let index = 0
320+
321+
while index < len(files)
322+
let templates[slugs[index]] = files[index]
323+
let index = index + 1
324+
endwhile
301325

302326
call self.cache.set('templates', templates)
303327
endif

0 commit comments

Comments
 (0)