11"
22" Vim Rspec
3- " Last change: March 3 2009
4- " Version> 0.0.2
3+ " Last change: March 4 2009
4+ " Version> 0.0.4
55" Maintainer: Eustáquio 'TaQ' Rangel
66" License: GPL
77" URL: git://github.com/taq/vim-rspec
88"
99" Script to run the spec command inside Vim
1010" To install, unpack the files on your ~/.vim directory and source it
1111"
12+ let s: xsltproc_cmd = " "
13+ let s: grep_cmd = " "
14+ let s: hpricot_cmd = " "
15+ let s: xslt = 0
16+ let s: hpricot = 0
17+
1218function ! s: find_xslt ()
1319 return system (" xsltproc --version | head -n1" )
1420endfunction
@@ -17,6 +23,10 @@ function! s:find_grep()
1723 return system (" grep --version | head -n1" )
1824endfunction
1925
26+ function ! s: find_hpricot ()
27+ return system (" gem search -i hpricot" )
28+ endfunction
29+
2030function ! s: error_msg (msg)
2131 echohl ErrorMsg
2232 echo a: msg
@@ -30,22 +40,39 @@ function! s:notice_msg(msg)
3040endfunction
3141
3242function ! s: RunSpecMain (type )
33- let l: xsltproc_cmd = s: find_xslt ()
34- if match (l: xsltproc_cmd ,' \d' )<0
35- call s: error_msg (" You need xsltproc to run this script." )
36- return
43+ if len (s: xsltproc_cmd )<1
44+ let s: xsltproc_cmd = s: find_xslt ()
45+ let s: xslt = match (s: xsltproc_cmd ,' \d' )>= 0
46+ end
47+ if len (s: hpricot_cmd )<1
48+ let s: hpricot_cmd = s: find_hpricot ()
49+ let s: hpricot = match (s: hpricot_cmd ,' true' )>= 0
3750 end
38- let l: grep_cmd = s: find_grep ()
39- if match (l: grep_cmd ,' \d' )<0
40- call s: error_msg (" You need grep to run this script." )
51+ if ! s: hpricot && ! s: xslt
52+ call s: error_msg (" You need the hpricot gem or xsltproc to run this script." )
4153 return
4254 end
55+ if len (s: grep_cmd )<1
56+ let s: grep_cmd = s: find_grep ()
57+ if match (s: grep_cmd ,' \d' )<0
58+ call s: error_msg (" You need grep to run this script." )
59+ return
60+ end
61+ end
4362 let l: bufn = bufname (" %" )
4463
64+ " filters
65+ let l: xsl = expand (" ~/" )." .vim/plugin/vim-rspec.xsl"
66+ let l: rubys = expand (" ~/" )." .vim/plugin/vim-rspec.rb"
67+
68+ " hpricot gets the priority
69+ let l: type = s: hpricot ? " hpricot" : " xsltproc"
70+ let l: filter = s: hpricot ? " ruby " .l: rubys : " xsltproc --novalid --html " .l: xsl ." - "
71+
4572 " run just the current file
4673 if a: type== " file"
4774 if match (l: bufn ,' _spec.rb' )>= 0
48- call s: notice_msg (" Running spec on the current file ..." )
75+ call s: notice_msg (" Running spec on the current file with " . l: type . " ..." )
4976 let l: spec = " spec -f h " .l: bufn
5077 else
5178 call s: error_msg (" Seems " .l: bufn ." is not a *_spec.rb file" )
@@ -54,7 +81,7 @@ function! s:RunSpecMain(type)
5481 else
5582 let l: dir = expand (" %:p:h" )
5683 if isdirectory (l: dir ." /spec" )>0
57- call s: notice_msg (" Running spec on the spec directory ..." )
84+ call s: notice_msg (" Running spec on the spec directory with " . l: type . " ..." )
5885 else
5986 " try to find a spec directory on the current path
6087 let l: tokens = split (l: dir ," /" )
@@ -68,7 +95,7 @@ function! s:RunSpecMain(type)
6895 end
6996 endfor
7097 if len (l: dir )>0
71- call s: notice_msg (" Running spec on the spec directory found (" .l: dir ." ) ..." )
98+ call s: notice_msg (" Running spec with " . l: type . " on the spec directory found (" .l: dir ." ) ..." )
7299 else
73100 call s: error_msg (" No " .l: dir ." /spec directory found" )
74101 return
@@ -82,8 +109,7 @@ function! s:RunSpecMain(type)
82109 end
83110
84111 " run the spec command
85- let l: xsl = expand (" ~/" )." .vim/plugin/vim-rspec.xsl"
86- let s: cmd = l: spec ." | xsltproc --novalid --html " .l: xsl ." - 2> /dev/null | grep \" ^[-\+\[ \\ # ]\" "
112+ let s: cmd = l: spec ." | " .l: filter ." 2> /dev/null | grep \" ^[-\+\[ \\ #\\ * ]\" "
87113 echo
88114
89115 " put the result on a new buffer
0 commit comments