Guest User

Untitled

a guest
Apr 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. require "#{ENV["TM_SUPPORT_PATH"]}/lib/scriptmate"
  2. require "cgi"
  3.  
  4. $SCRIPTMATE_VERSION = "$Revision: 8136 $"
  5.  
  6. class RubyScript < UserScript
  7. def lang; "Ruby" end
  8. def executable; @hashbang || ENV['TM_RUBY'] || 'ruby' end
  9. def args; ['-rcatch_exception', '-rstdin_dialog'] end
  10. def version_string
  11. ruby_path = %x{ #{executable} -e 'require "rbconfig"; print Config::CONFIG["bindir"] + "/" + Config::CONFIG["ruby_install_name"]'}
  12. res = "Ruby r" + %x{ #{executable} -e 'print RUBY_VERSION' }
  13. res + " (#{ruby_path})"
  14. end
  15. def test_script?
  16. @path =~ /(?:\b|_)(?:tc|ts|test)(?:\b|_)/ or
  17. @content =~ /\brequire\b.+(?:test\/unit|test_helper)/
  18. end
  19. def filter_cmd(cmd)
  20. if test_script?
  21. path_ary = @path.split("/")
  22. if index = path_ary.rindex("test")
  23. test_path = File.join(*path_ary[0..-2])
  24. lib_path = File.join( *( path_ary[0..-2] +
  25. [".."] * (path_ary.length - index - 1) ) +
  26. ["lib"] )
  27. if File.exist? lib_path
  28. cmd.insert(1, "-I#{e_sh lib_path}:#{e_sh test_path}")
  29. end
  30. end
  31. end
  32. cmd
  33. end
  34. end
  35.  
  36. class RubyMate < ScriptMate
  37. def filter_stdout(str)
  38. if @command.test_script? and str =~ /\A[.EF]+\Z/
  39. return htmlize(str).gsub(/[EF]+/, "<span style=\"color: red\">\\&</span>") +
  40. "<br style=\"display: none\"/>"
  41. else
  42. if @command.test_script?
  43. return ( str.map do |line|
  44. if line =~ /^(\s+)(\S.*?):(\d+)(?::in\s*`(.*?)')?/
  45. indent, file, line, method = $1, $2, $3, $4
  46. url, display_name = '', 'untitled document';
  47. unless file == "-"
  48. indent += " " if file.sub!(/^\[/, "")
  49. url = '&url=file://' + e_url(file)
  50. display_name = File.basename(file)
  51. end
  52. "#{indent}<a class='near' href='txmt://open?line=#{line + url}'>" +
  53. (method ? "method #{CGI::escapeHTML method}" : '<em>at top level</em>') +
  54. "</a> in <strong>#{CGI::escapeHTML display_name}</strong> at line #{line}<br/>"
  55. elsif line =~ /(\[[^\]]+\]\([^)]+\))\s+\[([\w\_\/\.]+)\:(\d+)\]/
  56. spec, file, line = $1, $2, $3, $4
  57. "<span><a style=\"color: blue;\" href=\"txmt://open?url=file://#{e_url(file)}&line=#{line}\">#{spec}</span>:#{line}<br/>"
  58. elsif line =~ /([\w\_]+).*\[([\w\_\/\.]+)\:(\d+)\]/
  59. method, file, line = $1, $2, $3
  60. "<span><a style=\"color: blue;\" href=\"txmt://open?url=file://#{e_url(file)}&line=#{line}\">#{method}</span>:#{line}<br/>"
  61. elsif line =~ /^\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors\b.*/
  62. "<span style=\"color: #{$1 + $2 == "00" ? "green" : "red"}\">#{$&}</span><br/>"
  63. else
  64. htmlize(line)
  65. end
  66. end.join )
  67. else
  68. return htmlize(str)
  69. end
  70. end
  71. end
  72. end
  73.  
  74. script = RubyScript.new(STDIN.read)
  75. RubyMate.new(script).emit_html
Add Comment
Please, Sign In to add comment