Class: Rack::JavascriptInject

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

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ JavascriptInject

Returns a new instance of JavascriptInject.



8
9
10
# File 'lib/rack/javascript_inject.rb', line 8

def initialize(app, options = {})
  @app, @options = app
end

Instance Method Details

#_call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rack/javascript_inject.rb', line 14

def _call(env)
  @status, @headers, @response = @app.call(env)
  
  if html? 
    response = Rack::Response.new([], @status, @headers)
    @response.each { |fragment| response.write inject(fragment) }
    response.finish
  else
    [@status, @headers, @response]
  end
end

#call(env) ⇒ Object



12
# File 'lib/rack/javascript_inject.rb', line 12

def call(env); dup._call(env); end