babie steps

作業療法記録

Rails2.0 対応 rails.vim

$ diff -u .vim/plugin/rails.vim.old .vim/plugin/rails.vim

--- .vim/plugin/rails.vim.old   2007-11-07 12:08:19.000000000 +0900
+++ .vim/plugin/rails.vim       2007-11-07 12:22:48.000000000 +0900
@@ -212,7 +212,7 @@
     return s:sub(f,'.*\<test/functional/\(.\{-\}\)_controller_test\.rb$','\1')
   elseif f =~ '\<components/.*_controller\.rb$'
     return s:sub(f,'.*\<components/\(.\{-\}\)_controller\.rb$','\1')
-  elseif f =~ '\<components/.*\.\(rhtml\|rxml\|rjs\|mab\|liquid\)$'
+  elseif f =~ '\<components/.*\.\(rhtml\|erb\|rxml\|builder\|rjs\|mab\|liquid\)$'
     return s:sub(f,'.*\<components/\(.\{-\}\)/\k\+\.\k\+$','\1')
   elseif f =~ '\<app/models/.*\.rb$' && t =~ '^model-mailer\>'
     return s:sub(f,'.*\<app/models/\(.\{-\}\)\.rb$','\1')
@@ -413,7 +413,7 @@
     let r = "view-layout-" . e
   elseif f =~ '\<\%(app/views\|components\)/.*/_\k\+\.\k\+$'
     let r = "view-partial-" . e
-  elseif f =~ '\<app/views\>.*\.' || f =~ '\<components/.*/.*\.\(rhtml\|rxml\|rjs\|mab\|liquid\)'
+  elseif f =~ '\<app/views\>.*\.' || f =~ '\<components/.*/.*\.\(rhtml\|erb\|rxml\|builder\|rjs\|mab\|liquid\)'
     let r = "view-" . e
   elseif f =~ '\<test/unit/.*_test\.rb'
     let r = "test-unit"
@@ -613,7 +613,7 @@
     command! -buffer -bar -nargs=? -bang  Rdbext   :call s:BufDatabase(2,<q-args>,<bang>0)
   endif
   let ext = expand("%:e")
-  if ext == "rhtml" || ext == "rxml" || ext == "rjs" || ext == "mab" || ext == "liquid"
+  if ext == "rhtml" || ext == "erb" || ext == "rxml" || ext == "builder" || ext == "rjs" || ext == "mab" || ext == "liquid"
     command! -buffer -bar -nargs=? -range Rpartial :<line1>,<line2>call s:Partial(<bang>0,<f-args>)
     " In case we one day we make Rpartial act like Rview
     command! -buffer -bar -nargs=? -range Rextract :<line1>,<line2>call s:Partial(<bang>0,<f-args>)
@@ -1418,8 +1418,12 @@
     "let str = s:sub(expand("%:p"),'.*[\/]app[\/]controllers[\/]\(.\{-\}\)_controller.rb','views/\1').'/'.str
     if filereadable(str.".rhtml")
       let str = str . ".rhtml"
+    if filereadable(str.".html.erb")
+      let str = str . ".html.erb"
     elseif filereadable(str.".rxml")
       let str = str . ".rxml"
+    elseif filereadable(str.".xml.builder")
+      let str = str . ".xml.builder"
     elseif filereadable(str.".rjs")
       let str = str . ".rjs"
     endif
@@ -1660,8 +1664,12 @@
     return pre.c
   elseif filereadable(RailsRoot(). pre.c.".rhtml")
     let file = pre.c.".rhtml"
+  elseif filereadable(RailsRoot(). pre.c.".html.erb")
+    let file = pre.c.".html.erb"
   elseif filereadable(RailsRoot(). pre.c.".rxml")
     let file = pre.c.".rxml"
+  elseif filereadable(RailsRoot(). pre.c.".xml.builder")
+    let file = pre.c.".xml.builder"
   elseif filereadable(RailsRoot(). pre.c.".mab")
     let file = pre.c.".mab"
   elseif filereadable(RailsRoot(). pre.c.".liquid")
@@ -1686,7 +1694,7 @@
     let file = s:findlayout("application")
   endif
   if file == ""
-    let file = "app/views/layouts/application.rhtml"
+    let file = "app/views/layouts/application.html.erb"
   endif
   call s:edit(a:cmd.(a:bang?'!':''),s:sub(file,'^/',''))
 endfunction
@@ -2045,6 +2053,13 @@
     let erub1 = ''
     let erub2 = ''
   endif
+  if expand("%:e") == "erb"
+    let erub1 = '<%\s*'
+    let erub2 = '\s*-\=%>'
+  else
+    let erub1 = ''
+    let erub2 = ''
+  endif
   let spaces = matchstr(getline(first),"^ *")
   if getline(last+1) =~ '^\s*'.erub1.'end'.erub2.'\s*$'
     let fspaces = matchstr(getline(last+1),"^ *")
@@ -2072,6 +2087,9 @@
   if expand("%:e") == "rhtml"
     let renderstr = "<%= ".renderstr." %>"
   endif
+  if expand("%:e") == "erb"
+    let renderstr = "<%= ".renderstr." %>"
+  endif
   let buf = @@
   silent exe range."yank"
   let partial = @@
@@ -3375,12 +3393,14 @@
   if g:rails_level > 0
     if &ft == "mason"
       setlocal filetype=eruby
-    elseif &ft =~ '^\%(conf\)\=$' && expand("%:e") =~ '^\%(rjs\|rxml\|rake\|mab\)$'
+    elseif &ft =~ '^\%(conf\)\=$' && expand("%:e") =~ '^\%(rjs\|rxml\|builder\|rake\|mab\)$'
       setlocal filetype=ruby
     elseif &ft == "" && expand("%:e") == "liquid"
       setlocal filetype=liquid
     elseif &ft == "" && expand("%:e") == 'rhtml'
       setlocal filetype=eruby
+    elseif &ft == "" && expand("%:e") == 'erb'
+      setlocal filetype=eruby
     elseif &ft == "" && expand("%:e") == 'yml'
       setlocal filetype=yaml
     elseif firsttime
@@ -3476,10 +3496,10 @@
   else
     " Does this cause problems in any filetypes?
     setlocal includeexpr=RailsIncludeexpr()
-    setlocal suffixesadd=.rb,.rhtml,.rxml,.rjs,.mab,.liquid,.css,.js,.yml,.csv,.rake,.sql,.html
+    setlocal suffixesadd=.rb,.rhtml,.erb,.rxml,builder,.rjs,.mab,.liquid,.css,.js,.yml,.csv,.rake,.sql,.html
   endif
   if &filetype == "ruby"
-    setlocal suffixesadd=.rb,.rhtml,.rxml,.rjs,.mab,.liquid,.yml,.csv,.rake,s.rb
+    setlocal suffixesadd=.rb,.rhtml,.erb,.rxml,.builder,.rjs,.mab,.liquid,.yml,.csv,.rake,s.rb
     if expand('%:e') == 'rake'
       setlocal define=^\\s*def\\s\\+\\(self\\.\\)\\=\\\|^\\s*\\%(task\\\|file\\)\\s\\+[:'\"]
     else
@@ -3487,7 +3507,7 @@
     endif
   elseif &filetype == "eruby"
     "set include=\\<\\zsAct\\f*::Base\\ze\\>\\\|^\\s*\\(require\\\|load\\)\\s\\+['\"]\\zs\\f\\+\\ze\\\|\\zs<%=\\ze
-    setlocal suffixesadd=.rhtml,.rxml,.rjs,.mab,.liquid,.rb,.css,.js,.html
+    setlocal suffixesadd=.rhtml,.erb,.rxml,.builder,.rjs,.mab,.liquid,.rb,.css,.js,.html
   endif
 endfunction

すごい適当。ここかな?ってとこに .erb と .builder を足しただけという。自己責任で。