rails_live_reload 0.3.2 → 0.3.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9719946dc13f20a304dd1d9c70238c2219252bd2a4c1b012bdb66f5c8ed1f8f0
|
4
|
+
data.tar.gz: 843756b9a273ddd189eff2ac6f77b0e44535d4b261e098bb70a9c900bb2e9287
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bf3875244b09962a7da0a1269853215365a57b9ce22b29a09332e43a538b2483f96287480c345a455a7b3d83b63200cb3b2ea34e0cbfa015d8697ef154a446a
|
7
|
+
data.tar.gz: 54a32215cdb6ae7c7811f46a6b6452aa5e86d9470d4d01732c10469ea5354197e5539806c9d703a67da391a39471a1c78025c9b4d28266c97cd68db4cf60dade
|
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
|
|
@@ -49,7 +49,13 @@ module RailsLiveReload
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def socket_path
|
52
|
-
root_path.join('tmp/sockets/rails_live_reload.sock')
|
52
|
+
root_path.join('tmp/sockets/rails_live_reload.sock').then do |path|
|
53
|
+
break path if path.to_s.size <= 104 # 104 is the max length of a socket path
|
54
|
+
|
55
|
+
puts "Unable to create socket path inside the project, using /tmp instead"
|
56
|
+
app_name = ::Rails.application.class.name.split('::').first.underscore
|
57
|
+
Pathname.new("/tmp/rails_live_reload_#{app_name}.sock")
|
58
|
+
end
|
53
59
|
end
|
54
60
|
end
|
55
61
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
|
-
Rails Live Reload 0.3.
|
3
|
-
Copyright ©
|
2
|
+
Rails Live Reload 0.3.4
|
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.4
|
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-22 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
|