turbolinks-5.1.1/0000755000004100000410000000000013273052222013740 5ustar www-datawww-dataturbolinks-5.1.1/README.md0000644000004100000410000000051213273052222015215 0ustar www-datawww-dataThis repository houses the `turbolinks` RubyGem, which provides a Rails engine for [Turbolinks 5](https://github.com/turbolinks/turbolinks) support. It depends on the [`turbolinks-source`](https://github.com/turbolinks/turbolinks-source-gem) RubyGem, which packages the Turbolinks JavaScript assets for the Rails asset pipeline. turbolinks-5.1.1/LICENSE0000644000004100000410000000203513273052222014745 0ustar www-datawww-dataCopyright 2018 Basecamp, LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. turbolinks-5.1.1/lib/0000755000004100000410000000000013273052222014506 5ustar www-datawww-dataturbolinks-5.1.1/lib/turbolinks.rb0000644000004100000410000000136113273052222017230 0ustar www-datawww-datarequire 'turbolinks/version' require 'turbolinks/redirection' require 'turbolinks/assertions' require 'turbolinks/source' module Turbolinks module Controller extend ActiveSupport::Concern included do include Redirection end end class Engine < ::Rails::Engine config.turbolinks = ActiveSupport::OrderedOptions.new config.turbolinks.auto_include = true config.assets.paths += [Turbolinks::Source.asset_path] if config.respond_to?(:assets) initializer :turbolinks do |app| ActiveSupport.on_load(:action_controller) do if app.config.turbolinks.auto_include include Controller ::ActionDispatch::Assertions.include ::Turbolinks::Assertions end end end end end turbolinks-5.1.1/lib/turbolinks/0000755000004100000410000000000013273052222016702 5ustar www-datawww-dataturbolinks-5.1.1/lib/turbolinks/version.rb0000644000004100000410000000005213273052222020711 0ustar www-datawww-datamodule Turbolinks VERSION = '5.1.1' end turbolinks-5.1.1/lib/turbolinks/redirection.rb0000644000004100000410000000260713273052222021543 0ustar www-datawww-datamodule Turbolinks module Redirection extend ActiveSupport::Concern included do before_action :set_turbolinks_location_header_from_session if respond_to?(:before_action) end def redirect_to(url = {}, options = {}) turbolinks = options.delete(:turbolinks) super.tap do if turbolinks != false && request.xhr? && !request.get? visit_location_with_turbolinks(location, turbolinks) else if request.headers["Turbolinks-Referrer"] store_turbolinks_location_in_session(location) end end end end private def visit_location_with_turbolinks(location, action) visit_options = { action: action.to_s == "advance" ? action : "replace" } script = [] script << "Turbolinks.clearCache()" script << "Turbolinks.visit(#{location.to_json}, #{visit_options.to_json})" self.status = 200 self.response_body = script.join("\n") response.content_type = "text/javascript" end def store_turbolinks_location_in_session(location) session[:_turbolinks_location] = location if session end def set_turbolinks_location_header_from_session if session && session[:_turbolinks_location] response.headers["Turbolinks-Location"] = session.delete(:_turbolinks_location) end end end end turbolinks-5.1.1/lib/turbolinks/assertions.rb0000644000004100000410000000320213273052222021416 0ustar www-datawww-datamodule Turbolinks module Assertions TURBOLINKS_VISIT = /Turbolinks\.visit\("([^"]+)", {"action":"([^"]+)"}\)/ def assert_redirected_to(options = {}, message = nil) if turbolinks_request? assert_turbolinks_visited(options, message) else super end end def assert_turbolinks_visited(options = {}, message = nil) assert_response(:ok, message) assert_equal("text/javascript", response.content_type) visit_location, _ = turbolinks_visit_location_and_action redirect_is = normalize_argument_to_redirection(visit_location) redirect_expected = normalize_argument_to_redirection(options) message ||= "Expected response to be a Turbolinks visit to <#{redirect_expected}> but was a visit to <#{redirect_is}>" assert_operator redirect_expected, :===, redirect_is, message end # Rough heuristic to detect whether this was a Turbolinks request: # non-GET request with a text/javascript response. # # Technically we'd check that Turbolinks-Referrer request header is # also set, but that'd require us to pass the header from post/patch/etc # test methods by overriding them to provide a `turbolinks:` option. # # We can't check `request.xhr?` here, either, since the X-Requested-With # header is cleared after controller action processing to prevent it # from leaking into subsequent requests. def turbolinks_request? !request.get? && response.content_type == "text/javascript" end def turbolinks_visit_location_and_action if response.body =~ TURBOLINKS_VISIT [ $1, $2 ] end end end end turbolinks-5.1.1/turbolinks.gemspec0000644000004100000410000000264613273052222017511 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: turbolinks 5.1.1 ruby lib Gem::Specification.new do |s| s.name = "turbolinks".freeze s.version = "5.1.1" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["David Heinemeier Hansson".freeze] s.date = "2018-04-11" s.description = "Rails engine for Turbolinks 5 support".freeze s.email = "david@loudthinking.com".freeze s.files = ["LICENSE".freeze, "README.md".freeze, "lib/turbolinks.rb".freeze, "lib/turbolinks/assertions.rb".freeze, "lib/turbolinks/redirection.rb".freeze, "lib/turbolinks/version.rb".freeze] s.homepage = "https://github.com/turbolinks/turbolinks".freeze s.licenses = ["MIT".freeze] s.rubygems_version = "2.5.2.1".freeze s.summary = "Turbolinks makes navigating your web application faster".freeze if s.respond_to? :specification_version then s.specification_version = 4 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q.freeze, ["~> 5.1"]) else s.add_dependency(%q.freeze, ["~> 5.1"]) end else s.add_dependency(%q.freeze, ["~> 5.1"]) end end