beforeRunningCommand nop bundleUUID E59DDF80-6EE4-11D9-BAB4-000D93589AF6 command #!/usr/bin/env ruby require "#{ENV["TM_SUPPORT_PATH"]}/lib/escape" require "#{ENV["TM_SUPPORT_PATH"]}/lib/dialog" require "#{ENV["TM_SUPPORT_PATH"]}/lib/web_preview" require "erb" include ERB::Util require "pstore" RAKEMATE_VERSION = "1.3.0".freeze DEFAULT_TASK = "(default task)".freeze RAKEFILE_DIR = (ENV["TM_PROJECT_DIRECTORY"] || ENV["TM_DIRECTORY"]).freeze html_header("RakeMate", "Rake") puts <<-HTML <pre>RakeMate v#{RAKEMATE_VERSION} running on Ruby v#{RUBY_VERSION} (#{`which ruby`.strip}) &gt;&gt;&gt; #{RAKEFILE_DIR}/Rakefile HTML rake = ENV["TM_RAKE"] || ENV["PATH"].split(":").map { |dir| File.join(dir, "rake") }. find { |r| File.exist? r } if rake.nil? puts "Rake not found. Please set TM_RAKE." puts "</pre>" html_footer exit end prefs = PStore.new( File.expand_path( "~/Library/Preferences/" + "com.macromates.textmate.run_rake" ) ) Dir.chdir(RAKEFILE_DIR) tasks = `#{rake} --tasks` unless $?.exited? puts "Could not fetch task list." puts "</pre>" html_footer exit end if tasks.include? "No Rakefile found" puts "Could not locate a Rakefile in #{RAKEFILE_DIR}." puts "</pre>" html_footer exit end tasks = [DEFAULT_TASK] + tasks.grep(/^rake\s+(\S+)/) { |t| t.split[1] } if last_task = tasks.index(prefs.transaction(true) { prefs[RAKEFILE_DIR] }) tasks.unshift(tasks.slice!(last_task)) end if task = Dialog.request_item( :title => "Rake Tasks", :prompt => "Select a task to execute:", :items => tasks, :button1 => "Run Task") prefs.transaction { prefs[RAKEFILE_DIR] = task } testing = task =~ /test/i || task == DEFAULT_TASK open("|#{rake} #{task == "(default task)" ? "" : task} 2>&1") do |output| while line = output.gets if testing and line =~ /^\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors/ print "<span style=\"color: ", ($1 + $2 == "00" ? "green" : "red"), "\">#{line.chomp}</span><br />" elsif testing and line =~ /^(\s+)(\S.*?):(\d+)(?::in\s*`(.*?)')?/ and File.exist? $2 indent, file, line, method = $1, $2, $3, $4 url, display_name = '', 'untitled document'; unless file == "-" url = '&url=file://' + e_url(File.expand_path(file)) display_name = File.basename(file) end print "#{indent}<a class='near' href='txmt://open?line=#{line + url}'>" + (method ? "method #{h method}" : '<em>at top level</em>') + "</a> in <strong>#{h display_name}</strong> at line #{line}<br/>" else print h(line).sub("\n", "<br />") end $stdout.flush if testing and line =~ /^Started\s*/ wrap = 0 while test = output.getc.chr wrap += 1 if %w[. E F].include? test print test.sub(/^[EF]$/, "<span style=\"color: red\">\\&</span>"), (wrap % 80 == 0 ? "<br />" : "<br style=\"display: none\"/>") $stdout.flush else print test.sub("\n", "<br />") $stdout.flush break end end end end end puts "</pre>" html_footer end input none keyEquivalent @ name Run Rake Task output showAsHTML uuid 879313DC-BCD6-4338-A844-F3B643C4C9A2