Sha256: 40a5f86cc41b45500688a48f9a75c8b8a385284d27c951e682048af964834c5e

Contents?: true

Size: 1018 Bytes

Versions: 1

Compression:

Stored size: 1018 Bytes

Contents

require 'uri'
require 'net/http'

module AssetsBooster
  module Compiler
    class Closure
      def self.name
        "Google Closure Compiler"
      end
                  
      def self.compile(code)
        post_data = {
          'js_code'=> code,
          'compilation_level' => 'SIMPLE_OPTIMIZATIONS',
          'output_format' => 'text',
          'output_info' => 'compiled_code'
        }
        uri = URI.parse('http://closure-compiler.appspot.com/compile')      
        res = Net::HTTP.post_form(uri, post_data)
        case res
        when Net::HTTPSuccess
          data = res.body.strip
          if code.size > 0 && data.size < 1
            post_data['output_info'] = 'errors'
            res = Net::HTTP.post_form(uri, post_data)
            raise CompileError.new("Google's Closure Compiler failed: "+res.body)
          end
          data
        else
          raise CompileError.new("HTTP request TO Google's Closure Compiler failed: "+res.to_s)
        end     
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
assets_booster-0.0.1 lib/assets_booster/compiler/closure.rb