Class: RackPhantom::Middleware
- Inherits:
-
Object
- Object
- RackPhantom::Middleware
- Defined in:
- lib/rack_phantom.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
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 |