Closure Compiler RESTful API - TextMate bundle integration

56 views
Skip to first unread message

Jimmy M

unread,
Nov 5, 2009, 3:58:53 PM11/5/09
to Closure Compiler Discuss
For those textmate folks interested, I just wrote this:

You'll need curl installed, and the json ruby gems (`sudo gem install
json` from terminal)

In TextMate, open Bundles>Bundle Editor>Show Bundle Editor
Create a new bundle (Google Closure)
Add a new command (Advanced Optimization)
Command Params: Input is 'Selected Text' or 'Document'. Output is
'Create New Document'

Add this code to the command:

### 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 @- <a href="http://closure-
compiler.appspot.com/compile"&gt http://closure-compiler.appspot.com/compile</a>
"

output = `#{cmd}`
parsedOutput = JSON.parse output
print parsedOutput["compiledCode"]
### END CODE

then open your JS file and execute the command (it'll beachball
briefly - it's not async). Should open a new document with the
advanced compressed Closure code.

Next step is handling error from the REST API

Jimmy M

unread,
Nov 5, 2009, 4:01:30 PM11/5/09
to Closure Compiler Discuss
Google groups chopped up the big cmd line - just remove all the line
breaks on that cmd block - it should be one line.

On Nov 5, 2:58 pm, Jimmy M <jimmy.moo...@gmail.com> wrote:
> For those textmate folks interested, I just wrote this:
>
> You'll need curl installed, and the json ruby gems (`sudo gem install
> json` from terminal)
>
> In TextMate, open Bundles>Bundle Editor>Show Bundle Editor
> Create a new bundle (Google Closure)
> Add a new command (Advanced Optimization)
> Command Params: Input is 'Selected Text' or 'Document'. Output is
> 'Create New Document'
>
> Add this code to the command:
>
> ### 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_i nfo=errors&output_info=statistics&compilation_level=ADVANCED_OPTIMIZATIONS& warning_level=verbose&output_file_name=default.js&js_code="+doc
> +"' | curl -s -X POST -d @- <a href="http://closure-
> compiler.appspot.com/compile"&gthttp://closure-compiler.appspot.com/compile</a>

Troex Nevelin

unread,
Nov 7, 2009, 10:19:36 AM11/7/09
to Closure Compiler Discuss
Thanks for the bundle, but there is limitation for POST to 200000
bytes, sad my project is 230876

John Lenz

unread,
Nov 7, 2009, 11:18:12 AM11/7/09
to closure-comp...@googlegroups.com
You will want to use the compiler locally for larger projects:
http://code.google.com/p/closure-compiler

Robert (Jimmy) Mooney

unread,
Nov 7, 2009, 10:36:19 PM11/7/09
to closure-comp...@googlegroups.com
Or - break up your files and do them individually.

Thanks,

--Jimmy

M. David Westbrook

unread,
Nov 9, 2009, 2:50:18 PM11/9/09
to closure-comp...@googlegroups.com
On Sat, Nov 7, 2009 at 10:36 PM, Robert (Jimmy) Mooney
<jimmy....@gmail.com> wrote:
>
> Or - break up your files and do them individually.

Compiling files separately may cause trouble, however. See
http://code.google.com/closure/compiler/docs/api-tutorial3.html#separately

Reply all
Reply to author
Forward
0 new messages