Skip to content

Commit 8ded064

Browse files
committed
Only append .js/.css to filenames that don't already have an extension.
Changed s:RailsFind() and s:RailsIncludefind to only append .js/.css extension to filenames that don't already have an extension. Before this change it would give an error such as 'Can't find file "public/javascripts/jquery.easing.1.3.js.js" in path', if you tried to do 'gf' on paths such as these: <%= javascript_include_tag 'jquery.easing.1.3.js' %> <%= stylesheet_link_tag '../jquery.fancybox/jquery.fancybox.css' %> Now it will work with those as well as the simpler cases that don't have an extension (as before): <%= stylesheet_link_tag 'print', :media => 'print' %> <%= javascript_include_tag 'application' %>
1 parent ecc931b commit 8ded064

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

autoload/rails.vim

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,10 +1891,16 @@ function! s:RailsFind()
18911891
let res = s:findamethod('redirect_to\s*(\=\s*:action\s\+=>\s*','\1')
18921892
if res != ""|return res|endif
18931893

1894-
let res = s:findfromview('stylesheet_link_tag','public/stylesheets/\1.css')
1894+
let res = s:findfromview('stylesheet_link_tag','public/stylesheets/\1')
1895+
if res != '' && fnamemodify(res, ':e') == '' " Append the default extension iff the filename doesn't already contains an extension
1896+
let res .= '.css'
1897+
end
18951898
if res != ""|return res|endif
18961899

1897-
let res = s:sub(s:findfromview('javascript_include_tag','public/javascripts/\1.js'),'/defaults>','/application')
1900+
let res = s:sub(s:findfromview('javascript_include_tag','public/javascripts/\1'),'/defaults>','/application')
1901+
if res != '' && fnamemodify(res, ':e') == '' " Append the default extension iff the filename doesn't already contains an extension
1902+
let res .= '.js'
1903+
end
18981904
if res != ""|return res|endif
18991905

19001906
if RailsFileType() =~ '^controller\>'
@@ -1991,13 +1997,17 @@ function! s:RailsIncludefind(str,...)
19911997
endif
19921998
elseif line =~# '\<stylesheet_\(link_tag\|path\)\s*(\='.fpat
19931999
let str = s:sub(str,'^/@!','/stylesheets/')
1994-
let str = 'public'.s:sub(str,'^[^.]*$','&.css')
2000+
if str != '' && fnamemodify(str, ':e') == '' " Append the default extension iff the filename doesn't already contains an extension
2001+
let str .= '.css'
2002+
endif
19952003
elseif line =~# '\<javascript_\(include_tag\|path\)\s*(\='.fpat
19962004
if str ==# "defaults"
19972005
let str = "application"
19982006
endif
19992007
let str = s:sub(str,'^/@!','/javascripts/')
2000-
let str = 'public'.s:sub(str,'^[^.]*$','&.js')
2008+
if str != '' && fnamemodify(str, ':e') == '' " Append the default extension iff the filename doesn't already contains an extension
2009+
let str .= '.js'
2010+
endif
20012011
elseif line =~# '\<\(has_one\|belongs_to\)\s*(\=\s*'
20022012
let str = 'app/models/'.str.'.rb'
20032013
elseif line =~# '\<has_\(and_belongs_to_\)\=many\s*(\=\s*'

0 commit comments

Comments
 (0)