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
render_with_turbolinks?(request, response)
click to toggle source
# File lib/turbolinks_render/middleware.rb, line 94 def render_with_turbolinks?(request, response) request.candidate_for_turbolinks? && response.candidate_for_turbolinks? && ignored_paths.none? { |path| request.fullpath.starts_with?(path) } && (request.turbolinks_render_option || (render_with_turbolinks_by_default? && request.turbolinks_render_option != false)) end
render_with_turbolinks_by_default?()
click to toggle source
# File lib/turbolinks_render/middleware.rb, line 100 def render_with_turbolinks_by_default? Rails.application.config.turbolinks_render.render_with_turbolinks_by_default end