[SVN] Google Closure simple bundle
Robert (Jimmy) Mooney
jimmy.mooney at gmail.com
Thu Nov 5 20:41:02 UTC 2009
Hi all,
I'm new to bundles (and to this list) but I just whipped this up in
response to google's announcement of the Closure toolset and a RESTful
API for the JS compressor:
You'll need curl installed, and the json ruby gems (`sudo gem install json`)
Create a new bundle in textmate (Google Closure), and a new command
(Advanced Optimization). Input is 'Selected Text' or 'Document'.
Output is 'Create New Document'
Add this code
### START CODE
#!/usr/bin/env ruby
require 'cgi'
require 'rubygems'
require 'json'
doc = CGI.escape(STDIN.read)
cmd = "echo 'output_format=json&output_info=compiled_code&output_info=warnings&output_info=errors&output_info=statistics&compilation_level=ADVANCED_OPTIMIZATIONS&warning_level=verbose&output_file_name=default.js&js_code="+doc+"'
| curl -s -X POST -d @- http://closure-compiler.appspot.com/compile "
output = `#{cmd}`
#print output
parsedOutput = JSON.parse output
print parsedOutput["compiledCode"]
### END CODE
then open your JS source and execute the command (it'll beachball briefly)
Next step is handling error from the REST API
Thanks,
--Jimmy
More information about the textmate-dev
mailing list