Skip to content

Instantly share code, notes, and snippets.

@bsbodden
Created September 14, 2010 03:49
Show Gist options
  • Save bsbodden/578495 to your computer and use it in GitHub Desktop.
Save bsbodden/578495 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# made by the folks at Integrallis (http://www.integrallis.com), enjoy!
require 'cgi'
require 'ostruct'
target = $TM_FILEPATH
f = IO.popen(%[java org.mozilla.javascript.tools.shell.Main -f $1 "$TM_FILEPATH" 2>&1])
lines = f.readlines()
f.close_read
formatted = []
lines.each do |line|
case line
when /^(?:js: )(.+), line (\d+): (.+)\n/m
file, line_number, message = $~.captures
formatted << OpenStruct.new(:file => file, :line_number => line_number, :message => message)
when /^(?:js: )(\.+)\^\n/m
dashes = $~.captures
formatted.last.position = dashes.to_s.length
when /^(?:js: )(uncaught JavaScript runtime exception:.+)/m
message = $~.captures
formatted << OpenStruct.new(:message => message)
when /^(?:js: )(.+)\n/m
code_line = $~.captures
if code_line
formatted.last.code = code_line.to_s
end
else
formatted << OpenStruct.new(:output => line)
end
end
formatted_output = []
formatted.each do |element|
if element.respond_to?(:output)
formatted_output << %[<pre>#{CGI.escapeHTML(element.output)}</pre>]
elsif element.respond_to?(:line_number)
formatted_output << %[<p><strong>Rhino says: on line <a href=\"txmt://open?url=file://#{ENV['TM_FILEPATH']}&line=#{element.line_number}\">#{element.line_number}</a> at position #{element.position}: </strong>#{element.message}</p>]
formatted_output << %[<pre>#{element.code}</pre>]
else
formatted_output << %[<p><strong>Rhino says: </strong>#{element.message}</p>]
end
end
print <<HTML
<!doctype>
<html>
<head>
<style type="text/css">
p { margin-bottom: 0; }
pre {
background: #f5f5f5;
border: 1px solid #cfcfcf;
font-size: 12px;
margin-top: 2px;
padding: 2px 4px;
}
</style>
</head>
<body>
#{formatted_output.join}
</body>
</html>
HTML
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment