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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e280f90e434bbda7fac2a73678441b6d1549bcd26a34b36a02e7bc430268a323
4
- data.tar.gz: 2f234433939c2dee28c31d6aacc3a4c178dfcd048d1af868ae4e32c7dae21df7
3
+ metadata.gz: 7c4babe3e6089e042ce6205c746540f8a6614bcd3676cbf14548517b06410af4
4
+ data.tar.gz: 6f6560db061ba14396011db0acfb0765ce2e4c8a63cefd0268c84dfa5729442f
5
5
  SHA512:
6
- metadata.gz: a1660d462adac9c80204cb3d34fa832ded9c3ab6c29c3e28269cb5d1f9a17513595033b15045aa0be07c10e52e30e62a43dbad745e4d43f546ab651dca0e5a96
7
- data.tar.gz: 80d496e2d359a3230388e31c39bdb17bc2e2da1dc9646959ae531d8d90e0cf914b8bc9dee99ade1ebb85c00927c1dda763a292054971d491205150a1f339d03f
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's not rendering json
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.length
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
- (function(){
55
- Turbolinks.clearCache();
56
- document.open();
57
- document.write("#{escaped_html}");
58
- document.close();
59
- Turbolinks.dispatch('turbolinks:load');
60
- window.scroll(0, 0);
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
 
@@ -1,3 +1,3 @@
1
1
  module TurbolinksRender
2
- VERSION = '0.9.9'
2
+ VERSION = '0.9.10'
3
3
  end
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.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-24 00:00:00.000000000 Z
11
+ date: 2019-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails