public
Description: Ruby TextMate bundle
Homepage: http://drnicwilliams.com
Clone URL: git://github.com/drnic/ruby-tmbundle.git
Search Repo:
• Transitioned from scriptmate to TextMate::Executor.run().

Every attempt was made to preserve the original logic.

git-svn-id: 
http://macromates.com/svn/Bundles/trunk/Bundles/Ruby.tmbundle@9980 
dfb7d73b-c2ec-0310-8fea-fb051d288c6d
ldaley (author)
Thu Jun 19 22:59:19 -0700 2008
commit  e78cd684d199867c5ba645a1581e188a7fc1bde5
tree    4f73786f48119dd24c287d6bf4f4ac36ee2c00bb
parent  1667d02c3f5a8090d4659a6bffe28b71554e4cdf
...
1
2
 
 
3
4
 
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
33
34
35
36
37
38
39
40
 
 
 
 
 
 
 
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
 
 
 
 
 
 
 
 
 
66
67
68
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
71
 
 
 
 
 
 
72
73
74
75
76
 
77
...
 
 
1
2
3
 
4
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
21
22
23
 
 
 
 
24
25
26
27
28
29
30
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
33
34
35
36
37
38
39
40
41
 
 
 
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
57
58
59
60
61
62
63
 
 
 
 
64
65
0
@@ -1,76 +1,64 @@
0
-require "#{ENV["TM_SUPPORT_PATH"]}/lib/scriptmate"
0
-require "cgi"
0
+require ENV["TM_SUPPORT_PATH"] + "/lib/tm/executor"
0
+require ENV["TM_SUPPORT_PATH"] + "/lib/tm/save_current_document"
0
 
0
-$SCRIPTMATE_VERSION = "$Revision$"
0
+TextMate.save_current_document
0
 
0
-class RubyScript < UserScript
0
- def lang; "Ruby" end
0
- def default_extension; ".rb" end
0
- def executable; @hashbang || ENV['TM_RUBY'] || 'ruby' end
0
- def args; ['-rcatch_exception'] end
0
- def version_string
0
- ruby_path = %x{ #{executable} -e 'require "rbconfig"; print Config::CONFIG["bindir"] + "/" + Config::CONFIG["ruby_install_name"]'}
0
- res = "Ruby r" + %x{ #{executable} -e 'print RUBY_VERSION' }
0
- res + " (#{ruby_path})"
0
- end
0
- def test_script?
0
- @path =~ /(?:\b|_)(?:tc|ts|test)(?:\b|_)/ or
0
- @content =~ /\brequire\b.+(?:test\/unit|test_helper)/
0
- end
0
- def filter_cmd(cmd)
0
- if test_script?
0
- path_ary = @path.split("/")
0
- if index = path_ary.rindex("test")
0
- test_path = File.join(*path_ary[0..-2])
0
- lib_path = File.join( *( path_ary[0..-2] +
0
- [".."] * (path_ary.length - index - 1) ) +
0
- ["lib"] )
0
- if File.exist? lib_path
0
- cmd.insert(1, "-I#{e_sh lib_path}:#{e_sh test_path}")
0
- end
0
- end
0
+is_test_script = ENV["TM_FILEPATH"] =~ /(?:\b|_)(?:tc|ts|test)(?:\b|_)/ or
0
+ File.read(ENV["TM_FILEPATH"]) =~ /\brequire\b.+(?:test\/unit|test_helper)/
0
+
0
+cmd = [ENV['TM_RUBY'] || 'ruby', '-rcatch_exception']
0
+
0
+if is_test_script and not ENV['TM_FILE_IS_UNTITLED']
0
+ path_ary = (ENV['TM_ORIG_FILEPATH'] || ENV['TM_FILEPATH']).split("/")
0
+ if index = path_ary.rindex("test")
0
+ test_path = File.join(*path_ary[0..-2])
0
+ lib_path = File.join( *( path_ary[0..-2] +
0
+ [".."] * (path_ary.length - index - 1) ) +
0
+ ["lib"] )
0
+ if File.exist? lib_path
0
+ cmd << "-I#{lib_path}:#{test_path}"
0
     end
0
- cmd
0
   end
0
 end
0
 
0
-class RubyMate < ScriptMate
0
- def filter_stdout(str)
0
- if @command.test_script? and str =~ /\A[.EF]+\Z/
0
- return htmlize(str).gsub(/[EF]+/, "<span style=\"color: red\">\\&</span>") +
0
+cmd << ENV["TM_FILEPATH"]
0
+
0
+TextMate::Executor.run(cmd, :version_args => ["--version"]) do |str, type|
0
+ case type
0
+ when :out
0
+ if is_test_script and str =~ /\A[.EF]+\Z/
0
+ htmlize(str).gsub(/[EF]+/, "<span style=\"color: red\">\\&</span>") +
0
             "<br style=\"display: none\"/>"
0
- else
0
- if @command.test_script?
0
- return ( str.map do |line|
0
- if line =~ /^(\s+)(\S.*?):(\d+)(?::in\s*`(.*?)')?/
0
- indent, file, line, method = $1, $2, $3, $4
0
- url, display_name = '', 'untitled document';
0
- unless file == "-"
0
- indent += " " if file.sub!(/^\[/, "")
0
- url = '&amp;url=file://' + e_url(file)
0
- display_name = File.basename(file)
0
- end
0
- "#{indent}<a class='near' href='txmt://open?line=#{line + url}'>" +
0
- (method ? "method #{CGI::escapeHTML method}" : '<em>at top level</em>') +
0
- "</a> in <strong>#{CGI::escapeHTML display_name}</strong> at line #{line}<br/>"
0
- elsif line =~ /(\[[^\]]+\]\([^)]+\))\s+\[([\w\_\/\.]+)\:(\d+)\]/
0
- spec, file, line = $1, $2, $3, $4
0
- "<span><a style=\"color: blue;\" href=\"txmt://open?url=file://#{e_url(file)}&amp;line=#{line}\">#{spec}</span>:#{line}<br/>"
0
- elsif line =~ /([\w\_]+).*\[([\w\_\/\.]+)\:(\d+)\]/
0
- method, file, line = $1, $2, $3
0
- "<span><a style=\"color: blue;\" href=\"txmt://open?url=file://#{e_url(file)}&amp;line=#{line}\">#{method}</span>:#{line}<br/>"
0
- elsif line =~ /^\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors\b.*/
0
- "<span style=\"color: #{$1 + $2 == "00" ? "green" : "red"}\">#{$&}</span><br/>"
0
- else
0
- htmlize(line)
0
+ elsif is_test_script
0
+ out = str.map do |line|
0
+ if line =~ /^(\s+)(\S.*?):(\d+)(?::in\s*`(.*?)')?/
0
+ indent, file, line, method = $1, $2, $3, $4
0
+ url, display_name = '', 'untitled document';
0
+ unless file == "-"
0
+ indent += " " if file.sub!(/^\[/, "")
0
+ url = '&amp;url=file://' + e_url(file)
0
+ display_name = File.basename(file)
0
           end
0
- end.join )
0
- else
0
- return htmlize(str)
0
+ "#{indent}<a class='near' href='txmt://open?line=#{line + url}'>" +
0
+ (method ? "method #{CGI::escapeHTML method}" : '<em>at top level</em>') +
0
+ "</a> in <strong>#{CGI::escapeHTML display_name}</strong> at line #{line}<br/>"
0
+ elsif line =~ /(\[[^\]]+\]\([^)]+\))\s+\[([\w\_\/\.]+)\:(\d+)\]/
0
+ spec, file, line = $1, $2, $3, $4
0
+ "<span><a style=\"color: blue;\" href=\"txmt://open?url=file://#{e_url(file)}&amp;line=#{line}\">#{spec}</span>:#{line}<br/>"
0
+ elsif line =~ /([\w\_]+).*\[([\w\_\/\.]+)\:(\d+)\]/
0
+ method, file, line = $1, $2, $3
0
+ "<span><a style=\"color: blue;\" href=\"txmt://open?url=file://#{e_url(file)}&amp;line=#{line}\">#{method}</span>:#{line}<br/>"
0
+ elsif line =~ /^\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors\b.*/
0
+ "<span style=\"color: #{$1 + $2 == "00" ? "green" : "red"}\">#{$&}</span><br/>"
0
+ else
0
+ htmlize(line)
0
+ end
0
       end
0
- end
0
+ out.join()
0
+ else
0
+ htmlize(str)
0
+ end
0
+ when :err
0
+ "<span style=\"color: red\">#{htmlize str}</span>"
0
   end
0
-end
0
-
0
-script = RubyScript.new(STDIN.read)
0
-RubyMate.new(script).emit_html
0
+end
0
\ No newline at end of file

Comments

    No one has commented yet.