Class: Coyote::ClosureCompiler
- Inherits:
-
Object
- Object
- Coyote::ClosureCompiler
- Defined in:
- lib/coyote/closure_compiler.rb
Instance Method Summary collapse
- #compile(content) ⇒ Object
- #compiled_code ⇒ Object
- #errors ⇒ Object
- #file_too_big? ⇒ Boolean
-
#initialize ⇒ ClosureCompiler
constructor
A new instance of ClosureCompiler.
- #success? ⇒ Boolean
Constructor Details
#initialize ⇒ ClosureCompiler
Returns a new instance of ClosureCompiler.
7 8 9 |
# File 'lib/coyote/closure_compiler.rb', line 7 def initialize @request = Net::HTTP::Post.new('/compile', 'Content-type' => 'application/x-www-form-urlencoded') end |
Instance Method Details
#compile(content) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/coyote/closure_compiler.rb', line 11 def compile(content) @content = content params = { 'compilation_level' => 'SIMPLE_OPTIMIZATIONS', 'output_format' => 'xml', 'output_info' => 'compiled_code', 'js_code' => @content } @request.set_form_data(params) begin res = Net::HTTP.new('closure-compiler.appspot.com', 80).start {|http| http.request(@request) } case res when Net::HTTPSuccess @doc = REXML::Document.new(res.body) end rescue REXML::ParseException => msg print "Failed: #{msg}\n".red rescue #these should be caught by external checking end self end |
#compiled_code ⇒ Object
48 49 50 |
# File 'lib/coyote/closure_compiler.rb', line 48 def compiled_code @doc.root.elements['compiledCode'].text end |
#errors ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/coyote/closure_compiler.rb', line 40 def errors unless @doc nil else @doc.root.elements["serverErrors"] end end |