turbolinks 2.5.4 → 5.0.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.md +0 -241
- data/lib/turbolinks.rb +16 -31
- data/lib/turbolinks/redirection.rb +40 -7
- data/lib/turbolinks/version.rb +1 -1
- metadata +9 -25
- data/lib/assets/javascripts/turbolinks.js.coffee +0 -558
- data/lib/turbolinks/cookies.rb +0 -15
- data/lib/turbolinks/x_domain_blocker.rb +0 -21
- data/lib/turbolinks/xhr_headers.rb +0 -46
- data/lib/turbolinks/xhr_url_for.rb +0 -22
- data/test/config.ru +0 -55
- data/test/dummy.gif +0 -0
- data/test/index.html +0 -51
- data/test/manifest.appcache +0 -10
- data/test/offline.html +0 -19
- data/test/other.html +0 -26
- data/test/redirect1.html +0 -15
- data/test/redirect2.html +0 -11
- data/test/reload.html +0 -18
- data/test/withoutextension +0 -26
data/lib/turbolinks/cookies.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module Turbolinks
|
2
|
-
# For non-GET requests, sets a request_method cookie containing
|
3
|
-
# the request method of the current request. The Turbolinks script
|
4
|
-
# will not initialize if this cookie is set.
|
5
|
-
module Cookies
|
6
|
-
private
|
7
|
-
def set_request_method_cookie
|
8
|
-
if request.get?
|
9
|
-
cookies.delete(:request_method)
|
10
|
-
else
|
11
|
-
cookies[:request_method] = request.request_method
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Turbolinks
|
2
|
-
# Changes the response status to 403 Forbidden if all of these conditions are true:
|
3
|
-
# - The current request originated from Turbolinks
|
4
|
-
# - The request is being redirected to a different domain
|
5
|
-
module XDomainBlocker
|
6
|
-
private
|
7
|
-
def same_origin?(a, b)
|
8
|
-
a = URI.parse URI.escape(a)
|
9
|
-
b = URI.parse URI.escape(b)
|
10
|
-
[a.scheme, a.host, a.port] == [b.scheme, b.host, b.port]
|
11
|
-
end
|
12
|
-
|
13
|
-
def abort_xdomain_redirect
|
14
|
-
to_uri = response.headers['Location'] || ""
|
15
|
-
current = request.headers['X-XHR-Referer'] || ""
|
16
|
-
unless to_uri.blank? || current.blank? || same_origin?(current, to_uri)
|
17
|
-
self.status = 403
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Turbolinks
|
2
|
-
# Intercepts calls to _compute_redirect_to_location (used by redirect_to) for two purposes.
|
3
|
-
#
|
4
|
-
# 1. Corrects the behavior of redirect_to with the :back option by using the X-XHR-Referer
|
5
|
-
# request header instead of the standard Referer request header.
|
6
|
-
#
|
7
|
-
# 2. Stores the return value (the redirect target url) to persist through to the redirect
|
8
|
-
# request, where it will be used to set the X-XHR-Redirected-To response header. The
|
9
|
-
# Turbolinks script will detect the header and use replaceState to reflect the redirected
|
10
|
-
# url.
|
11
|
-
module XHRHeaders
|
12
|
-
extend ActiveSupport::Concern
|
13
|
-
|
14
|
-
def _compute_redirect_to_location(*args)
|
15
|
-
options, request = _normalize_redirect_params(args)
|
16
|
-
|
17
|
-
store_for_turbolinks begin
|
18
|
-
if options == :back && request.headers["X-XHR-Referer"]
|
19
|
-
super(*[(request if args.length == 2), request.headers["X-XHR-Referer"]].compact)
|
20
|
-
else
|
21
|
-
super(*args)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
def store_for_turbolinks(url)
|
28
|
-
session[:_turbolinks_redirect_to] = url if session && request.headers["X-XHR-Referer"]
|
29
|
-
url
|
30
|
-
end
|
31
|
-
|
32
|
-
def set_xhr_redirected_to
|
33
|
-
if session && session[:_turbolinks_redirect_to]
|
34
|
-
response.headers['X-XHR-Redirected-To'] = session.delete :_turbolinks_redirect_to
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Ensure backwards compatibility
|
39
|
-
# Rails < 4.2: _compute_redirect_to_location(options)
|
40
|
-
# Rails >= 4.2: _compute_redirect_to_location(request, options)
|
41
|
-
def _normalize_redirect_params(args)
|
42
|
-
options, req = args.reverse
|
43
|
-
[options, req || request]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Turbolinks
|
2
|
-
# Corrects the behavior of url_for (and link_to, which uses url_for) with the :back
|
3
|
-
# option by using the X-XHR-Referer request header instead of the standard Referer
|
4
|
-
# request header.
|
5
|
-
module LegacyXHRUrlFor
|
6
|
-
def self.included(base)
|
7
|
-
base.alias_method_chain :url_for, :xhr_referer
|
8
|
-
end
|
9
|
-
|
10
|
-
def url_for_with_xhr_referer(options = {})
|
11
|
-
options = (controller.request.headers["X-XHR-Referer"] || options) if options == :back
|
12
|
-
url_for_without_xhr_referer options
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
module XHRUrlFor
|
17
|
-
def url_for(options = {})
|
18
|
-
options = (controller.request.headers["X-XHR-Referer"] || options) if options == :back
|
19
|
-
super options
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/test/config.ru
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'sprockets'
|
2
|
-
require 'coffee-script'
|
3
|
-
|
4
|
-
Root = File.expand_path("../..", __FILE__)
|
5
|
-
|
6
|
-
Assets = Sprockets::Environment.new do |env|
|
7
|
-
env.append_path File.join(Root, "lib", "assets", "javascripts")
|
8
|
-
end
|
9
|
-
|
10
|
-
class SlowResponse
|
11
|
-
CHUNKS = ['<html><body>', '.'*50, '.'*20, '<a href="/index.html">Home</a></body></html>']
|
12
|
-
|
13
|
-
def call(env)
|
14
|
-
[200, headers, self]
|
15
|
-
end
|
16
|
-
|
17
|
-
def each
|
18
|
-
CHUNKS.each do |part|
|
19
|
-
sleep rand(0.3..0.8)
|
20
|
-
yield part
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def length
|
25
|
-
CHUNKS.join.length
|
26
|
-
end
|
27
|
-
|
28
|
-
def headers
|
29
|
-
{ "Content-Length" => length.to_s, "Content-Type" => "text/html", "Cache-Control" => "no-cache, no-store, must-revalidate" }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
map "/js" do
|
34
|
-
run Assets
|
35
|
-
end
|
36
|
-
|
37
|
-
map "/500" do
|
38
|
-
# throw Internal Server Error (500)
|
39
|
-
end
|
40
|
-
|
41
|
-
map "/withoutextension" do
|
42
|
-
run Rack::File.new(File.join(Root, "test", "withoutextension"), "Content-Type" => "text/html")
|
43
|
-
end
|
44
|
-
|
45
|
-
map "/slow-response" do
|
46
|
-
run SlowResponse.new
|
47
|
-
end
|
48
|
-
|
49
|
-
map "/bounce" do
|
50
|
-
run Proc.new{ [200, { "X-XHR-Redirected-To" => "redirect1.html", "Content-Type" => "text/html" }, File.open( File.join( Root, "test", "redirect1.html" ) ) ] }
|
51
|
-
end
|
52
|
-
|
53
|
-
map "/" do
|
54
|
-
run Rack::Directory.new(File.join(Root, "test"))
|
55
|
-
end
|
data/test/dummy.gif
DELETED
Binary file
|
data/test/index.html
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="en">
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<title>Home</title>
|
6
|
-
<script type="text/javascript" src="/js/turbolinks.js"></script>
|
7
|
-
<script type="text/javascript">
|
8
|
-
Turbolinks.enableProgressBar();
|
9
|
-
|
10
|
-
document.addEventListener("page:change", function() {
|
11
|
-
console.log("page changed");
|
12
|
-
});
|
13
|
-
|
14
|
-
document.addEventListener("page:update", function() {
|
15
|
-
console.log("page updated");
|
16
|
-
});
|
17
|
-
|
18
|
-
document.addEventListener("page:restore", function() {
|
19
|
-
console.log("page restored");
|
20
|
-
});
|
21
|
-
</script>
|
22
|
-
</head>
|
23
|
-
<body class="page-index">
|
24
|
-
<ul style="margin-top:20px;">
|
25
|
-
<li><a href="/other.html">Other page</a></li>
|
26
|
-
<li><a href="/slow-response">Slow loading page for progress bar</a></li>
|
27
|
-
<li><a href="/other.html"><span>Wrapped link</span></a></li>
|
28
|
-
<li><a href="/withoutextension">Without extension</a></li>
|
29
|
-
<li><a href="/withoutextension?sort=user.name">Without extension with query params</a></li>
|
30
|
-
<li><a href="http://www.google.com/">Cross origin</a></li>
|
31
|
-
<li><a href="/other.html" onclick="if(!confirm('follow link?')) { return false}">Confirm Fire Order</a></li>
|
32
|
-
<li><a href="/reload.html"><span>New assets track </span></a></li>
|
33
|
-
<li><a href="/dummy.gif?12345">Query Param Image Link</a></li>
|
34
|
-
<li><a href="/bounce">Redirect</a></li>
|
35
|
-
<li><a href="#">Hash link</a></li>
|
36
|
-
<li><a href="/reload.html#foo">New assets track with hash link</a></li>
|
37
|
-
<li><h5>If you stop the server or go into airplane/offline mode</h5></li>
|
38
|
-
<li><a href="/doesnotexist.html">A page with client error (4xx, rfc2616 sec. 10.4) should error out</a></li>
|
39
|
-
<li><a href="/500">Also server errors (5xx, rfc2616 sec. 10.5) should error out</a></li>
|
40
|
-
<li><a href="/fallback.html">A page that has a fallback in appcache should fallback</a></li>
|
41
|
-
</ul>
|
42
|
-
|
43
|
-
<div style="background:#ccc;height:5000px;width:200px;">
|
44
|
-
</div>
|
45
|
-
<iframe height='1' scrolling='no' src='/offline.html' style='display: none;' width='1'></iframe>
|
46
|
-
|
47
|
-
<script type="text/javascript" data-turbolinks-eval=false>
|
48
|
-
console.log("turbolinks-eval-false script fired. This should only happen on the initial page load.");
|
49
|
-
</script>
|
50
|
-
</body>
|
51
|
-
</html>
|
data/test/manifest.appcache
DELETED
data/test/offline.html
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="en" manifest="/manifest.appcache">
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<title>Home</title>
|
6
|
-
<script type="text/javascript" src="/js/turbolinks.js"></script>
|
7
|
-
<script type="text/javascript">
|
8
|
-
document.addEventListener("page:change", function() {
|
9
|
-
console.log("page changed");
|
10
|
-
});
|
11
|
-
</script>
|
12
|
-
</head>
|
13
|
-
<body class="page-offline">
|
14
|
-
<h1>Offline Mode Fallback</h1>
|
15
|
-
<ul>
|
16
|
-
<li><a href="/index.html">Home</a></li>
|
17
|
-
</ul>
|
18
|
-
</body>
|
19
|
-
</html>
|
data/test/other.html
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="en">
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<title>Home</title>
|
6
|
-
<script type="text/javascript" src="/js/turbolinks.js"></script>
|
7
|
-
<script type="text/javascript">
|
8
|
-
document.addEventListener("page:change", function() {
|
9
|
-
console.log("page changed");
|
10
|
-
});
|
11
|
-
|
12
|
-
document.addEventListener("page:update", function() {
|
13
|
-
console.log("page updated");
|
14
|
-
});
|
15
|
-
|
16
|
-
document.addEventListener("page:restore", function() {
|
17
|
-
console.log("page restored");
|
18
|
-
});
|
19
|
-
</script>
|
20
|
-
</head>
|
21
|
-
<body class="page-other">
|
22
|
-
<ul>
|
23
|
-
<li><a href="/index.html">Home</a></li>
|
24
|
-
</ul>
|
25
|
-
</body>
|
26
|
-
</html>
|
data/test/redirect1.html
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="en">
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<title>Home</title>
|
6
|
-
<script type="text/javascript" src="/js/turbolinks.js"></script>
|
7
|
-
</head>
|
8
|
-
<body class="page-other">
|
9
|
-
Should show /redirect1.html as path
|
10
|
-
<ul>
|
11
|
-
<li>Click <a href="/redirect2.html">Redirect 2</a></li>
|
12
|
-
</ul>
|
13
|
-
|
14
|
-
</body>
|
15
|
-
</html>
|
data/test/redirect2.html
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="en">
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<title>Home</title>
|
6
|
-
<script type="text/javascript" src="/js/turbolinks.js"></script>
|
7
|
-
</head>
|
8
|
-
<body class="page-other">
|
9
|
-
Hit back button twice. It should go back to home page.
|
10
|
-
</body>
|
11
|
-
</html>
|
data/test/reload.html
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="en">
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<title>Home</title>
|
6
|
-
<script type="text/javascript" src="/js/turbolinks.js?1" data-turbolinks-track='true'></script>
|
7
|
-
<script type="text/javascript">
|
8
|
-
document.addEventListener("page:change", function() {
|
9
|
-
console.log("page changed");
|
10
|
-
});
|
11
|
-
</script>
|
12
|
-
</head>
|
13
|
-
<body class="page-reload">
|
14
|
-
<ul>
|
15
|
-
<li><a href="/index.html">Home</a></li>
|
16
|
-
</ul>
|
17
|
-
</body>
|
18
|
-
</html>
|
data/test/withoutextension
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="en">
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<title>Home</title>
|
6
|
-
<script type="text/javascript" src="/js/turbolinks.js"></script>
|
7
|
-
<script type="text/javascript">
|
8
|
-
document.addEventListener("page:change", function() {
|
9
|
-
console.log("page changed");
|
10
|
-
});
|
11
|
-
|
12
|
-
document.addEventListener("page:update", function() {
|
13
|
-
console.log("page updated");
|
14
|
-
});
|
15
|
-
|
16
|
-
document.addEventListener("page:restore", function() {
|
17
|
-
console.log("page restored");
|
18
|
-
});
|
19
|
-
</script>
|
20
|
-
</head>
|
21
|
-
<body class="page-other">
|
22
|
-
<ul>
|
23
|
-
<li><a href="/index.html">Home</a></li>
|
24
|
-
</ul>
|
25
|
-
</body>
|
26
|
-
</html>
|