class Ember::Rails::Assets::Middleware

Public Instance Methods

call(env) click to toggle source
# File lib/ember/rails/assets/middleware.rb, line 7
def call env
  @status, @headers, @body = app.call(env)
  return [@status, @headers, @body] unless html?

  response = Rack::Response.new([], @status, @headers)
  @body.each do |fragment|
    response.write inject(fragment)
  end
  @body.close if @body.respond_to?(:close)

  response.headers.delete("Content-Length") # some downstream middleware will recalculate
  response.finish
end

Private Instance Methods

html?() click to toggle source
# File lib/ember/rails/assets/middleware.rb, line 23
def html?
  @headers["Content-Type"] =~ /html/
end
inject(response) click to toggle source
# File lib/ember/rails/assets/middleware.rb, line 27
def inject response
  key = "ASSETS"
  path = ActionView::Base.assets_manifest.path
  markup = Javascript.new(key, path).render
  response.gsub(%r{</head>}, "<script>#{markup}</script></head>")
end