Class: Rack::Livejs

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/livejs.rb,
lib/rack/livejs/version.rb

Constant Summary collapse

VERSION =
"0.2.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Livejs.



8
9
10
11
12
13
# File 'lib/rack/livejs.rb', line 8

def initialize(app, options = {})
  @app = Rack::URLMap.new(
    bundled_livejs_prefix => Rack::File.new(bundled_livejs_dir),
    '/' => app
  )
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



6
7
8
# File 'lib/rack/livejs.rb', line 6

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  status, headers, body = @app.call(env)
  if headers["Content-Type"] == "text/html"
    new_html = inject_livejs(read_body(body))
    headers["Content-Length"] = new_html.size.to_s
    body = [new_html]
  end
  [status, headers, body]
end