Class: Rack::JavascriptFeatures

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

Constant Summary collapse

DEFAULT_OPTIONS =
{:minify => true}

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of JavascriptFeatures.



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

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

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rack/javascript_features.rb', line 13

def call(env)
  request = Rack::Request.new(env)

  if package = package_for_path(request.path)
    etag = package_etag(package)
    if etag == env['HTTP_IF_NONE_MATCH']
      [304, {}, []]
    else
      javascript = package_javascript(package)
      [200, {"Content-Type" => "text/javascript", "Cache-Control" => "private", "ETag" => etag}, [javascript]]
    end
  else
    @app.call(env)
  end
end