Class: RackPhantom::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_phantom.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



15
16
17
# File 'lib/rack_phantom.rb', line 15

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rack_phantom.rb', line 19

def call(env)
  status, headers, response = @app.call(env)

  return [status, headers, response] unless render?(headers, env)

  response = response.join("\n").gsub("\"", "\\\"")
  html = Phantomjs.run(render_js, %["#{response}"]).strip
  headers['Content-Length'] = html.length.to_s

  [status, headers, [html]]
end