Saying stuff about stuff.

Quick Ruby Script to the Google Closure API

Closure is a Google tool for intelligently optimising - minifying - your Javascript. There’s a command-line tool, an online version and a REST API.

Here’s a quick Ruby script for accessing the REST API:

require 'rubygems'
require 'httparty'
class GoogleClosure
include HTTParty
base_uri 'closure-compiler.appspot.com'
def self.compile(path)
contents = File.read(path)
params = {
:js_code => contents,
:compilation_level => 'SIMPLE_OPTIMIZATIONS',
:output_format => 'text',
:output_info => 'compiled_code',
}
post('/compile',
:body => params,
:headers => {
'Content-type' => 'application/x-www-form-urlencoded'
}
)
end
end
File.open('public/javascripts/bookmarklet.min.js', 'w') do |f|
f.write GoogleClosure.compile('public/javascripts/bookmarklet.js')
end
view raw gistfile1.rb hosted with ❤ by GitHub