Skip to content

Commit

Permalink
Use list for handlers directories
Browse files Browse the repository at this point in the history
  • Loading branch information
alx741 committed Nov 23, 2016
1 parent 693c01d commit 3b7ae5e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
49 changes: 32 additions & 17 deletions ftplugin/yesod.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ if !exists("g:yesod_disable_maps")
let g:yesod_disable_maps = 0
endif

if !exists("g:yesod_handlers_path")
let g:yesod_handlers_path = "Handler"
if !exists("g:yesod_handlers_directories")
let g:yesod_handlers_directories = ['Handler']
endif



command! YesodAddHandler execute "call yesod#AddHandler()"
command! YesodOpenHandler execute "call yesod#OpenHandler()"
setlocal commentstring=--\ %s
Expand All @@ -33,30 +32,46 @@ function! yesod#OpenHandler()
return ""
endif

let s:route_resource_function = s:route_resource . "R *::"
for dir in g:yesod_handlers_directories
if finddir(expand("%:p:h") . "/../" . dir) !=? ""
if (yesod#OpenHandlerTryDir(dir, s:route_resource))
return ""
endif
else
echom dir . " does not exists in the project root!"
continue
endif
endfor

let s:prompt = input("The resource handler for " .
\ s:route_resource .
\ "R does not exist. Create it? [y/N] ")

if s:prompt ==? "y"
call yesod#AddHandler()
call yesod#OpenHandler()
else
return ""
endif
endfunction

function! yesod#OpenHandlerTryDir(directory, route_resource)
let s:route_resource_function = a:route_resource . "R *::"

try
execute "lvimgrep /" . s:route_resource_function . "/ " .
\ expand("%:p:h") . "/../" . g:yesod_handlers_path . "/**/*"
\ expand("%:p:h") . "/../" . a:directory . "/**/*"
let success=1
catch /*/
finally
if !exists('success')
let s:prompt = input("The resource handler for " .
\ s:route_resource .
\ "R does not exist. Create it? [y/N] ")

if s:prompt ==? "y"
call yesod#AddHandler()
call yesod#OpenHandler()
else
return ""
endif
if exists('success')
return 1
else
return 0
endif
endtry
endfunction


function! yesod#AddHandler()
let l:winview = winsaveview()

Expand Down
4 changes: 2 additions & 2 deletions test/config/routes
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

/searchThing/#id SearchR GET

/some-route SomeRouteR POST
/does/not/exists DoesNotExistsR POST

/noResource/here NoResourceHere POST
/invalid/resource/here InvalidResourceHere POST

/recursive/handlers RecursiveHandlerR GET POST PUT

Expand Down

0 comments on commit 3b7ae5e

Please sign in to comment.