rails_live_reload 0.3.1 → 0.3.3

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: 939afe7a09bcddd449e696c10118799ad2852b073e7db44289d19e3f24802049
4
- data.tar.gz: 39d77ccf8dec080c29914e30c3a67cd509cef8dde544ebbbdcb3bea0c88fd81e
3
+ metadata.gz: aceaf0973158c274de7e8572a411ea88c7bfdd24b0cfcebb26f7499f3bc3d436
4
+ data.tar.gz: 9d1cc878c89e323f9e5f0eec2ba98d716d18340d705cf3547efcc1c3b75f3533
5
5
  SHA512:
6
- metadata.gz: 8ed51bae3cc1dd8f940d004088a3141396acd8e0a2ba8b33b9339c4f81ce3cd9723a908d2337d22dc1c3ea851c95baf87532a51a8e60f60cd62a393dd710ea4f
7
- data.tar.gz: 833333f6e32fecf52a1b70c70af3fe355436a68910022ca59337fa6da91fc5e8bc27058539edb77981b9311ab47d25b4862076daf8f43b17e75cc3d90f781afb
6
+ metadata.gz: dedfe054d3a67b70c2ee7ad8e719865eeed77d98e0437b07e56abaf48703cd06a83ec460a25c84cf067c8a6cce53164ec5918de1268d8877c68fd18fd4312b85
7
+ data.tar.gz: 0653e1710da6837048395204355b60a6c2b4320c0809da7b5a3e886dafac191aa188de0588a869a105523c8954a2c3bdfbfb5720132f2ef5fe05db519300e98d
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Rails Live Reload
2
2
 
3
3
  [![RailsJazz](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/my_other.svg?raw=true)](https://www.railsjazz.com)
4
+ [![Listed on OpenSource-Heroes.com](https://opensource-heroes.com/badge-v1.svg)](https://opensource-heroes.com/r/railsjazz/rails_live_reload)
4
5
 
5
6
  ![RailsLiveReload](docs/rails_live_reload.gif)
6
7
 
@@ -1,6 +1,6 @@
1
1
  /*!
2
- Rails Live Reload 0.3.1
3
- Copyright © 2022 RailsJazz
2
+ Rails Live Reload 0.3.3
3
+ Copyright © 2023 RailsJazz
4
4
  https://railsjazz.com
5
5
  */
6
6
  var RailsLiveReload=function(){"use strict";const t="RELOAD",e=["rails-live-reload-v1-json"];class n{static _instance;static get instance(){return n._instance||(n._instance=new this),n._instance}static start(){this.instance.start()}constructor(){this.initialize(),document.addEventListener("turbo:render",(()=>{document.documentElement.hasAttribute("data-turbo-preview")||this.restart()})),document.addEventListener("turbolinks:render",(()=>{document.documentElement.hasAttribute("data-turbolinks-preview")||this.restart()}))}initialize(){const{files:t,time:e,url:n}=JSON.parse(this.optionsNode.textContent);this.files=t,this.time=e,this.url=n}fullReload(){window.location.reload()}get optionsNode(){const t=document.getElementById("rails-live-reload-options");if(!t)throw"Unable to find RailsLiveReload options";return t}start(){this.connection||(this.connection=new WebSocket(function(t){if("function"==typeof t&&(t=t()),t&&!/^wss?:/i.test(t)){const e=document.createElement("a");return e.href=t,e.href=e.href,e.protocol=e.protocol.replace("http","ws"),e.href}return t}(this.url),e),this.connection.onmessage=this.handleMessage.bind(this),this.connection.onopen=this.handleConnectionOpen.bind(this),this.connection.onclose=this.handleConnectionClosed.bind(this))}stop(){this.connection.close()}restart(){this.initialize(),this.setupConnection()}setupConnection(){this.connection.send(JSON.stringify({event:"setup",options:{files:this.files,dt:this.time}}))}handleConnectionOpen(t){this.retriesCount=0,this.setupConnection()}handleMessage(e){JSON.parse(e.data).command===t&&this.fullReload()}handleConnectionClosed(t){this.connection=void 0,!t.wasClean&&this.retriesCount<=10&&(this.retriesCount++,setTimeout((()=>{this.start()}),1e3*this.retriesCount))}}return document.addEventListener("DOMContentLoaded",(()=>{n.start()})),n}();
@@ -16,22 +16,34 @@ module RailsLiveReload
16
16
  end
17
17
  else
18
18
  request = Rack::Request.new(env)
19
- status, headers, response = @app.call(env)
19
+ status, headers, body = @app.call(env)
20
20
 
21
- if html?(headers) && response.respond_to?(:[]) && (status == 500 || (status.to_s =~ /20./ && request.get?))
22
- new_response = make_new_response(response[0])
23
- headers['Content-Length'] = new_response.bytesize.to_s
24
- response = [new_response]
21
+ if html?(headers) && (status == 500 || (status.to_s =~ /20./ && request.get?))
22
+ return inject_rails_live_reload(status, headers, body)
25
23
  end
26
24
 
27
- [status, headers, response]
25
+ [status, headers, body]
28
26
  end
29
27
  end
30
28
 
31
29
  private
32
30
 
31
+ def inject_rails_live_reload(status, headers, body)
32
+ response = Rack::Response.new([], status, headers)
33
+
34
+ if String === body
35
+ response.write make_new_response(body)
36
+ else
37
+ body.each { |fragment| response.write make_new_response(fragment) }
38
+ end
39
+ body.close if body.respond_to?(:close)
40
+ response.finish
41
+ end
42
+
33
43
  def make_new_response(body)
34
44
  index = body.rindex(/<\/body>/i) || body.rindex(/<\/html>/i)
45
+ return body if index.nil?
46
+
35
47
  body.insert(index, <<~HTML.html_safe)
36
48
  <script defer type="text/javascript" src="#{RailsLiveReload.config.url}/script"></script>
37
49
  <script id="rails-live-reload-options" type="application/json">
@@ -1,3 +1,3 @@
1
1
  module RailsLiveReload
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_live_reload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-09-25 00:00:00.000000000 Z
12
+ date: 2023-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
133
  requirements: []
134
- rubygems_version: 3.3.7
134
+ rubygems_version: 3.4.8
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: Ruby on Rails Live Reload