beforeRunningCommand nop command #!/usr/bin/env ruby -wKU require "#{ENV['TM_SUPPORT_PATH']}/lib/escape.rb" require ENV["TM_SUPPORT_PATH"] + "/lib/tm/save_current_document" if !ENV['TM_FILEPATH'] || ENV['TM_FILEPATH'][-2,2] == "js" #if the file hasn't been saved or it's a javascript file contents = STDIN.read #grab the stream of the window contents url = "/tmp/processing_js_preview.html" #create the temp url my_file = File.new(url, "w") #create the temp file if !contents.index("application/processing") #do a quick check to see if processing code is embedded since the file might not have an extension yet dimensions = contents.scan(/size\(\s*(\d*).*?(\d*)/) #find the dimensions in the processing code header = '<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>TextMate Processing.js Quick Preview</title> <script language="javascript" src="http://github.com/jeresig/processing-js/raw/master/examples/init.js"></script> <script language="javascript" src="http://github.com/jeresig/processing-js/raw/master/processing.min.js"></script> </head><body><script type="application/processing">' footer = '</script><canvas width="'+dimensions[0][0]+'px" height="'+dimensions[0][1]+'px"></canvas></body></html>' my_file.puts header + contents + footer #add the small html header and the footer with a canvas else my_file.puts contents #if it was embedded code, just echo the page as is end else #if the file is HTML, save it and preview the actual file intead of a temp file. TextMate.save_current_document #save_current_document uses STDIN.read which can only be read once so it's important not to try to read it earlier on ### ALL OF THE FOLLOWING CODE WAS TAKEN FROM THE "Open Document in Running Browser(s)" COMMAND IN THE HTML BUNDLE ### if ENV['TM_PROJECT_SITEURL'] url = "#{ENV['TM_PROJECT_SITEURL']}" + ENV['TM_FILEPATH'].sub(/^#{Regexp.escape(ENV['TM_PROJECT_DIRECTORY'])}\//, '') else url = "file://#{ENV['TM_FILEPATH']}" end end proclist = `ps -x -o command` active = [] os = `defaults read /System/Library/CoreServices/SystemVersion ProductVersion` browsers = %w[ Safari OmniWeb Camino Shiira firefox-bin Xyle\ scope Opera Internet\ Explorer flock-bin iCab Sunrise seamonkey-bin navigator-bin ].join('|') # Build paths to each active browser # # Notes: # - 'WebKit' look ahead is to rule it out so we can use the working # rule below. # - 'LaunchCFMApp' portion is so iCab works. active = proclist.scan(%r{^(?:/.*LaunchCFMApp )?(/.*\.app)(?=/Contents/MacOS/(?:#{browsers})\b(?!.*WebKit))}) # Special check for WebKit as it appears as Safari # Note: Only supports one running instance of WebKit, picked at random. if proclist =~ %r{/Contents/MacOS/Safari.*WebKit} active << "WebKit" end # TODO: Change when Leopard Only # On Leopard use the -g option to open in background. if os =~ /^10\.(5|6)/ active.each {|p| `open -g -a #{e_sh(p)} #{e_sh(url)}` } else active.each {|p| `open -a #{e_sh(p)} #{e_sh(url)}` } end input document keyEquivalent @r name Preview output discard scope source.processing.js uuid E148DAB2-6E7D-4B43-B205-CC0D0EDAD9A8