class TurbolinksRender::Middleware

Constants

Request
Response

Public Class Methods

new(app) click to toggle source
# File lib/turbolinks_render/middleware.rb, line 72
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/turbolinks_render/middleware.rb, line 76
def call(env)
  rack_request = Rack::Request.new(env)
  request = Request.new(rack_request)
  rack_request.set_header('X-Turbolinks-Render-Candidate', request.candidate_for_turbolinks?)

  rack_status, rack_headers, rack_response = @app.call(env)
  response = Response.new(rack_status, rack_headers, rack_response)

  return [rack_status, rack_headers, rack_response] unless render_with_turbolinks?(request, response)

  rack_headers['Content-Type'] = 'text/javascript'
  rack_headers['Content-Length'] = response.turbolinks_body.bytesize.to_s

  [rack_status, rack_headers, [response.turbolinks_body]]
end

Private Instance Methods

ignored_paths() click to toggle source
# File lib/turbolinks_render/middleware.rb, line 104
def ignored_paths
  Rails.application.config.turbolinks_render.ignored_paths
end