Class: Rack::Assets

Inherits:
Object
  • Object
show all
Includes:
AssetHelpers
Defined in:
lib/rack/assets.rb

Constant Summary

Constants included from AssetHelpers

Rack::AssetHelpers::TEMPLATE

Instance Method Summary collapse

Methods included from AssetHelpers

#head_code

Constructor Details

#initialize(app) ⇒ Assets

Returns a new instance of Assets.



5
6
7
# File 'lib/rack/assets.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rack/assets.rb', line 9

def call(env)
  status, headers, response = @app.call(env)
  return [status, headers, response] unless check_html?(headers, response) && status == 200

  if response.respond_to?(:body)
    response_body = response.body
  else
    response_body = response.first
  end

  # Inject the html, css and js code to the view
  response_body.gsub!('</head>', "#{head_code}</head>")

  headers['Content-Length'] = response_body.bytesize.to_s

  [status, headers, [response_body]]
end