rails_live_reload 0.3.2 → 0.3.3
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 -0
- data/lib/rails_live_reload/javascript/websocket.js +2 -2
- data/lib/rails_live_reload/middleware/base.rb +16 -6
- data/lib/rails_live_reload/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aceaf0973158c274de7e8572a411ea88c7bfdd24b0cfcebb26f7499f3bc3d436
|
4
|
+
data.tar.gz: 9d1cc878c89e323f9e5f0eec2ba98d716d18340d705cf3547efcc1c3b75f3533
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
3
|
-
Copyright ©
|
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,
|
19
|
+
status, headers, body = @app.call(env)
|
20
20
|
|
21
|
-
if html?(headers) &&
|
22
|
-
|
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,
|
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?
|
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.
|
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:
|
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.
|
134
|
+
rubygems_version: 3.4.8
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: Ruby on Rails Live Reload
|