rails_live_reload 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1750367f18660b1f44055cf60de3a56b3d115055bd33ed3fb3f9736ef54ef110
4
- data.tar.gz: 1c4ae3308c85a213a82606775a03d0b66465f9678471c7192f6b66e8f94cee20
3
+ metadata.gz: aceaf0973158c274de7e8572a411ea88c7bfdd24b0cfcebb26f7499f3bc3d436
4
+ data.tar.gz: 9d1cc878c89e323f9e5f0eec2ba98d716d18340d705cf3547efcc1c3b75f3533
5
5
  SHA512:
6
- metadata.gz: 3b0eef0d9a4754dcc2abd53c63142b34a4106e1c9668f93f3352aabb056bc5862e032beb51a54946fd731f7f12fc02a03db8002652c772afbb049e17d419f961
7
- data.tar.gz: 7abd8952bdc1c08d785721dc3ee27b5ec1610437ad958591e8296fbfbddc38a427dabef8cfcf0cfdff558fcd69ccd69cc7116b1ede9a285ae9156e46d1e4bcf3
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.2
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,20 +16,30 @@ 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)
35
45
  return body if index.nil?
@@ -1,3 +1,3 @@
1
1
  module RailsLiveReload
2
- VERSION = "0.3.2"
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.2
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-10-30 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