turbolinks_render 0.9.9 → 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/turbolinks_render/middleware.rb +24 -10
- data/lib/turbolinks_render/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c4babe3e6089e042ce6205c746540f8a6614bcd3676cbf14548517b06410af4
|
4
|
+
data.tar.gz: 6f6560db061ba14396011db0acfb0765ce2e4c8a63cefd0268c84dfa5729442f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c53e0d03adf0fc750c6f9184302bd1c583e0f1cf41f39c6eed11d3c0ee025c09098074cbd9c07c582a776edfe29395ce5d8a0507dcab2e166d4ce0b752440db9
|
7
|
+
data.tar.gz: f3103e0d16097ca7a81a56e51ce94c7fe9290cd17546cc8bbd9cea10f061f4afc20adb201b114d41bf44819a2383065fc9ac7381f9ab3028ce2ea61604ee4aea
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ By default, `render` will be handled by Turbolinks if these conditions are met:
|
|
26
26
|
|
27
27
|
- It's an ajax request
|
28
28
|
- It's not a `get` request
|
29
|
-
- It
|
29
|
+
- It generates an html response (`text/html` content type)
|
30
30
|
|
31
31
|
When these conditions are met and `render` is used:
|
32
32
|
|
@@ -22,7 +22,7 @@ module TurbolinksRender
|
|
22
22
|
def render_body_with_turbolinks(body)
|
23
23
|
@headers["Content-Type"] = 'text/javascript'
|
24
24
|
build_turbolinks_response_to_render(body).tap do |turbolinks_body|
|
25
|
-
@headers["Content-Length"] = turbolinks_body.
|
25
|
+
@headers["Content-Length"] = turbolinks_body.bytesize
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -49,16 +49,30 @@ module TurbolinksRender
|
|
49
49
|
|
50
50
|
def build_turbolinks_response_to_render(html)
|
51
51
|
escaped_html = ActionController::Base.helpers.j(html)
|
52
|
-
|
53
52
|
<<-JS
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
53
|
+
(function(){
|
54
|
+
function renderWithTurbolinks(htmlContent){
|
55
|
+
var currentSnapshot = Turbolinks.Snapshot.fromHTMLElement(document.documentElement);
|
56
|
+
var newSpanshot = Turbolinks.Snapshot.fromHTMLString(htmlContent);
|
57
|
+
var nullCallback = function(){};
|
58
|
+
var nullDelegate = {viewInvalidated: nullCallback, viewWillRender: nullCallback, viewRendered: nullCallback};
|
59
|
+
|
60
|
+
var renderer = new Turbolinks.SnapshotRenderer(currentSnapshot, newSpanshot, false);
|
61
|
+
renderer.delegate = nullDelegate;
|
62
|
+
if(renderer.shouldRender()){
|
63
|
+
renderer.render(nullCallback);
|
64
|
+
}
|
65
|
+
else{
|
66
|
+
renderer = new Turbolinks.ErrorRenderer(htmlContent);
|
67
|
+
renderer.delegate = nullDelegate;
|
68
|
+
renderer.render(nullCallback);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
Turbolinks.clearCache();
|
72
|
+
renderWithTurbolinks("#{escaped_html}");
|
73
|
+
Turbolinks.dispatch('turbolinks:load');
|
74
|
+
window.scroll(0, 0);
|
75
|
+
})();
|
62
76
|
JS
|
63
77
|
end
|
64
78
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turbolinks_render
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jorge Manrubia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|