Skip to content

Commit

Permalink
Support transitionTo for going to routes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewRadev committed Jul 15, 2016
1 parent 757d5fe commit a785119
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
1 change: 1 addition & 0 deletions autoload/ember_tools.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function! ember_tools#Includeexpr()
call extend(callbacks, g:ember_tools_custom_gf_callbacks)
call extend(callbacks, [
\ 'ember_tools#gf#RouterRoute',
\ 'ember_tools#gf#TransitionRoute',
\ 'ember_tools#gf#Controller',
\ 'ember_tools#gf#Action',
\ 'ember_tools#gf#ServiceInjection',
Expand Down
31 changes: 25 additions & 6 deletions autoload/ember_tools/gf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@ function! ember_tools#gf#RouterRoute()
endwhile
endif

let filename = ember_tools#ExistingLogicFile('app/routes/'.join(route_path, '/'))
if filename == ''
let filename = ember_tools#ExistingLogicFile('app/routes/'.join(route_path, '/').'/index')
return s:FindRoute(join(route_path, '/'))
endfunction

function! ember_tools#gf#TransitionRoute()
if !ember_tools#IsLogicFiletype()
return ''
endif
if filename == ''
let filename = ember_tools#ExistingLogicFile('app/pods/'.join(route_path, '/').'/route')

if !ember_tools#search#UnderCursor('transitionTo\%(Route\)\=[( ][''"]\zs\k\+[''"]')
return ''
endif

return filename
let route_path = split(expand('<cword>'), '\.')
let route_path = map(route_path, 'ember_tools#util#Dasherize(v:val)')

return s:FindRoute(join(route_path, '/'))
endfunction

function! ember_tools#gf#Controller()
Expand Down Expand Up @@ -224,6 +231,18 @@ function! s:FindController(name)
return ''
endfunction

function! s:FindRoute(name)
let filename = ember_tools#ExistingLogicFile('app/routes/'.a:name)
if filename == ''
let filename = ember_tools#ExistingLogicFile('app/routes/'.a:name.'/index')
endif
if filename == ''
let filename = ember_tools#ExistingLogicFile('app/pods/'.a:name.'/route')
endif

return filename
endfunction

function! s:IsComponentTemplate(filename)
return
\ a:filename =~ 'app/templates/components/\k\+\.\(emblem\|hbs\)' ||
Expand Down
16 changes: 15 additions & 1 deletion spec/plugin/gf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
expect(current_file).to eq 'app/stuff.js'
end

specify "finding a route" do
specify "finding a route from the router" do
touch_file 'app/routes/foo/bar-baz.js'
edit_file 'app/router.js', <<-EOF
this.route('foo', function() {
Expand All @@ -28,6 +28,20 @@
expect(current_file).to eq 'app/routes/foo/bar-baz.js'
end

specify "finding a route from a transitionTo" do
touch_file 'app/routes/foo/bar-baz.js'
edit_file 'app/controllers/foo.js', <<-EOF
beforeModel() {
this.transitionTo('foo.bar-baz');
}
EOF
vim.search 'foo.bar-baz'

vim.normal 'gf'

expect(current_file).to eq 'app/routes/foo/bar-baz.js'
end

specify "finding a route in a pod structure" do
touch_file 'app/pods/foo/bar-baz/route.js'
edit_file 'app/router.js', <<-EOF
Expand Down

0 comments on commit a785119

Please sign in to comment.